From ae9b065387634d8756e64dabd3918fa8f0f9ecf5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Collin Date: Tue, 5 Nov 2024 18:40:14 +0000 Subject: [PATCH] Add logs to diagnose the case --- .../versatile_thermostat/base_thermostat.py | 32 +++++++++++++++++++ .../versatile_thermostat/commons.py | 1 - .../versatile_thermostat/const.py | 6 +++- .../thermostat_climate.py | 17 +++++++++- .../versatile_thermostat/thermostat_switch.py | 14 +++++++- .../versatile_thermostat/thermostat_valve.py | 14 +++++++- 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/custom_components/versatile_thermostat/base_thermostat.py b/custom_components/versatile_thermostat/base_thermostat.py index 7342a12..04527c5 100644 --- a/custom_components/versatile_thermostat/base_thermostat.py +++ b/custom_components/versatile_thermostat/base_thermostat.py @@ -84,6 +84,10 @@ def get_tz(hass: HomeAssistant): return dt_util.get_time_zone(hass.config.time_zone) +_LOGGER_ENERGY = logging.getLogger( + "custom_components.versatile_thermostat.energy_debug" +) + class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): """Representation of a base class for all Versatile Thermostat device.""" @@ -198,6 +202,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): self._attr_translation_key = "versatile_thermostat" self._total_energy = None + _LOGGER_ENERGY.debug("%s - _init_ resetting energy to None", self) # because energy of climate is calculated in the thermostat we have to keep that here and not in underlying entity self._underlying_climate_start_hvac_action_date = None @@ -470,6 +475,7 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): self._presence_state = None self._total_energy = None + _LOGGER_ENERGY.debug("%s - post_init_ resetting energy to None", self) # Read the parameter from configuration.yaml if it exists short_ema_params = DEFAULT_SHORT_EMA_PARAMS @@ -804,6 +810,11 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): old_total_energy = old_state.attributes.get(ATTR_TOTAL_ENERGY) self._total_energy = old_total_energy if old_total_energy is not None else 0 + _LOGGER_ENERGY.debug( + "%s - get_my_previous_state restored energy is %s", + self, + self._total_energy, + ) self.restore_specific_previous_state(old_state) else: @@ -817,6 +828,11 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): "No previously saved temperature, setting to %s", self._target_temp ) self._total_energy = 0 + _LOGGER_ENERGY.debug( + "%s - get_my_previous_state no previous state energy is %s", + self, + self._total_energy, + ) if not self._hvac_mode: self._hvac_mode = HVACMode.OFF @@ -2622,6 +2638,22 @@ class BaseThermostat(ClimateEntity, RestoreEntity, Generic[T]): "hvac_off_reason": self.hvac_off_reason, } + _LOGGER_ENERGY.debug( + "%s - update_custom_attributes saved energy is %s", + self, + self.total_energy, + ) + + @overrides + def async_write_ha_state(self): + """overrides to have log""" + _LOGGER_ENERGY.debug( + "%s - async_write_ha_state written state energy is %s", + self, + self._total_energy, + ) + return super().async_write_ha_state() + @callback def async_registry_entry_updated(self): """update the entity if the config entry have been updated diff --git a/custom_components/versatile_thermostat/commons.py b/custom_components/versatile_thermostat/commons.py index 19a02b3..b76267c 100644 --- a/custom_components/versatile_thermostat/commons.py +++ b/custom_components/versatile_thermostat/commons.py @@ -17,7 +17,6 @@ from .const import DOMAIN, DEVICE_MANUFACTURER, ServiceConfigurationError _LOGGER = logging.getLogger(__name__) - def get_tz(hass: HomeAssistant): """Get the current timezone""" diff --git a/custom_components/versatile_thermostat/const.py b/custom_components/versatile_thermostat/const.py index 44f4838..d6ceb7b 100644 --- a/custom_components/versatile_thermostat/const.py +++ b/custom_components/versatile_thermostat/const.py @@ -354,7 +354,11 @@ CONF_WINDOW_ACTIONS = [ CONF_WINDOW_ECO_TEMP, ] -SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON +SUPPORT_FLAGS = ( + ClimateEntityFeature.TARGET_TEMPERATURE + | ClimateEntityFeature.TURN_OFF + | ClimateEntityFeature.TURN_ON +) SERVICE_SET_PRESENCE = "set_presence" SERVICE_SET_PRESET_TEMPERATURE = "set_preset_temperature" diff --git a/custom_components/versatile_thermostat/thermostat_climate.py b/custom_components/versatile_thermostat/thermostat_climate.py index 1411f27..f7ef9ed 100644 --- a/custom_components/versatile_thermostat/thermostat_climate.py +++ b/custom_components/versatile_thermostat/thermostat_climate.py @@ -31,6 +31,10 @@ from .auto_start_stop_algorithm import ( ) _LOGGER = logging.getLogger(__name__) +_LOGGER_ENERGY = logging.getLogger( + "custom_components.versatile_thermostat.energy_debug" +) + HVAC_ACTION_ON = [ # pylint: disable=invalid-name HVACAction.COOLING, @@ -97,7 +101,7 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): """Initialize the Thermostat""" super().post_init(config_entry) - + for climate in config_entry.get(CONF_UNDERLYING_LIST): self._underlyings.append( UnderlyingClimate( @@ -549,6 +553,7 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): ] = self._auto_start_stop_algo.accumulated_error_threshold self.async_write_ha_state() + _LOGGER.debug( "%s - Calling update_custom_attributes: %s", self, @@ -595,8 +600,18 @@ class ThermostatOverClimate(BaseThermostat[UnderlyingClimate]): if self._total_energy is None: self._total_energy = added_energy + _LOGGER_ENERGY.debug( + "%s - incremente_energy set energy is %s", + self, + self._total_energy, + ) else: self._total_energy += added_energy + _LOGGER_ENERGY.debug( + "%s - incremente_energy incremented energy is %s", + self, + self._total_energy, + ) _LOGGER.debug( "%s - added energy is %.3f . Total energy is now: %.3f", diff --git a/custom_components/versatile_thermostat/thermostat_switch.py b/custom_components/versatile_thermostat/thermostat_switch.py index 7869d2a..4e07b8d 100644 --- a/custom_components/versatile_thermostat/thermostat_switch.py +++ b/custom_components/versatile_thermostat/thermostat_switch.py @@ -21,7 +21,9 @@ from .underlyings import UnderlyingSwitch from .prop_algorithm import PropAlgorithm _LOGGER = logging.getLogger(__name__) - +_LOGGER_ENERGY = logging.getLogger( + "custom_components.versatile_thermostat.energy_debug" +) class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): """Representation of a base class for a Versatile Thermostat over a switch.""" @@ -183,8 +185,18 @@ class ThermostatOverSwitch(BaseThermostat[UnderlyingSwitch]): if self._total_energy is None: self._total_energy = added_energy + _LOGGER_ENERGY.debug( + "%s - incremente_energy set energy is %s", + self, + self._total_energy, + ) else: self._total_energy += added_energy + _LOGGER_ENERGY.debug( + "%s - incremente_energy increment energy is %s", + self, + self._total_energy, + ) self.update_custom_attributes() diff --git a/custom_components/versatile_thermostat/thermostat_valve.py b/custom_components/versatile_thermostat/thermostat_valve.py index 7eb7f23..d9324d0 100644 --- a/custom_components/versatile_thermostat/thermostat_valve.py +++ b/custom_components/versatile_thermostat/thermostat_valve.py @@ -25,7 +25,9 @@ from .const import ( from .underlyings import UnderlyingValve _LOGGER = logging.getLogger(__name__) - +_LOGGER_ENERGY = logging.getLogger( + "custom_components.versatile_thermostat.energy_debug" +) class ThermostatOverValve(BaseThermostat[UnderlyingValve]): # pylint: disable=abstract-method """Representation of a class for a Versatile Thermostat over a Valve""" @@ -265,8 +267,18 @@ class ThermostatOverValve(BaseThermostat[UnderlyingValve]): # pylint: disable=a if self._total_energy is None: self._total_energy = added_energy + _LOGGER_ENERGY.debug( + "%s - incremente_energy set energy is %s", + self, + self._total_energy, + ) else: self._total_energy += added_energy + _LOGGER_ENERGY.debug( + "%s - get_my_previous_state increment energy is %s", + self, + self._total_energy, + ) self.update_custom_attributes()