Files
brewpi/tasks/pot.py
T
jens f035e1decd GUI: add a spinbox to pre-dial the simulated Pot's reset temperature
btn_pot_reset always reset the simulated Pot to the ambient
temperature. Add doubleSpinBox_pot_temp next to it (shown/hidden
together, same as the button) so the user can dial in a different
starting temperature before committing it - it seeds from the same
remembered ambient value on startup but is otherwise independent and
not persisted.

tasks/pot.py's PotTask.recv() now resets the plant to whatever
temperature the 'Reset' message carries, falling back to ambient for
the bare True a caller might still send.
2026-06-23 19:34:33 +02:00

49 lines
1.6 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
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):
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
self.plant.set_on_changed('power_actual', ChangedInteger(self.on_changed_power).set)
self.plant.set_on_changed('temp', ChangedFloat(self.on_changed_temp, prec=1).set)
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)