deCONZ add new device without restart (#14221)
* Add new device without restarting hass * Remove debug prints * Fix copy paste error * Fix comments from balloob Add tests to verify signalling with new added devices * Fix hound comments Add test to verify when new sensor is added * Fix tests * Unload entry should unsubscribe all deconz dispatchers * Make sure mock setup also creates unsub in hass data * Fix copy paste issue * Lint
This commit is contained in:
parent
af8cd63838
commit
8410b63d9c
11 changed files with 212 additions and 48 deletions
|
@ -5,13 +5,14 @@ For more details about this component, please refer to the documentation at
|
|||
https://home-assistant.io/components/light.deconz/
|
||||
"""
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID, DATA_DECONZ_UNSUB)
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_FLASH, ATTR_HS_COLOR,
|
||||
ATTR_TRANSITION, EFFECT_COLORLOOP, FLASH_LONG, FLASH_SHORT,
|
||||
SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP, SUPPORT_EFFECT,
|
||||
SUPPORT_FLASH, SUPPORT_TRANSITION, Light)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
|
@ -19,23 +20,35 @@ DEPENDENCIES = ['deconz']
|
|||
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Old way of setting up deCONZ lights."""
|
||||
"""Old way of setting up deCONZ lights and group."""
|
||||
pass
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_devices):
|
||||
"""Set up the deCONZ lights from a config entry."""
|
||||
lights = hass.data[DATA_DECONZ].lights
|
||||
groups = hass.data[DATA_DECONZ].groups
|
||||
entities = []
|
||||
"""Set up the deCONZ lights and groups from a config entry."""
|
||||
@callback
|
||||
def async_add_light(lights):
|
||||
"""Add light from deCONZ."""
|
||||
entities = []
|
||||
for light in lights:
|
||||
entities.append(DeconzLight(light))
|
||||
async_add_devices(entities, True)
|
||||
hass.data[DATA_DECONZ_UNSUB].append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_light', async_add_light))
|
||||
|
||||
for light in lights.values():
|
||||
entities.append(DeconzLight(light))
|
||||
@callback
|
||||
def async_add_group(groups):
|
||||
"""Add group from deCONZ."""
|
||||
entities = []
|
||||
for group in groups:
|
||||
if group.lights:
|
||||
entities.append(DeconzLight(group))
|
||||
async_add_devices(entities, True)
|
||||
hass.data[DATA_DECONZ_UNSUB].append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_group', async_add_group))
|
||||
|
||||
for group in groups.values():
|
||||
if group.lights: # Don't create entity for group not containing light
|
||||
entities.append(DeconzLight(group))
|
||||
async_add_devices(entities, True)
|
||||
async_add_light(hass.data[DATA_DECONZ].lights.values())
|
||||
async_add_group(hass.data[DATA_DECONZ].groups.values())
|
||||
|
||||
|
||||
class DeconzLight(Light):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue