feat: add connect/disconnect status for real heater/stirrer hardware
Heater and Stirrer can be real serial hardware (hendi, Pololu1376), but there was no connection concept at all - the constructors opened the port and crashed the whole server if the device was missing, with no way to see connection status or firmware version and no way to reconnect without a restart. Adds an observable Connectable mixin (components/connectable.py) shared by AHeater/AStirrer; real devices defer opening the serial port to an explicit connect(), auto-connect on server startup, and surface Connected/FirmwareVersion/Simulated plus manual Connect/Disconnect over the web GUI. Heating/stirring and Sud Start are all gated on connection state, and a disconnect mid-brew force-stops the run via the same path as a manual Stop. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YaPLuRPpyjWcwhMvCvpHCL
This commit is contained in:
+32
-2
@@ -3,7 +3,7 @@ import bisect
|
||||
from tasks import ATask
|
||||
from ws.message import MsgIo
|
||||
from utils.value import ChangedFloat
|
||||
from components import APid, AStirrer
|
||||
from components import APid, AStirrer, AHeater
|
||||
from components.plant import APlant
|
||||
from components.sud import Sud, SudState
|
||||
|
||||
@@ -37,12 +37,13 @@ def _downsample(t, theta, max_points=MAX_FORECAST_POINTS):
|
||||
|
||||
|
||||
class SudTask(ATask):
|
||||
def __init__(self, sud: Sud, tc: APid, stirrer: AStirrer, pot: APlant, dt, interval, msg_handler: MsgIo,
|
||||
def __init__(self, sud: Sud, tc: APid, stirrer: AStirrer, heater: AHeater, pot: APlant, dt, interval, msg_handler: MsgIo,
|
||||
forecast_estimator=None):
|
||||
ATask.__init__(self, interval)
|
||||
self.sud = sud
|
||||
self.tc = tc
|
||||
self.stirrer = stirrer
|
||||
self.heater = heater
|
||||
self.pot = pot
|
||||
# Simulated seconds per tick, vs. interval's wall-clock seconds per
|
||||
# tick - same dt/interval split Pot/TempController/Stirrer already
|
||||
@@ -255,6 +256,24 @@ class SudTask(ATask):
|
||||
def set_on_start(self, callback):
|
||||
self._on_start = callback
|
||||
|
||||
def check_connections(self):
|
||||
"""Called whenever the heater's or stirrer's connection state
|
||||
changes (wired up in server/brewpi.py via HeaterTask/StirrerTask's
|
||||
set_on_connected_changed()) - force-stops a run already in progress
|
||||
if either has dropped, since continuing to run a schedule with a
|
||||
dead actuator is misleading. Reuses Sud.stop() (already a no-op
|
||||
outside RAMPING/HOLDING/WAIT_USER/PAUSED), the same path a manual
|
||||
Stop press takes, so all the usual shutdown plumbing (heater
|
||||
shutdown, sud log stop_run - see SudTask.set_on_end()'s wiring in
|
||||
server/brewpi.py) fires exactly as it would for Stop."""
|
||||
if self.sud.state in (SudState.IDLE, SudState.DONE):
|
||||
return
|
||||
if self.heater.connected and self.stirrer.connected:
|
||||
return
|
||||
self.sud.stop()
|
||||
asyncio.create_task(self.send({'Error': 'Heater/Stirrer disconnected - brew stopped.'}))
|
||||
asyncio.create_task(self.send({'Error': None}))
|
||||
|
||||
def on_state_changed(self, value):
|
||||
asyncio.create_task(self.send({'State': str(value)}))
|
||||
|
||||
@@ -473,6 +492,17 @@ class SudTask(ATask):
|
||||
async def recv(self, data):
|
||||
for pair in data.items():
|
||||
if 'Start' in pair[0]:
|
||||
# Refuse to (re)start a brew if either actuator it depends
|
||||
# on isn't actually connected - continuing to "run" a
|
||||
# schedule with a dead heater/stirrer is misleading. Mirrors
|
||||
# the 'Load'-while-running refusal below: send the Error then
|
||||
# immediately clear it, since the dispatcher has no concept of
|
||||
# a one-shot event (see that branch's own comment).
|
||||
missing = [name for name, device in (('heater', self.heater), ('stirrer', self.stirrer)) if not device.connected]
|
||||
if missing:
|
||||
await self.send({'Error': f"Cannot start - {' and '.join(missing)} not connected."})
|
||||
await self.send({'Error': None})
|
||||
continue
|
||||
# A fresh start (not a resume from Pause, which keeps
|
||||
# whatever forecast the run already established) re-
|
||||
# anchors the forecast to the real temperature right now
|
||||
|
||||
Reference in New Issue
Block a user