diff --git a/custom_components/versatile_thermostat/climate.py b/custom_components/versatile_thermostat/climate.py index 611d510..7851153 100644 --- a/custom_components/versatile_thermostat/climate.py +++ b/custom_components/versatile_thermostat/climate.py @@ -971,15 +971,24 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): Need to be one of CURRENT_HVAC_*. """ - if self._is_over_climate and self._underlying_climate: - return self._underlying_climate.hvac_action + if self._is_over_climate: + # if one not IDLE or OFF -> return it + # else if one IDLE -> IDLE + # else OFF + one_idle = False + for under in self._underlyings: + if action := under.hvac_action not in [HVACAction.IDLE, HVACAction.OFF]: + return action + if under.hvac_action == HVACAction.IDLE: + one_idle = True + if one_idle: + return HVACAction.IDLE + return HVACAction.OFF if self._hvac_mode == HVACMode.OFF: return HVACAction.OFF if not self._is_device_active: return HVACAction.IDLE - if self._ac_mode: - return HVACAction.COOLING return HVACAction.HEATING @property @@ -999,7 +1008,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): def _is_device_active(self): """Returns true if one underlying is active""" for under in self._underlyings: - if under.is_device_active(): + if under.is_device_active: return True return False @@ -1203,7 +1212,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): # Delegate to all underlying for under in self._underlyings: - await under.set_have_mode(hvac_mode) + await under.set_hvac_mode(hvac_mode) self._hvac_mode = hvac_mode await self._async_control_heating(force=True) @@ -2441,16 +2450,25 @@ class VersatileThermostat(ClimateEntity, RestoreEntity): "window_auto_max_duration": self._window_auto_max_duration, } if self._is_over_climate: - self._attr_extra_state_attributes[ - "underlying_climate" - ] = self._climate_entity_id + self._attr_extra_state_attributes["underlying_climate"] = self._underlyings[ + 0 + ].entity_id self._attr_extra_state_attributes[ "start_hvac_action_date" ] = self._underlying_climate_start_hvac_action_date else: self._attr_extra_state_attributes[ - "underlying_switch" - ] = self._heater_entity_id + "underlying_switch_1" + ] = self._underlyings[0].entity_id + self._attr_extra_state_attributes["underlying_switch_2"] = ( + self._underlyings[1].entity_id if len(self._underlyings) > 1 else None + ) + self._attr_extra_state_attributes["underlying_switch_3"] = ( + self._underlyings[2].entity_id if len(self._underlyings) > 2 else None + ) + self._attr_extra_state_attributes["underlying_switch_4"] = ( + self._underlyings[3].entity_id if len(self._underlyings) > 3 else None + ) self._attr_extra_state_attributes[ "on_percent" ] = self._prop_algorithm.on_percent diff --git a/custom_components/versatile_thermostat/tests/test_bugs.py b/custom_components/versatile_thermostat/tests/test_bugs.py index 85b0ed1..7990b3e 100644 --- a/custom_components/versatile_thermostat/tests/test_bugs.py +++ b/custom_components/versatile_thermostat/tests/test_bugs.py @@ -258,7 +258,7 @@ async def test_bug_66( assert mock_send_event.call_count == 1 assert mock_heater_on.call_count == 1 - assert mock_heater_off.call_count == 2 + assert mock_heater_off.call_count == 1 assert mock_condition.call_count == 1 assert entity.window_state == STATE_ON diff --git a/custom_components/versatile_thermostat/tests/test_window.py b/custom_components/versatile_thermostat/tests/test_window.py index a2fdc00..a3eb43a 100644 --- a/custom_components/versatile_thermostat/tests/test_window.py +++ b/custom_components/versatile_thermostat/tests/test_window.py @@ -174,7 +174,7 @@ async def test_window_management_time_enough( ) assert mock_heater_on.call_count == 1 # One call in turn_oiff and one call in the control_heating - assert mock_heater_off.call_count == 2 + assert mock_heater_off.call_count == 1 assert mock_condition.call_count == 1 assert entity.window_state == STATE_ON diff --git a/custom_components/versatile_thermostat/underlyings.py b/custom_components/versatile_thermostat/underlyings.py index 60ba94e..584bb55 100644 --- a/custom_components/versatile_thermostat/underlyings.py +++ b/custom_components/versatile_thermostat/underlyings.py @@ -144,7 +144,6 @@ class UnderlyingSwitch(UnderlyingEntity): class UnderlyingClimate(UnderlyingEntity): """Represent a underlying climate""" - _initialDelaySec: int _underlying_climate: ClimateEntity def __init__( @@ -158,6 +157,7 @@ class UnderlyingClimate(UnderlyingEntity): entity_type=UnderlyingEntityType.CLIMATE, entity_id=climate_entity_id, ) + self._underlying_climate = None def find_underlying_climate(self) -> ClimateEntity: """Find the underlying climate entity""" @@ -279,3 +279,10 @@ class UnderlyingClimate(UnderlyingEntity): SERVICE_SET_TEMPERATURE, data, # TODO needed ? context=self._context ) + + @property + def hvac_action(self) -> HVACAction: + """Get the hvac action of the underlying""" + if not self.is_initialized: + return None + return self._underlying_climate.hvac_action