Move set_on_changed registrations from on_process() to __init__()

Callbacks were registered inside the async on_process() coroutine,
meaning they weren't active until the event loop started ticking.
Moving them to __init__ ensures they're wired up at construction time.
Also removes remaining debug prints from the affected task files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tqxrk8uj4M3w3d3eXm3xK8
This commit is contained in:
2026-06-25 20:39:06 +02:00
co-authored by Claude Sonnet 4.6
parent 3ec0a248bb
commit 47fb09aa06
5 changed files with 18 additions and 30 deletions
+3 -8
View File
@@ -2,7 +2,7 @@ import asyncio
from tasks import ATask
from ws.message import MsgIo
from utils.value import ChangedFloat
from components import ATemperatureSensor, TemperatureSensorException
from components import ATemperatureSensor
class TempSensorTask(ATask):
@@ -13,6 +13,7 @@ class TempSensorTask(ATask):
msg_handler.set_recv_handler(self.recv)
self.sensor = sensor_device
self.temp = self.sensor.temperature()
self.set_on_changed("temp", ChangedFloat(self.on_temp_changed, prec=1).set)
def on_temp_changed(self, value):
asyncio.create_task(self.send({'Temp': value}))
@@ -24,12 +25,6 @@ class TempSensorTask(ATask):
await self.msg_handler.send(data)
async def on_process(self):
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
temp = ChangedFloat(self.on_temp_changed, prec=1)
self.set_on_changed("temp", temp.set)
while True:
try:
self.temp = self.sensor.temperature()
except TemperatureSensorException as e:
print(e)
self.temp = self.sensor.temperature()
await asyncio.sleep(self.interval)