This commit is contained in:
Ingo Ratsdorf
2025-09-28 16:09:21 +13:00
parent 3ece89379f
commit 06c38322ed

View File

@@ -57,9 +57,6 @@ def main():
# Check if basic config settings supplied # Check if basic config settings supplied
if not check_config(): if not check_config():
mylog('verbose', [f'[{pluginName}] ⚠ ERROR: Publisher notification \
gateway not set up correctly. Check your {confFileName} \
{pluginName}_* variables.'])
return return
# Create a database connection # Create a database connection
@@ -273,8 +270,8 @@ def publish_mqtt(mqtt_client, topic, message):
qos = get_setting_value('MQTT_QOS') qos = get_setting_value('MQTT_QOS')
mylog('debug', [f"[{pluginName}] Sending MQTT topic: {topic}"]) mylog('debug', [f"[{pluginName}] Sending MQTT topic: {topic}",
mylog('debug', [f"[{pluginName}] Sending MQTT message: {message}"]) f"[{pluginName}] Sending MQTT message: {message}"])
# mylog('verbose', [f"[{pluginName}] get_setting_value('MQTT_QOS'): {qos}"]) # mylog('verbose', [f"[{pluginName}] get_setting_value('MQTT_QOS'): {qos}"])
if not mqtt_connected_to_broker: if not mqtt_connected_to_broker:
@@ -443,7 +440,7 @@ def mqtt_start(db):
# General stats # General stats
# Create a generic device for overal stats # Create a generic device for overal stats
if get_setting_value('MQTT_SEND_STATS') == True: if get_setting_value('MQTT_SEND_STATS'):
# Create a new device representing overall stats # Create a new device representing overall stats
create_generic_device(mqtt_client, deviceId, deviceName) create_generic_device(mqtt_client, deviceId, deviceName)
@@ -474,8 +471,6 @@ def mqtt_start(db):
mylog('verbose', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60, 1), 'min)']) mylog('verbose', [f"[{pluginName}] Estimated delay: ", (sec_delay), 's ', '(', round(sec_delay/60, 1), 'min)'])
debug_index = 0
for device in devices: for device in devices:
# # debug statement START 🔻 # # debug statement START 🔻
@@ -543,23 +538,18 @@ def mqtt_start(db):
# Home Assistant UTILs # Home Assistant UTILs
# ============================================================================= # =============================================================================
def to_binary_sensor(input): def to_binary_sensor(input):
# In HA a binary sensor returns ON or OFF """
result = "OFF" Converts various input types to a binary sensor state ("ON" or "OFF") for Home Assistant.
"""
# bytestring if isinstance(input, (int, float)) and input >= 1:
if isinstance(input, str): return "ON"
if input == "1": elif isinstance(input, bool) and input:
result = "ON" return "ON"
elif isinstance(input, int): elif isinstance(input, str) and input == "1":
if input == 1: return "ON"
result = "ON" elif isinstance(input, bytes) and bytes_to_string(input) == "1":
elif isinstance(input, bool): return "ON"
if input == True: return "OFF"
result = "ON"
elif isinstance(input, bytes):
if bytes_to_string(input) == "1":
result = "ON"
return result
# ------------------------------------- # -------------------------------------