Simplify signalling for updating available property of deCONZ entities (#58078)

This commit is contained in:
Robert Svensson 2021-10-20 14:59:36 +02:00 committed by GitHub
parent 2bd64cec11
commit 3ad3f4e2ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 27 deletions

View File

@ -112,14 +112,14 @@ class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity):
self.alarm_system = get_alarm_system_for_unique_id(gateway, device.unique_id)
@callback
def async_update_callback(self, force_update: bool = False) -> None:
def async_update_callback(self) -> None:
"""Update the control panels state."""
keys = {"panel", "reachable"}
if force_update or (
if (
self._device.changed_keys.intersection(keys)
and self._device.state in DECONZ_TO_ALARM_STATE
):
super().async_update_callback(force_update=force_update)
super().async_update_callback()
@property
def state(self) -> str | None:

View File

@ -129,11 +129,11 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
self.entity_description = entity_description
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Update the sensor's state."""
keys = {"on", "reachable", "state"}
if force_update or self._device.changed_keys.intersection(keys):
super().async_update_callback(force_update=force_update)
if self._device.changed_keys.intersection(keys):
super().async_update_callback()
@property
def is_on(self):
@ -183,11 +183,11 @@ class DeconzTampering(DeconzDevice, BinarySensorEntity):
return f"{self.serial}-tampered"
@callback
def async_update_callback(self, force_update: bool = False) -> None:
def async_update_callback(self) -> None:
"""Update the sensor's state."""
keys = {"tampered", "reachable"}
if force_update or self._device.changed_keys.intersection(keys):
super().async_update_callback(force_update=force_update)
if self._device.changed_keys.intersection(keys):
super().async_update_callback()
@property
def is_on(self) -> bool:

View File

@ -66,7 +66,9 @@ class DeconzDevice(DeconzBase, Entity):
self.gateway.deconz_ids[self.entity_id] = self._device.deconz_id
self.async_on_remove(
async_dispatcher_connect(
self.hass, self.gateway.signal_reachable, self.async_update_callback
self.hass,
self.gateway.signal_reachable,
self.async_update_connection_state,
)
)
@ -77,9 +79,14 @@ class DeconzDevice(DeconzBase, Entity):
self.gateway.entities[self.TYPE].remove(self.unique_id)
@callback
def async_update_callback(self, force_update=False):
def async_update_connection_state(self):
"""Update the device's available state."""
self.async_write_ha_state()
@callback
def async_update_callback(self):
"""Update the device's state."""
if not force_update and self.gateway.ignore_state_updates:
if self.gateway.ignore_state_updates:
return
self.async_write_ha_state()

View File

@ -110,7 +110,7 @@ class DeconzEvent(DeconzBase):
self._device.remove_callback(self.async_update_callback)
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Fire the event if reason is that state is updated."""
if (
self.gateway.ignore_state_updates
@ -155,7 +155,7 @@ class DeconzAlarmEvent(DeconzEvent):
"""Alarm control panel companion event when user interacts with a keypad."""
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Fire the event if reason is new action is updated."""
if (
self.gateway.ignore_state_updates

View File

@ -159,11 +159,11 @@ class DeconzFan(DeconzDevice, FanEntity):
return self._attr_supported_features
@callback
def async_update_callback(self, force_update=False) -> None:
def async_update_callback(self) -> None:
"""Store latest configured speed from the device."""
if self._device.speed in ORDERED_NAMED_FAN_SPEEDS:
self._default_on_speed = self._device.speed
super().async_update_callback(force_update)
super().async_update_callback()
async def async_set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""

View File

@ -113,7 +113,7 @@ class DeconzGateway:
"""Handle signals of gateway connection status."""
self.available = available
self.ignore_state_updates = False
async_dispatcher_send(self.hass, self.signal_reachable, True)
async_dispatcher_send(self.hass, self.signal_reachable)
@callback
def async_add_device_callback(

View File

@ -193,11 +193,11 @@ class DeconzSensor(DeconzDevice, SensorEntity):
self.entity_description = entity_description
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Update the sensor's state."""
keys = {"on", "reachable", "state"}
if force_update or self._device.changed_keys.intersection(keys):
super().async_update_callback(force_update=force_update)
if self._device.changed_keys.intersection(keys):
super().async_update_callback()
@property
def native_value(self):
@ -257,11 +257,11 @@ class DeconzTemperature(DeconzDevice, SensorEntity):
return f"{self.serial}-temperature"
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Update the sensor's state."""
keys = {"temperature", "reachable"}
if force_update or self._device.changed_keys.intersection(keys):
super().async_update_callback(force_update=force_update)
if self._device.changed_keys.intersection(keys):
super().async_update_callback()
@property
def native_value(self):
@ -282,11 +282,11 @@ class DeconzBattery(DeconzDevice, SensorEntity):
self._attr_name = f"{self._device.name} Battery Level"
@callback
def async_update_callback(self, force_update=False):
def async_update_callback(self):
"""Update the battery's state, if needed."""
keys = {"battery", "reachable"}
if force_update or self._device.changed_keys.intersection(keys):
super().async_update_callback(force_update=force_update)
if self._device.changed_keys.intersection(keys):
super().async_update_callback()
@property
def unique_id(self):
@ -339,7 +339,7 @@ class DeconzSensorStateTracker:
self.sensor = None
@callback
def async_update_callback(self, ignore_update=False):
def async_update_callback(self):
"""Sensor state updated."""
if "battery" in self.sensor.changed_keys:
async_dispatcher_send(