diff --git a/custom_components/versatile_thermostat/base_thermostat.py b/custom_components/versatile_thermostat/base_thermostat.py index 3d32c63..c88d3c0 100644 --- a/custom_components/versatile_thermostat/base_thermostat.py +++ b/custom_components/versatile_thermostat/base_thermostat.py @@ -444,10 +444,6 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): ) ) - # start listening for all managers - for manager in self._managers: - manager.start_listening() - self.async_on_remove(self.remove_thermostat) # issue 428. Link to others entities will start at link @@ -480,6 +476,10 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): _LOGGER.debug("%s - Calling async_startup_internal", self) need_write_state = False + # start listening for all managers + for manager in self._managers: + manager.start_listening() + await self.get_my_previous_state() await self.init_presets(central_configuration) @@ -1609,7 +1609,9 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): return False # Check overpowering condition - # Not necessary for switch because each switch is checking at startup + await VersatileThermostatAPI.get_vtherm_api().central_power_manager.refresh_state() + + # TODO remove this # overpowering is now centralized # overpowering = await self._power_manager.check_overpowering() # if overpowering == STATE_ON: diff --git a/custom_components/versatile_thermostat/central_feature_power_manager.py b/custom_components/versatile_thermostat/central_feature_power_manager.py index 0113993..477b82e 100644 --- a/custom_components/versatile_thermostat/central_feature_power_manager.py +++ b/custom_components/versatile_thermostat/central_feature_power_manager.py @@ -208,8 +208,7 @@ class CentralFeaturePowerManager(BaseFeatureManager): ) else: total_affected_power += power_consumption_max - # Always set to false - # if vtherm.power_manager.is_overpowering_detected: + # Always set to false to init the state _LOGGER.debug( "%s - vtherm %s should not be in overpowering state", self, diff --git a/custom_components/versatile_thermostat/feature_power_manager.py b/custom_components/versatile_thermostat/feature_power_manager.py index 64b415d..e9a2030 100644 --- a/custom_components/versatile_thermostat/feature_power_manager.py +++ b/custom_components/versatile_thermostat/feature_power_manager.py @@ -47,6 +47,7 @@ class FeaturePowerManager(BaseFeatureManager): self._overpowering_state = STATE_UNAVAILABLE self._is_configured: bool = False self._device_power: float = 0 + self._use_power_feature: bool = False @overrides def post_init(self, entry_infos: ConfigData): @@ -56,16 +57,35 @@ class FeaturePowerManager(BaseFeatureManager): self._power_temp = entry_infos.get(CONF_PRESET_POWER) self._device_power = entry_infos.get(CONF_DEVICE_POWER) or 0 + self._use_power_feature = entry_infos.get(CONF_USE_POWER_FEATURE, False) self._is_configured = False - if entry_infos.get(CONF_USE_POWER_FEATURE, False) and self._device_power: - self._is_configured = True - self._overpowering_state = STATE_UNKNOWN - else: - _LOGGER.info("%s - Power management is not fully configured", self) @overrides def start_listening(self): """Start listening the underlying entity. There is nothing to listen""" + central_power_configuration = ( + VersatileThermostatAPI.get_vtherm_api().central_power_manager.is_configured + ) + + if ( + self._use_power_feature + and self._device_power + and central_power_configuration + ): + self._is_configured = True + self._overpowering_state = STATE_UNKNOWN + else: + if self._use_power_feature: + if not central_power_configuration: + _LOGGER.warning( + "%s - Power management is not fully configured. You have to configure the central configuration power", + self, + ) + else: + _LOGGER.warning( + "%s - Power management is not fully configured. You have to configure the power feature of the VTherm", + self, + ) def add_custom_attributes(self, extra_state_attributes: dict[str, Any]): """Add some custom attributes"""