Skip to content

Commit

Permalink
Prevent negative SOC
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jun 13, 2024
1 parent b039ba7 commit b8d4778
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ def _handle_coordinator_update(self) -> None:
if self.coordinator.data and self.coordinator.data['car'] and self.coordinator.data['car']['batterySoc']:
self._state = self.coordinator.data['car']['batterySoc']['percent'] or self.coordinator.data['batterySoc']['percent']

# Don't allow negatives
if isinstance(self._state, int) and self._state < 0:
self._state = 0

self._last_updated = utcnow()
self.async_write_ha_state()

Expand Down

0 comments on commit b8d4778

Please sign in to comment.