Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(binary_sensor): changes async_write_ha_state method to schedule_update_ha_state in is_on() #351

Merged
merged 1 commit into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/dahua/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def is_on(self):

This is the magic part of this sensor along with the async_added_to_hass method below.
The async_added_to_hass method adds a listener to the coordinator so when the event is started or stopped
it calls the async_write_ha_state function. async_write_ha_state gets the current value from this is_on method.
it calls the schedule_update_ha_state function. schedule_update_ha_state gets the current value from this is_on method.
"""
return self._coordinator.get_event_timestamp(self._event_name) > 0

async def async_added_to_hass(self):
"""Connect to dispatcher listening for entity data notifications."""
self._coordinator.add_dahua_event_listener(self._event_name, self.async_write_ha_state)
self._coordinator.add_dahua_event_listener(self._event_name, self.schedule_update_ha_state)

@property
def should_poll(self) -> bool:
Expand Down
Loading