AttributeChange (the common base of every ATask and component ABC) now sets self.log = logging.getLogger(type(self).__name__), so components no longer need to hand-type their own name into each message. Wired logging.basicConfig() in server/brewpi.py with a bare "%(name)s: %(message)s" formatter - Tee (see prior commit) still supplies the "<date>T<time>:" prefix, so lines read "<date>T<time>:<component>: <message>" without double-stamping, and third-party loggers (websockets, asyncio) now get the same formatting for free. Converted the print() call sites that were standing in for this in tasks/ and components/ (leaving __main__ demo blocks and explicit debug-dump helpers alone).
87 lines
2.2 KiB
Python
Executable File
87 lines
2.2 KiB
Python
Executable File
from components.aheater import AHeater
|
|
from components.actor.hendiCtrl import HendiCtrl
|
|
|
|
|
|
class HeaterHendi(AHeater):
|
|
def __init__(self, params):
|
|
AHeater.__init__(self, simulated=False)
|
|
self.hendi = HendiCtrl(params['port'], params['speed'])
|
|
self.power_set = 0
|
|
self.power_eff = 0
|
|
|
|
def get_power_min(self):
|
|
return 0
|
|
|
|
def get_power_max(self):
|
|
caps = self.hendi.getCapabilties()
|
|
return caps['pwr_watts_max']
|
|
|
|
def get_powers(self):
|
|
caps = self.hendi.getCapabilties()
|
|
return [0] + caps['pwr_list']
|
|
|
|
def connect(self):
|
|
ok = self.hendi.connect()
|
|
self.connected = ok
|
|
return ok
|
|
|
|
def disconnect(self):
|
|
self.hendi.disconnect()
|
|
self.connected = False
|
|
|
|
def activate(self, enable):
|
|
if not self.connected:
|
|
return
|
|
try:
|
|
if enable:
|
|
self.hendi.remoteEnable(1)
|
|
else:
|
|
self.hendi.setSwitch(0)
|
|
except Exception as e:
|
|
# A device that was connected can still fail a live command (the
|
|
# hendi's own idle-timeout auto-suspend, a cable pulled mid-run,
|
|
# ...) - treat that the same as a disconnect rather than letting
|
|
# it escape uncaught, since this is called both from HeaterTask's
|
|
# tick loop (with self.device.open(): activate(True)/(False)) and
|
|
# from a client's Connect/Disconnect command, neither of which
|
|
# expect activate() itself to ever raise.
|
|
self.log.error(f"comm error in activate({enable}): {e}")
|
|
self.disconnect()
|
|
|
|
def is_activated(self):
|
|
if not self.connected:
|
|
return False
|
|
try:
|
|
s = self.hendi.isRemoteEnable()
|
|
return '1' in s
|
|
except Exception as e:
|
|
self.log.error(f"comm error in is_activated: {e}")
|
|
self.disconnect()
|
|
return False
|
|
|
|
def process(self):
|
|
if not self.connected:
|
|
self.power_eff = 0
|
|
return
|
|
try:
|
|
power = self.power_set
|
|
if power == 0:
|
|
self.hendi.setSwitch(0)
|
|
else:
|
|
self.hendi.setSwitch(1)
|
|
self.hendi.setPowerWatts(power)
|
|
self.power_eff = self.hendi.getPowerWatts() if power > 0 else 0
|
|
except Exception as e:
|
|
self.log.error(f"comm error in process: {e}")
|
|
self.disconnect()
|
|
self.power_eff = 0
|
|
|
|
def set_power(self, power):
|
|
self.power_set = min(self.get_power_max(), power)
|
|
|
|
def get_power(self):
|
|
return self.power_eff
|
|
|
|
def close(self):
|
|
self.disconnect()
|