Deconz make groups configurable (#14704)
* Make groups configurable * Config flow and tests in place * Fix too long line
This commit is contained in:
1 parent
940577e105
commit
ac13a2736b
7 files changed
+46
-12
No files matched your search
@@ -23,7 +23,8 @@
|
||||
"options": {
|
||||
"title": "Extra configuration options for deCONZ",
|
||||
"data": {
|
||||
"allow_clip_sensor": "Allow importing virtual sensors"
|
||||
"allow_clip_sensor": "Allow importing virtual sensors",
|
||||
"allow_deconz_groups": "Allow importing deCONZ groups"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -8,7 +8,9 @@ from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.util.json import load_json
|
||||
|
||||
from .const import CONF_ALLOW_CLIP_SENSOR, CONFIG_FILE, DOMAIN
|
||||
from .const import (
|
||||
CONF_ALLOW_DECONZ_GROUPS, CONF_ALLOW_CLIP_SENSOR, CONFIG_FILE, DOMAIN)
|
||||
|
||||
|
||||
CONF_BRIDGEID = 'bridgeid'
|
||||
|
||||
@@ -94,12 +96,15 @@ class DeconzFlowHandler(data_entry_flow.FlowHandler):
|
||||
"""Extra options for deCONZ.
|
||||
|
||||
CONF_CLIP_SENSOR -- Allow user to choose if they want clip sensors.
|
||||
CONF_DECONZ_GROUPS -- Allow user to choose if they want deCONZ groups.
|
||||
"""
|
||||
from pydeconz.utils import async_get_bridgeid
|
||||
|
||||
if user_input is not None:
|
||||
self.deconz_config[CONF_ALLOW_CLIP_SENSOR] = \
|
||||
user_input[CONF_ALLOW_CLIP_SENSOR]
|
||||
self.deconz_config[CONF_ALLOW_DECONZ_GROUPS] = \
|
||||
user_input[CONF_ALLOW_DECONZ_GROUPS]
|
||||
|
||||
if CONF_BRIDGEID not in self.deconz_config:
|
||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||
@@ -115,6 +120,7 @@ class DeconzFlowHandler(data_entry_flow.FlowHandler):
|
||||
step_id='options',
|
||||
data_schema=vol.Schema({
|
||||
vol.Optional(CONF_ALLOW_CLIP_SENSOR): bool,
|
||||
vol.Optional(CONF_ALLOW_DECONZ_GROUPS): bool,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -158,6 +164,7 @@ class DeconzFlowHandler(data_entry_flow.FlowHandler):
|
||||
return await self.async_step_link()
|
||||
|
||||
self.deconz_config[CONF_ALLOW_CLIP_SENSOR] = True
|
||||
self.deconz_config[CONF_ALLOW_DECONZ_GROUPS] = True
|
||||
return self.async_create_entry(
|
||||
title='deCONZ-' + self.deconz_config[CONF_BRIDGEID],
|
||||
data=self.deconz_config
|
||||
|
||||
@@ -10,3 +10,4 @@ DATA_DECONZ_ID = 'deconz_entities'
|
||||
DATA_DECONZ_UNSUB = 'deconz_dispatchers'
|
||||
|
||||
CONF_ALLOW_CLIP_SENSOR = 'allow_clip_sensor'
|
||||
CONF_ALLOW_DECONZ_GROUPS = 'allow_deconz_groups'
|
||||
@@ -16,7 +16,8 @@
|
||||
"options": {
|
||||
"title": "Extra configuration options for deCONZ",
|
||||
"data":{
|
||||
"allow_clip_sensor": "Allow importing virtual sensors"
|
||||
"allow_clip_sensor": "Allow importing virtual sensors",
|
||||
"allow_deconz_groups": "Allow importing deCONZ groups"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ https://home-assistant.io/components/light.deconz/
|
||||
"""
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID, DATA_DECONZ_UNSUB)
|
||||
from homeassistant.components.deconz.const import CONF_ALLOW_DECONZ_GROUPS
|
||||
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,
|
||||
@@ -33,6 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
|
||||
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))
|
||||
|
||||
@@ -40,10 +42,12 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
|
||||
def async_add_group(groups):
|
||||
"""Add group from deCONZ."""
|
||||
entities = []
|
||||
allow_group = config_entry.data.get(CONF_ALLOW_DECONZ_GROUPS, True)
|
||||
for group in groups:
|
||||
if group.lights:
|
||||
if group.lights and allow_group:
|
||||
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))
|
||||
|
||||
|
||||
Reference in new issue
Block a user