deCONZ - retry if setup fails (#17772)

* Make component retry if setup fails
* Improve overall test coverage
This commit is contained in:
Robert Svensson 2018-10-31 22:38:04 +01:00 committed by GitHub
parent 145677ed75
commit a9140dc8f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 823 additions and 475 deletions

View file

@ -6,7 +6,7 @@ https://home-assistant.io/components/sensor.deconz/
"""
from homeassistant.components.deconz.const import (
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DATA_DECONZ,
DATA_DECONZ_ID, DATA_DECONZ_UNSUB, DECONZ_DOMAIN)
DECONZ_DOMAIN)
from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_VOLTAGE, DEVICE_CLASS_BATTERY)
from homeassistant.core import callback
@ -46,10 +46,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities.append(DeconzSensor(sensor))
async_add_entities(entities, True)
hass.data[DATA_DECONZ_UNSUB].append(
hass.data[DATA_DECONZ].listeners.append(
async_dispatcher_connect(hass, 'deconz_new_sensor', async_add_sensor))
async_add_sensor(hass.data[DATA_DECONZ].sensors.values())
async_add_sensor(hass.data[DATA_DECONZ].api.sensors.values())
class DeconzSensor(Entity):
@ -62,7 +62,8 @@ class DeconzSensor(Entity):
async def async_added_to_hass(self):
"""Subscribe to sensors events."""
self._sensor.register_async_callback(self.async_update_callback)
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._sensor.deconz_id
self.hass.data[DATA_DECONZ].deconz_ids[self.entity_id] = \
self._sensor.deconz_id
async def async_will_remove_from_hass(self) -> None:
"""Disconnect sensor object when removed."""
@ -147,7 +148,7 @@ class DeconzSensor(Entity):
self._sensor.uniqueid.count(':') != 7):
return None
serial = self._sensor.uniqueid.split('-', 1)[0]
bridgeid = self.hass.data[DATA_DECONZ].config.bridgeid
bridgeid = self.hass.data[DATA_DECONZ].api.config.bridgeid
return {
'connections': {(CONNECTION_ZIGBEE, serial)},
'identifiers': {(DECONZ_DOMAIN, serial)},
@ -171,7 +172,8 @@ class DeconzBattery(Entity):
async def async_added_to_hass(self):
"""Subscribe to sensors events."""
self._sensor.register_async_callback(self.async_update_callback)
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._sensor.deconz_id
self.hass.data[DATA_DECONZ].deconz_ids[self.entity_id] = \
self._sensor.deconz_id
async def async_will_remove_from_hass(self) -> None:
"""Disconnect sensor object when removed."""
@ -181,7 +183,7 @@ class DeconzBattery(Entity):
@callback
def async_update_callback(self, reason):
"""Update the battery's state, if needed."""
if 'battery' in reason['attr']:
if 'reachable' in reason['attr'] or 'battery' in reason['attr']:
self.async_schedule_update_ha_state()
@property
@ -229,7 +231,7 @@ class DeconzBattery(Entity):
self._sensor.uniqueid.count(':') != 7):
return None
serial = self._sensor.uniqueid.split('-', 1)[0]
bridgeid = self.hass.data[DATA_DECONZ].config.bridgeid
bridgeid = self.hass.data[DATA_DECONZ].api.config.bridgeid
return {
'connections': {(CONNECTION_ZIGBEE, serial)},
'identifiers': {(DECONZ_DOMAIN, serial)},