refactor: make ATemperatureSensor's temp observable directly on the sensor
TempSensorSim/TempSensor_max31865's temperature() now stores its reading on self.temp, so ATemperatureSensor's inherited AttributeChange (previously never triggered by anything) actually fires. TempSensorTask no longer keeps its own shadow copy of the reading - it registers its websocket-push callback on self.sensor directly and just drives the read each tick; server/brewpi.py's TC-feeding registration moved from sensor_task to sensor for the same reason. Priming read happens before registering the callback (not after) since all tasks are built synchronously at module level, before the asyncio event loop starts - registering first would fire on_temp_changed's asyncio.create_task() with no running loop. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GpePKZiEZWbGo9HrfuML6U
This commit is contained in:
@@ -42,4 +42,5 @@ class TempSensorSim(ATemperatureSensor):
|
||||
innovation = self.stirrer_sigma * np.sqrt(2.0 * alpha) * np.random.normal()
|
||||
self._stirrer_state = (1.0 - alpha) * self._stirrer_state + innovation
|
||||
|
||||
return self.temp_set + self.offset + white + self._stirrer_state
|
||||
self.temp = self.temp_set + self.offset + white + self._stirrer_state
|
||||
return self.temp
|
||||
|
||||
@@ -47,7 +47,8 @@ class TempSensor_max31865(ATemperatureSensor):
|
||||
|
||||
def temperature(self):
|
||||
digits = self.read_digits()
|
||||
return self.temp_offset + self.to_temperature(digits)
|
||||
self.temp = self.temp_offset + self.to_temperature(digits)
|
||||
return self.temp
|
||||
|
||||
@staticmethod
|
||||
def to_temperature(digits):
|
||||
|
||||
Reference in New Issue
Block a user