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