import json class Heater: def __init__(self, topic, set_topic): self.not_initialized_yet = True self.wanted_temperature = 15 self.actual_temperature = 15 self.set_topic = set_topic self.topic = topic def payload(self): payload = { "system_mode": "auto", "current_heating_setpoint": str(self.wanted_temperature), "eurotronic_host_flags": {"window_open": True} } return json.dumps(payload) def needs_publish(self): if self.not_initialized_yet: return True else: return self.wanted_temperature != self.actual_temperature def update_actual_heating_point(self, payload): heating_setpoint = int(payload["current_heating_setpoint"]) if self.not_initialized_yet: self.not_initialized_yet = False self.wanted_temperature = heating_setpoint print("%s: update wanted temperature %d" % (self.topic, self.actual_temperature)) self.actual_temperature = heating_setpoint print("%s: update actual temperature %d" % (self.topic, self.actual_temperature)) def topic_and_payload_for_query(self): payload = { "current_heating_setpoint": "" } return ("%s/get" % self.topic), json.dumps(payload)