1919from .heating_curve import HeatingCurve
2020from .helpers import float_value , is_state_stale , state_age_seconds
2121from .pid import PID , PID_UPDATE_INTERVAL
22- from .temperature .state import TemperatureStates , TemperatureState
22+ from .temperature .state import TemperatureState
2323
2424_LOGGER = logging .getLogger (__name__ )
2525
2626ATTR_TEMPERATURE = "temperature"
2727ATTR_CURRENT_TEMPERATURE = "current_temperature"
28- ATTR_CURRENT_VALVE_POSITION = "current_valve_position"
29-
3028ATTR_SENSOR_TEMPERATURE_ID = "sensor_temperature_id"
29+ ATTR_CURRENT_VALVE_POSITION = "current_valve_position"
3130
3231COMFORT_BAND = 0.1
3332COOLING_SLOPE = 4.0
@@ -81,7 +80,7 @@ def climate_state(self) -> Optional[State]:
8180
8281 return state if state .state not in [STATE_UNKNOWN , STATE_UNAVAILABLE ] else None
8382
84- def temperature_state (self ) -> Optional [State ]:
83+ def sensor_state (self ) -> Optional [State ]:
8584 """Return the source state used to calculate the current temperature."""
8685 if (self ._hass is None ) or (climate_state := self .climate_state ) is None :
8786 return None
@@ -105,7 +104,7 @@ def temperature_state(self) -> Optional[State]:
105104 @property
106105 def current_temperature (self ) -> Optional [float ]:
107106 """Retrieve the current temperature, overridden by a sensor if set."""
108- if (state := self .temperature_state ()) is None :
107+ if (state := self .sensor_state ()) is None :
109108 return None
110109
111110 if sensor .DOMAIN in state .entity_id :
@@ -125,10 +124,9 @@ def target_temperature(self) -> Optional[float]:
125124 return float_value (state .attributes .get ("temperature" ))
126125
127126 @property
128- def error (self ) -> Optional [TemperatureState ]:
129- """Calculate the temperature error (target - current)."""
130- temperature_state = self .temperature_state ()
131- if temperature_state is None :
127+ def temperature_state (self ) -> Optional [TemperatureState ]:
128+ """Calculate the temperature state."""
129+ if (sensor_state := self .sensor_state ()) is None :
132130 return None
133131
134132 target_temperature = self .target_temperature
@@ -141,9 +139,9 @@ def error(self) -> Optional[TemperatureState]:
141139 entity_id = self ._entity_id ,
142140 setpoint = target_temperature ,
143141 current = current_temperature ,
144- last_reported = temperature_state .last_reported ,
145- last_updated = temperature_state .last_updated ,
146- last_changed = temperature_state .last_changed ,
142+ last_reported = sensor_state .last_reported ,
143+ last_updated = sensor_state .last_updated ,
144+ last_changed = sensor_state .last_changed ,
147145 )
148146
149147 @property
@@ -228,11 +226,11 @@ async def async_outside_entity_changed(self, _event: Event[EventStateChangedData
228226
229227 def control_pid (self , _time : Optional [datetime ] = None ) -> None :
230228 """Update the PID controller with the current error and heating curve."""
231- if (error := self .error ) is None :
232- _LOGGER .debug ("Skipping control loop for %s because error could not be computed " , self ._entity_id )
229+ if (temperature_state := self .temperature_state ) is None :
230+ _LOGGER .debug ("Skipping control loop for %s because the temperature is not available. " , self ._entity_id )
233231 return
234232
235- self .pid .update (error )
233+ self .pid .update (temperature_state )
236234
237235
238236class Areas :
@@ -246,12 +244,6 @@ def __init__(self, areas: list[Area]) -> None:
246244 def from_config (config : SatConfig ) -> "Areas" :
247245 return Areas ([Area (config , entity_id ) for entity_id in config .rooms ])
248246
249- @property
250- def errors (self ) -> TemperatureStates :
251- """Return a collection of all the error values for all areas."""
252- error_list = [area .error for area in self ._areas if area .error is not None ]
253- return TemperatureStates (error_list )
254-
255247 @property
256248 def pids (self ) -> "Areas._PIDs" :
257249 """Return an interface to reset PID controllers for all areas."""
@@ -342,15 +334,14 @@ def overshoot_cap(self) -> Optional[float]:
342334 if not area .pid .available or not area .requires_heat :
343335 continue
344336
345- error = area .error
346- if error is None :
337+ if (temperature_state := area .temperature_state ) is None :
347338 continue
348339
349- if error .error >= - OVERSHOOT_MARGIN :
340+ if temperature_state .error >= - OVERSHOOT_MARGIN :
350341 continue
351342
352343 # Degrees above target (positive number)
353- degrees_over = - error .error
344+ degrees_over = - temperature_state .error
354345
355346 # Start from a “max allowed in cooling” and pull it down with overshoot severity.
356347 caps .append (COLD_SETPOINT + COOLING_HEADROOM - COOLING_SLOPE * degrees_over )
0 commit comments