You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As can be seen in the the attached home assistant log early after boot there is a division by zero if the self.average is 0. After that the sensor says "Unavailable".
I just tried adding the bold text below to sensor.py and rebooted and it seems to have work to keep the sensor alive during reboot:
self.current_price / self._average
if isinstance(self.current_price, (int, float))
and isinstance(self._average, (float, int)) and self._average>0
else None
Debug log
2024-10-27 11:36:43.222 ERROR (MainThread) [homeassistant.util.logging] Exception in handle_new_hr when dispatching 'nordpool_update_hour': ()
Traceback (most recent call last):
File "/config/custom_components/nordpool/sensor.py", line 493, in handle_new_hr
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state
self.__async_calculate_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1071, in __async_calculate_state
if extra_state_attributes := self.extra_state_attributes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/nordpool/sensor.py", line 412, in extra_state_attributes
"price_percent_to_average": self.price_percent_to_average,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/nordpool/sensor.py", line 269, in price_percent_to_average
self.current_price / self._average
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero
The text was updated successfully, but these errors were encountered:
Having average costs of 0 seems unlikely. However it should not stop the integration from booting. Thanks for the config examples this will let me recreate it. The easiest solution is just tp catch the exception and return None
Version of the custom_component
0.0.15
Homeassistant version
2024.10.4
Configuration
Describe the bug
As can be seen in the the attached home assistant log early after boot there is a division by zero if the self.average is 0. After that the sensor says "Unavailable".
I just tried adding the bold text below to sensor.py and rebooted and it seems to have work to keep the sensor alive during reboot:
self.current_price / self._average
if isinstance(self.current_price, (int, float))
and isinstance(self._average, (float, int))
and self._average>0
else None
Debug log
The text was updated successfully, but these errors were encountered: