Avoid writing unifiprotect state when nothing has changed (#100439)

This commit is contained in:
J. Nick Koston 2023-09-16 09:57:43 -05:00 committed by GitHub
parent 7b71d27637
commit 8a98a0e830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 163 additions and 25 deletions

View file

@ -193,3 +193,17 @@ class ProtectButton(ProtectDeviceEntity, ButtonEntity):
if self.entity_description.ufp_press is not None:
await getattr(self.device, self.entity_description.ufp_press)()
@callback
def _async_updated_event(self, device: ProtectModelWithId) -> None:
"""Call back for incoming data that only writes when state has changed.
Only available is 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_available = self._attr_available
self._async_update_device_from_protect(device)
if self._attr_available != previous_available:
self.async_write_ha_state()