Skip to content

Commit 52b2089

Browse files
Fix 0.0 check on battery percentage template (#4404)
1 parent 1059e10 commit 52b2089

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

custom_components/battery_notes/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def validate_is_float(num):
1010
"""Validate value is a float."""
11-
if num:
11+
if num is not None:
1212
try:
1313
float(num)
1414
return True

custom_components/battery_notes/coordinator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ def current_battery_level(self, value):
608608
self._previous_battery_low = self.battery_low
609609
self._previous_battery_level = self._current_battery_level
610610

611+
self.async_set_updated_data(None)
612+
611613
@property
612614
def battery_type_and_quantity(self) -> str:
613615
"""Merge battery type & quantity."""
@@ -729,7 +731,9 @@ def battery_low(self) -> bool:
729731
if self.battery_low_template:
730732
return self.battery_low_template_state
731733
elif self.battery_percentage_template or self.wrapped_battery:
732-
if validate_is_float(self.current_battery_level):
734+
if self.current_battery_level is not None and validate_is_float(
735+
self.current_battery_level
736+
):
733737
return bool(
734738
float(self.current_battery_level) < self.battery_low_threshold
735739
)

0 commit comments

Comments
 (0)