Avoid writing unifiprotect state when nothing has changed (#100439)
This commit is contained in:
parent
7b71d27637
commit
8a98a0e830
7 changed files with 163 additions and 25 deletions
|
@ -621,3 +621,23 @@ class ProtectEventBinarySensor(EventEntityMixin, BinarySensorEntity):
|
|||
if not is_on:
|
||||
self._event = None
|
||||
self._attr_extra_state_attributes = {}
|
||||
|
||||
@callback
|
||||
def _async_updated_event(self, device: ProtectModelWithId) -> None:
|
||||
"""Call back for incoming data that only writes when state has changed.
|
||||
|
||||
Only the is_on, _attr_extra_state_attributes, and available are ever
|
||||
updated for these entities, and since the websocket update for the
|
||||
device will trigger an update for all entities connected to the device,
|
||||
we want to avoid writing state unless something has actually changed.
|
||||
"""
|
||||
previous_is_on = self._attr_is_on
|
||||
previous_available = self._attr_available
|
||||
previous_extra_state_attributes = self._attr_extra_state_attributes
|
||||
self._async_update_device_from_protect(device)
|
||||
if (
|
||||
self._attr_is_on != previous_is_on
|
||||
or self._attr_extra_state_attributes != previous_extra_state_attributes
|
||||
or self._attr_available != previous_available
|
||||
):
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue