Skip to content

Commit

Permalink
Merge pull request #130 from AndersHoglund/fix_midnigth_glitch_HA2024.1
Browse files Browse the repository at this point in the history
Fix #129 midnight glitch for HA2024.1
  • Loading branch information
tijsverkoyen authored Jan 8, 2024
2 parents 5b0153a + 5cbd783 commit 41a5129
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions custom_components/fusion_solar/fusion_solar/energy_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import math

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass
Expand Down Expand Up @@ -60,14 +61,12 @@ def native_value(self) -> float:
if entity is not None:
current_value = entity.state
if current_value == 'unavailable':
_LOGGER.info(
f'{self.entity_id}: not available.')
_LOGGER.info(f'{self.entity_id}: not available.')
return

realtime_power = self.coordinator.data[self._data_name][ATTR_REALTIME_POWER]
if realtime_power == '0.00':
_LOGGER.info(
f'{self.entity_id}: not producing any power, so not updating to prevent positive glitched.')
if math.isclose(realtime_power, 0, abs_tol = 0.001):
_LOGGER.info(f'{self.entity_id}: not producing any power, so no energy update to prevent glitches.')
return float(current_value)

if self._data_name not in self.coordinator.data:
Expand Down

0 comments on commit 41a5129

Please sign in to comment.