Config flow tradfri (#16665)
* Fix comments * Add config flow tests * Fix Tradfri light tests * Lint * Remove import group from config flow * fix stale comments
This commit is contained in:
parent
3160fa5de8
commit
a1c524d372
13 changed files with 519 additions and 262 deletions
|
@ -13,8 +13,9 @@ from homeassistant.components.light import (
|
|||
SUPPORT_COLOR, Light)
|
||||
from homeassistant.components.light import \
|
||||
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA
|
||||
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_TRADFRI_GROUPS, \
|
||||
KEY_API
|
||||
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_API
|
||||
from homeassistant.components.tradfri.const import (
|
||||
CONF_IMPORT_GROUPS, CONF_GATEWAY_ID)
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -31,28 +32,21 @@ SUPPORTED_FEATURES = SUPPORT_TRANSITION
|
|||
SUPPORTED_GROUP_FEATURES = SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config,
|
||||
async_add_entities, discovery_info=None):
|
||||
"""Set up the IKEA Tradfri Light platform."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Load Tradfri lights based on a config entry."""
|
||||
gateway_id = config_entry.data[CONF_GATEWAY_ID]
|
||||
api = hass.data[KEY_API][config_entry.entry_id]
|
||||
gateway = hass.data[KEY_GATEWAY][config_entry.entry_id]
|
||||
|
||||
gateway_id = discovery_info['gateway']
|
||||
api = hass.data[KEY_API][gateway_id]
|
||||
gateway = hass.data[KEY_GATEWAY][gateway_id]
|
||||
|
||||
devices_command = gateway.get_devices()
|
||||
devices_commands = await api(devices_command)
|
||||
devices_commands = await api(gateway.get_devices())
|
||||
devices = await api(devices_commands)
|
||||
lights = [dev for dev in devices if dev.has_light_control]
|
||||
if lights:
|
||||
async_add_entities(
|
||||
TradfriLight(light, api, gateway_id) for light in lights)
|
||||
|
||||
allow_tradfri_groups = hass.data[KEY_TRADFRI_GROUPS][gateway_id]
|
||||
if allow_tradfri_groups:
|
||||
groups_command = gateway.get_groups()
|
||||
groups_commands = await api(groups_command)
|
||||
if config_entry.data[CONF_IMPORT_GROUPS]:
|
||||
groups_commands = await api(gateway.get_groups())
|
||||
groups = await api(groups_commands)
|
||||
if groups:
|
||||
async_add_entities(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue