From e27eafd73197d2ae2bd1de801b282fef0aa93ddb Mon Sep 17 00:00:00 2001 From: James Connor Date: Tue, 10 Dec 2024 10:46:59 +0000 Subject: [PATCH] Fix for error logs - self.hass is None Fixes #63 --- custom_components/hildebrand_glow_ihd_mqtt/sensor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/custom_components/hildebrand_glow_ihd_mqtt/sensor.py b/custom_components/hildebrand_glow_ihd_mqtt/sensor.py index 24f2e99..8c45181 100755 --- a/custom_components/hildebrand_glow_ihd_mqtt/sensor.py +++ b/custom_components/hildebrand_glow_ihd_mqtt/sensor.py @@ -485,10 +485,17 @@ def process_update(self, mqtt_data) -> None: return self._attr_native_value = new_value - if self._last_reset_reported and self._meter_interval: + zoneInfo = None + if self._time_zone: + zoneInfo = self._time_zone + elif (self.hass is not None and + self.hass.config is not None): + zoneInfo = self.hass.config.time_zone + + if zoneInfo and self._last_reset_reported and self._meter_interval: self._attr_last_reset = self.determine_last_reset( self.get_message_datetime(mqtt_data), - ZoneInfo(self._time_zone or self.hass.config.time_zone), + ZoneInfo(zoneInfo), self._meter_interval )