New btn_pot_reset next to the ambient entry, sends {"Pot": {"Reset":
true}}; tasks/pot.py's PotTask.recv() (previously a no-op) now resets
the plant to its current ambient temperature (Pot.initial()) on that
command.
The button only appears when the server reports its Pot is simulated
(new "PlantSim" field on the System channel, derived from
config.json's previously-unused Controller.plant_name) - resetting a
simulated plant's temperature is meaningless for a real one.
40 lines
1.1 KiB
Python
40 lines
1.1 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]:
|
|
self.plant.initial(self.plant.theta_amb)
|
|
|
|
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:
|
|
self.plant.process()
|
|
await asyncio.sleep(self.interval)
|
|
|
|
|