Skip to content

Commit 368c2bb

Browse files
Clamp template percentage (#4436)
1 parent 680af4e commit 368c2bb

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

custom_components/battery_notes/sensor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,19 +923,21 @@ def _update_state(self, result):
923923
self._attr_available = False
924924
state = None
925925

926-
if state == self._state:
926+
clamped_state = max(0, min(100, state)) if state is not None else state
927+
928+
if clamped_state == self._state:
927929
return
928930

929-
self._state = state
930-
self.coordinator.current_battery_level = state
931+
self._state = clamped_state
932+
self.coordinator.current_battery_level = clamped_state
931933

932934
self._attr_available = True
933935
self._attr_native_value = self.coordinator.rounded_battery_level
934936

935937
_LOGGER.debug(
936938
"%s sensor battery_plus set to: %s via template",
937939
self.entity_id,
938-
state,
940+
clamped_state,
939941
)
940942

941943
@property

0 commit comments

Comments
 (0)