Skip to content

Commit

Permalink
Fix events firing
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Jan 25, 2024
1 parent 626c478 commit 18eeafd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions custom_components/battery_notes/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ async def async_state_changed_listener(
)

if wrapped_battery_state.state not in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
if float(wrapped_battery_state.state) >= (
self._previous_battery_level + increase_threshold
if (
wrapped_battery_state.state
and self._previous_battery_level
and float(wrapped_battery_state.state)
>= (self._previous_battery_level + increase_threshold)
):
self.hass.bus.fire(
EVENT_BATTERY_INCREASED,
Expand All @@ -315,8 +318,8 @@ async def async_state_changed_listener(

self._previous_battery_level = float(wrapped_battery_state.state)

self._previous_state_last_changed = wrapped_battery_state.last_changed
self._previous_battery_low = battery_low
self._previous_state_last_changed = wrapped_battery_state.last_changed
self._previous_battery_low = battery_low

async def async_added_to_hass(self) -> None:
"""Handle added to Hass."""
Expand Down

0 comments on commit 18eeafd

Please sign in to comment.