Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 1959948

Browse files
committed
Allow state to drop to 0
1 parent 5c4d901 commit 1959948

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

custom_components/ohme/sensor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ def __init__(
290290
def _handle_coordinator_update(self) -> None:
291291
# Ensure we have data, then ensure value is going up and above 0
292292
if self.coordinator.data and self.coordinator.data['batterySoc']:
293-
self._state = max(0, self._state or 0, self.coordinator.data['batterySoc']['wh'])
293+
new_state = self.coordinator.data['batterySoc']['wh']
294+
295+
# Let the state reset to 0, but not drop otherwise
296+
if new_state <= 0:
297+
self._state = 0
298+
else:
299+
self._state = max(0, self._state or 0, new_state)
294300

295301
self.async_write_ha_state()
296302

0 commit comments

Comments
 (0)