Support multiple deCONZ gateways (#22449)
* Store gateways inside a dict in deconz domain * Make reachable events gateway specific * Gateway shall always exist * Adapt new device signalling to support multiple gateways * Services follow gateway master * Working on unload entry * Make unload and master handover work Improve tests for init * Fix config flow * Fix linting * Clean up init tests * Clean up hassio discovery to fit with the rest * Store gateways inside a dict in deconz domain * Make reachable events gateway specific * Gateway shall always exist * Adapt new device signalling to support multiple gateways * Services follow gateway master * Working on unload entry * Make unload and master handover work Improve tests for init * Fix config flow * Fix linting * Clean up init tests * Clean up hassio discovery to fit with the rest * Add support for services to specify bridgeid
This commit is contained in:
1 parent
b9ec623ad9
commit
b50afec5f1
22 files changed
+535
-426
No files matched your search
@@ -3,8 +3,9 @@ from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import DOMAIN as DECONZ_DOMAIN, NEW_LIGHT, POWER_PLUGS, SIRENS
|
||||
from .const import NEW_LIGHT, POWER_PLUGS, SIRENS
|
||||
from .deconz_device import DeconzDevice
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
|
||||
@@ -20,21 +21,25 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
Switches are based same device class as lights in deCONZ.
|
||||
"""
|
||||
gateway = hass.data[DECONZ_DOMAIN]
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
|
||||
@callback
|
||||
def async_add_switch(lights):
|
||||
"""Add switch from deCONZ."""
|
||||
entities = []
|
||||
|
||||
for light in lights:
|
||||
|
||||
if light.type in POWER_PLUGS:
|
||||
entities.append(DeconzPowerPlug(light, gateway))
|
||||
|
||||
elif light.type in SIRENS:
|
||||
entities.append(DeconzSiren(light, gateway))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
gateway.listeners.append(
|
||||
async_dispatcher_connect(hass, NEW_LIGHT, async_add_switch))
|
||||
gateway.listeners.append(async_dispatcher_connect(
|
||||
hass, gateway.async_event_new_device(NEW_LIGHT), async_add_switch))
|
||||
|
||||
async_add_switch(gateway.api.lights.values())
|
||||
|
||||
|
||||
Reference in new issue
Block a user