-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version of the custom_component
0.0.15
Homeassistant version
2024.10.4
Configuration
- platform: nordpool
VAT: True
currency: "SEK"
price_in_cents: false
low_price_cutoff: 0.95
region: "SE3"
precision: 1
price_type: kWh
additional_costs: "{{0.0|float}}"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
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working