From 51995fc48987ad835ba2459208e7518cdb4ccece Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 7 Nov 2024 20:02:03 +0100 Subject: [PATCH] status text output --- deployment/configmap.yml | 3 ++- src/main.py | 4 ++++ src/message_processor.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deployment/configmap.yml b/deployment/configmap.yml index 026a2cb..a1f8e28 100644 --- a/deployment/configmap.yml +++ b/deployment/configmap.yml @@ -10,7 +10,7 @@ data: MQTT_BOX_TOPIC_PREFIXES: | { "high_temp": "heating/config/high_temp/", - "overwrite_window": "heating/overwrite_window", + "overwrite_window": "heating/overwrite_window/", "cmd": "heating/command/" } MQTT_CENTRAL_TOPICS: | @@ -20,6 +20,7 @@ data: "status": "heating/system/status" } MQTT_STATUS_TOPIC: "heating/status" + MQTT_STATUSTEXT_TOPIC_PREFIX: "heating/statustext/" OFF_TEMPERATURE: "5.0" LOW_TEMPERATURE: "15.0" DEFAULT_HIGH_TEMPERATURE: "21.0" diff --git a/src/main.py b/src/main.py index 7e3ee70..640ada3 100644 --- a/src/main.py +++ b/src/main.py @@ -19,6 +19,7 @@ LOW_TEMPERATURE = os.getenv("LOW_TEMPERATURE", "15.0") DEFAULT_HIGH_TEMPERATURE = os.getenv("DEFAULT_HIGH_TEMPERATURE", "21.0") MAINTENANCE_TEMPERATURE = os.getenv("MAINTENANCE_TEMPERATURE", "30.0") STATUS_TOPIC = os.getenv("MQTT_STATUS_TOPIC") +STATUSTEXT_TOPIC_PREFIX = os.getenv("MQTT_STATUSTEXT_TOPIC_PREFIX") # Check if required environment variables are set missing_vars = [] @@ -32,6 +33,8 @@ if not CENTRAL_TOPICS_CONFIG: missing_vars.append('MQTT_CENTRAL_TOPICS') if not STATUS_TOPIC: missing_vars.append('MQTT_STATUS_TOPIC') +if not STATUSTEXT_TOPIC_PREFIX: + missing_vars.append('MQTT_STATUSTEXT_TOPIC_PREFIX') if missing_vars: logger.error(f"Error: The following environment variables are not set: {', '.join(missing_vars)}") @@ -46,6 +49,7 @@ context['low_temperature'] = LOW_TEMPERATURE context['default_high_temperature'] = DEFAULT_HIGH_TEMPERATURE context['maintenance_temperature'] = MAINTENANCE_TEMPERATURE context['status_topic'] = STATUS_TOPIC +context['statustext_topic_prefix'] = STATUSTEXT_TOPIC_PREFIX # Load box configurations from JSON try: diff --git a/src/message_processor.py b/src/message_processor.py index 04ceeb5..dc99aef 100644 --- a/src/message_processor.py +++ b/src/message_processor.py @@ -63,6 +63,9 @@ def process_message(box_name, topic_key, payload, context): context['client'].publish(publish_topic, result_message) logger.info(f"[{box_name}] Result published on '{publish_topic}': {status} {result_message}") + statustext_topic = f"{context['statustext_topic_prefix']}/{box['label']}" + context['client'].publish(statustext_topic, f"{local_context}") + logger.info(f"[{box_name}] Local context after: {local_context}") except Exception as e: logger.error(f"[{box_name}] Error processing '{topic_key}': {e}")