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:
2026-07-03 19:18:59 +02:00
co-authored by Claude Sonnet 5
parent 698c019581
commit f20e617d81
15 changed files with 369 additions and 39 deletions
+38 -10
View File
@@ -12,15 +12,18 @@ class HendiException(Exception):
class HendiCtrl:
def __init__(self, port, speed, debug=False):
self.debug = debug
self.ser = serial.Serial(port, speed)
try:
self.ser.open()
except:
self.ser.close()
self.ser.open()
self.ser.timeout = 1.000
self.prompt = b':'
self.sw_id = None
self.sw_ver = None
# Deferred-open pyserial idiom: the port isn't actually opened until
# connect() is called, so a missing/unplugged device doesn't crash
# the whole server at construction time (see components/actor/
# heater_hendi.py's HeaterHendi.connect()).
self.ser = serial.Serial()
self.ser.port = port
self.ser.baudrate = speed
self.ser.timeout = 1.000
powers = [500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300,3400, 3500]
digits = [4092, 3840, 3700, 3440, 3300, 3060, 3000, 2930, 2860, 2780, 2640, 2510, 2430, 2360, 2190, 2130, 2030, 1980, 1880, 1730, 1630, 1560, 1480, 1400, 1240, 1150, 1150, 1080, 920, 740, 670]
@@ -36,13 +39,28 @@ class HendiCtrl:
self.poly_w2d = np.polyfit(powers, digits, 5)
self.poly_d2w = np.polyfit(digits, powers, 5)
def is_connected(self):
return self.ser.is_open
def connect(self):
if self.ser.is_open:
return True
try:
self.ser.open()
except serial.SerialException as e:
print(f"HendiCtrl: connect failed: {e}")
return False
# The port itself is what "connected" means - a failed version query
# (e.g. the device sitting in its ungraceful-disconnect lockout, see
# docs/hendi_lockout_findings.md) doesn't make the link any less
# open, so it's reported but doesn't fail connect() overall.
try:
self.sw_id = self.getSoftwareIdentifier()
self.sw_ver = self.getSoftwareVersion()
print(f"{self.sw_id}, F/W-Version: {self.sw_ver}")
except HendiException:
print("HendiCtrl: Hendi not found")
return True
@contextmanager
def remote_open(self):
@@ -191,5 +209,15 @@ class HendiCtrl:
def getPowerWatts(self):
return int(self.toWatts(self.getPowerDigits()) + 0.5)
def disconnect(self):
if self.ser.is_open:
try:
self.remoteEnable(False)
except HendiException:
pass
self.ser.close()
self.sw_id = None
self.sw_ver = None
def close(self):
self.remoteEnable(False)
self.disconnect()