feedback
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Wolfgang Hottgenroth 2024-11-24 15:48:18 +01:00
parent da5506f432
commit 12bcbfcca4
Signed by: wn
GPG Key ID: 18FDFA577A8871AD
3 changed files with 14 additions and 0 deletions

View File

@ -59,6 +59,7 @@ data:
"street": { "topic": "homegear/instance1/plain/52/1/STATE", "label": "Strasse", "converter": "max" }
},
"output_topic": "homegear/instance1/set/42/1/SET_TEMPERATURE",
"feedback_topic": "homegear/instance1/jsonobj/42/1",
"output_converter": "max"
},
"wolfgang": {

View File

@ -24,11 +24,14 @@ class Box:
self.windows = box_config['windows']
self.output_converter = box_config['output_converter']
self.output_topic = box_config['output_topic']
# we use get here since this key is optional
self.feedback_topic = box_config.get('feedback_topic')
self.config = config
self.context = Context(high_temperature=config.DEFAULT_HIGH_TEMPERATURE,
output_temperature=config.DEFAULT_HIGH_TEMPERATURE,
mode='high',
feedback={},
window_state={ k: 'closed' for k in self.windows.keys() })
self.mqtt_client = None
@ -89,6 +92,8 @@ class Box:
self.context.maintenance_mode = payload.lower() == 'true'
case [ primary_key ] if primary_key == 'status':
pass
case [ primary_key ] if primary_key == 'feedback':
self.context.feedback = json.loads(payload)
case _:
raise Error(f"Unexcepted topic_key: {topic_key}, {payload}")

View File

@ -45,6 +45,14 @@ def on_connect(client, userdata, flags, reason_code, properties):
topic_mapping[topic] = (box, topic_key)
logger.info(f"[{box.id}] Subscribed to '{topic}' (Key: '{topic_key}')")
# Subscribe feedback topic if one is available
if box.feedback_topic:
topic = box.feedback_topic
topic_key = "feedback"
client.subscribe(topic)
topic_mapping[topic] = (box, topic_key)
logger.info(f"[{box.id}] Subscribed to '{topic}' (Key: '{topic_key}')")
# Subscribe to central topics and create mappings
for central_key, central_topic in config.CENTRAL_TOPICS.items():
client.subscribe(central_topic)