Fix service device refresh calling state update (#30920)

This commit is contained in:
Robert Svensson 2020-01-18 00:33:46 +01:00 committed by Paulus Schoutsen
parent 7b29a498c6
commit c9db21ffac
8 changed files with 44 additions and 27 deletions

View file

@ -54,11 +54,13 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorDevice):
"""Representation of a deCONZ binary sensor.""" """Representation of a deCONZ binary sensor."""
@callback @callback
def async_update_callback(self, force_update=False): def async_update_callback(self, force_update=False, ignore_update=False):
"""Update the sensor's state.""" """Update the sensor's state."""
changed = set(self._device.changed_keys) if ignore_update:
return
keys = {"on", "reachable", "state"} keys = {"on", "reachable", "state"}
if force_update or any(key in changed for key in keys): if force_update or self._device.changed_keys.intersection(keys):
self.async_schedule_update_ha_state() self.async_schedule_update_ha_state()
@property @property

View file

@ -97,8 +97,11 @@ class DeconzDevice(DeconzBase, Entity):
unsub_dispatcher() unsub_dispatcher()
@callback @callback
def async_update_callback(self, force_update=False): def async_update_callback(self, force_update=False, ignore_update=False):
"""Update the device's state.""" """Update the device's state."""
if ignore_update:
return
self.async_schedule_update_ha_state() self.async_schedule_update_ha_state()
@property @property

View file

@ -39,16 +39,20 @@ class DeconzEvent(DeconzBase):
self._device = None self._device = None
@callback @callback
def async_update_callback(self, force_update=False): def async_update_callback(self, force_update=False, ignore_update=False):
"""Fire the event if reason is that state is updated.""" """Fire the event if reason is that state is updated."""
if "state" in self._device.changed_keys: if ignore_update or "state" not in self._device.changed_keys:
return
data = { data = {
CONF_ID: self.event_id, CONF_ID: self.event_id,
CONF_UNIQUE_ID: self.serial, CONF_UNIQUE_ID: self.serial,
CONF_EVENT: self._device.state, CONF_EVENT: self._device.state,
} }
if self._device.gesture: if self._device.gesture:
data[CONF_GESTURE] = self._device.gesture data[CONF_GESTURE] = self._device.gesture
self.gateway.hass.bus.async_fire(CONF_DECONZ_EVENT, data) self.gateway.hass.bus.async_fire(CONF_DECONZ_EVENT, data)
async def async_update_device_registry(self): async def async_update_device_registry(self):

View file

@ -3,13 +3,17 @@
"name": "deCONZ", "name": "deCONZ",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/deconz", "documentation": "https://www.home-assistant.io/integrations/deconz",
"requirements": ["pydeconz==67"], "requirements": [
"pydeconz==68"
],
"ssdp": [ "ssdp": [
{ {
"manufacturer": "Royal Philips Electronics" "manufacturer": "Royal Philips Electronics"
} }
], ],
"dependencies": [], "dependencies": [],
"codeowners": ["@kane610"], "codeowners": [
"@kane610"
],
"quality_scale": "platinum" "quality_scale": "platinum"
} }

View file

@ -97,11 +97,13 @@ class DeconzSensor(DeconzDevice):
"""Representation of a deCONZ sensor.""" """Representation of a deCONZ sensor."""
@callback @callback
def async_update_callback(self, force_update=False): def async_update_callback(self, force_update=False, ignore_update=False):
"""Update the sensor's state.""" """Update the sensor's state."""
changed = set(self._device.changed_keys) if ignore_update:
return
keys = {"on", "reachable", "state"} keys = {"on", "reachable", "state"}
if force_update or any(key in changed for key in keys): if force_update or self._device.changed_keys.intersection(keys):
self.async_schedule_update_ha_state() self.async_schedule_update_ha_state()
@property @property
@ -155,11 +157,13 @@ class DeconzBattery(DeconzDevice):
"""Battery class for when a device is only represented as an event.""" """Battery class for when a device is only represented as an event."""
@callback @callback
def async_update_callback(self, force_update=False): def async_update_callback(self, force_update=False, ignore_update=False):
"""Update the battery's state, if needed.""" """Update the battery's state, if needed."""
changed = set(self._device.changed_keys) if ignore_update:
return
keys = {"battery", "reachable"} keys = {"battery", "reachable"}
if force_update or any(key in changed for key in keys): if force_update or self._device.changed_keys.intersection(keys):
self.async_schedule_update_ha_state() self.async_schedule_update_ha_state()
@property @property
@ -217,7 +221,7 @@ class DeconzSensorStateTracker:
self.sensor = None self.sensor = None
@callback @callback
def async_update_callback(self): def async_update_callback(self, ignore_update=False):
"""Sensor state updated.""" """Sensor state updated."""
if "battery" in self.sensor.changed_keys: if "battery" in self.sensor.changed_keys:
async_dispatcher_send( async_dispatcher_send(

View file

@ -127,7 +127,7 @@ async def async_refresh_devices_service(hass, data):
scenes = set(gateway.api.scenes.keys()) scenes = set(gateway.api.scenes.keys())
sensors = set(gateway.api.sensors.keys()) sensors = set(gateway.api.sensors.keys())
await gateway.api.refresh_state() await gateway.api.refresh_state(ignore_update=True)
gateway.async_add_device_callback( gateway.async_add_device_callback(
NEW_GROUP, NEW_GROUP,

View file

@ -1188,7 +1188,7 @@ pydaikin==1.6.1
pydanfossair==0.1.0 pydanfossair==0.1.0
# homeassistant.components.deconz # homeassistant.components.deconz
pydeconz==67 pydeconz==68
# homeassistant.components.delijn # homeassistant.components.delijn
pydelijn==0.5.1 pydelijn==0.5.1

View file

@ -417,7 +417,7 @@ pycoolmasternet==0.0.4
pydaikin==1.6.1 pydaikin==1.6.1
# homeassistant.components.deconz # homeassistant.components.deconz
pydeconz==67 pydeconz==68
# homeassistant.components.zwave # homeassistant.components.zwave
pydispatcher==2.0.5 pydispatcher==2.0.5