34 lines
1 KiB
Python
34 lines
1 KiB
Python
import time
|
|
from typing import List, Dict
|
|
|
|
from heater.modules.heater import Heater
|
|
|
|
|
|
class Watcher:
|
|
|
|
def __init__(self, heater: Dict[str, Heater]):
|
|
self.heater = heater
|
|
|
|
def publish(self, client):
|
|
for heater in self.heater.values():
|
|
if heater.needs_publish():
|
|
client.publish(heater.set_topic, heater.payload())
|
|
time.sleep(2)
|
|
|
|
def update(self, name, temperature):
|
|
heater: Heater = self.heater.get(name)
|
|
heater.wanted_temperature = temperature
|
|
|
|
def get_topics(self):
|
|
return [heater.topic for heater in self.heater.values()]
|
|
|
|
def update_actual_heating_point_for_topic(self, topic, payload):
|
|
for heater in self.heater.values():
|
|
if heater.topic == topic:
|
|
heater.update_actual_heating_point(payload)
|
|
return
|
|
|
|
def pull_values(self, client):
|
|
for heater in self.heater.values():
|
|
topic, payload = heater.topic_and_payload_for_query()
|
|
client.publish(topic, payload)
|