Skip to content

Commit

Permalink
Added debug logging to EnergyUsageSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Oct 24, 2024
1 parent 66bd621 commit 81e9b96
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,15 @@ def _handle_coordinator_update(self) -> None:
# Ensure we have data, then ensure value is going up and above 0
if self.coordinator.data and self.coordinator.data['batterySoc']:
new_state = self.coordinator.data['batterySoc']['wh']
_LOGGER.debug("EnergyUsageSensor: Raw Wh reading %s", new_state)

# Let the state reset to 0, but not drop otherwise
if not new_state or new_state <= 0:
_LOGGER.debug("EnergyUsageSensor: Resetting Wh reading to 0")
self._state = 0
else:
self._state = max(0, self._state or 0, new_state)
_LOGGER.debug("EnergyUsageSensor: New state is %s", self._state)

self.async_write_ha_state()

Expand Down

0 comments on commit 81e9b96

Please sign in to comment.