Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
626b8edc88
|
|||
c5ed655399
|
18
src/box.py
18
src/box.py
@ -73,6 +73,7 @@ class Box:
|
||||
|
||||
try:
|
||||
# match topic to find operation to be executed
|
||||
send_command = True
|
||||
match topic_key.split('/'):
|
||||
case [ primary_key, sub_key ] if primary_key == 'window':
|
||||
self.context.window_state[sub_key] = CONVERTERS["window_contact_input"][self.windows[sub_key]["converter"]](payload)
|
||||
@ -91,9 +92,12 @@ class Box:
|
||||
case [ primary_key ] if primary_key == 'maintenance_mode':
|
||||
self.context.maintenance_mode = payload.lower() == 'true'
|
||||
case [ primary_key ] if primary_key == 'status':
|
||||
send_command = False
|
||||
pass
|
||||
case [ primary_key ] if primary_key == 'feedback':
|
||||
self.context.feedback = json.loads(payload)
|
||||
# merge the both dicts
|
||||
self.context.feedback |= json.loads(payload)
|
||||
send_command = False
|
||||
case _:
|
||||
raise Error(f"Unexcepted topic_key: {topic_key}, {payload}")
|
||||
|
||||
@ -101,12 +105,14 @@ class Box:
|
||||
self._calculate_output_temperature()
|
||||
|
||||
|
||||
# publish output temperature
|
||||
result_message = CONVERTERS["target_temperature_output"][self.output_converter](self.context.output_temperature)
|
||||
publish_topic = self.output_topic
|
||||
self.mqtt_client.publish(publish_topic, result_message)
|
||||
logger.info(f"[Box {self.id}] Result published on '{publish_topic}': {result_message}")
|
||||
if send_command:
|
||||
# publish output temperature
|
||||
result_message = CONVERTERS["target_temperature_output"][self.output_converter](self.context.output_temperature)
|
||||
publish_topic = self.output_topic
|
||||
self.mqtt_client.publish(publish_topic, result_message)
|
||||
logger.info(f"[Box {self.id}] Result published on '{publish_topic}': {result_message}")
|
||||
|
||||
# send context in any case
|
||||
context_topic = f"{self.config.CONTEXT_TOPIC_PREFIX}{self.id}"
|
||||
self.mqtt_client.publish(context_topic, str(self.context))
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user