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
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import asyncio
|
|
from tasks import ATask
|
|
from ws.message import MsgIo
|
|
from utils.value import ChangedInteger, ChangedFloat
|
|
from components.plant import APlant
|
|
|
|
|
|
class PotTask(ATask):
|
|
def __init__(self, pot: APlant, interval, msg_handler: MsgIo):
|
|
ATask.__init__(self, interval)
|
|
|
|
self.msg_handler = msg_handler
|
|
msg_handler.set_recv_handler(self.recv)
|
|
self.plant = pot
|
|
pot.set_on_changed('power_actual', ChangedInteger(self.on_changed_power).set)
|
|
pot.set_on_changed('temp', ChangedFloat(self.on_changed_temp, prec=1).set)
|
|
|
|
def on_changed_power(self, value):
|
|
asyncio.create_task(self.send({'Power': value}))
|
|
|
|
def on_changed_temp(self, value):
|
|
asyncio.create_task(self.send({'Temp': value}))
|
|
|
|
async def recv(self, data):
|
|
for pair in data.items():
|
|
if 'Reset' in pair[0]:
|
|
# The GUI's pot-temp spinbox sends the temperature to reset
|
|
# to directly - fall back to ambient for any older/other
|
|
# caller that still just sends a bare True.
|
|
value = pair[1]
|
|
temp = value if isinstance(value, (int, float)) else self.plant.theta_amb
|
|
self.plant.initial(temp)
|
|
|
|
async def send(self, data):
|
|
await self.msg_handler.send(data)
|
|
|
|
async def on_process(self):
|
|
while True:
|
|
# Stays inert until a Sud actually supplies plant params (see
|
|
# tasks/sud.py's SudTask.apply_plant_params()) - process()
|
|
# would otherwise raise (components/plant/pot.py's Pot).
|
|
if self.plant.is_configured():
|
|
self.plant.process()
|
|
await asyncio.sleep(self.interval)
|
|
|
|
|