Fix yeelight recorder warning (#22756)

This commit is contained in:
zewelor 2019-04-05 13:32:46 +02:00 committed by Pascal Vizeli
parent 4b877dd96f
commit 5e7fdb479b
2 changed files with 36 additions and 37 deletions

View file

@ -111,37 +111,6 @@ UPDATE_REQUEST_PROPERTIES = [
]
def _transitions_config_parser(transitions):
"""Parse transitions config into initialized objects."""
import yeelight
transition_objects = []
for transition_config in transitions:
transition, params = list(transition_config.items())[0]
transition_objects.append(getattr(yeelight, transition)(*params))
return transition_objects
def _parse_custom_effects(effects_config):
import yeelight
effects = {}
for config in effects_config:
params = config[CONF_FLOW_PARAMS]
action = yeelight.Flow.actions[params[ATTR_ACTION]]
transitions = _transitions_config_parser(
params[ATTR_TRANSITIONS])
effects[config[CONF_NAME]] = {
ATTR_COUNT: params[ATTR_COUNT],
ATTR_ACTION: action,
ATTR_TRANSITIONS: transitions
}
return effects
def setup(hass, config):
"""Set up the Yeelight bulbs."""
conf = config.get(DOMAIN, {})
@ -192,9 +161,8 @@ def _setup_device(hass, hass_config, ipaddr, device_config):
platform_config = device_config.copy()
platform_config[CONF_HOST] = ipaddr
platform_config[CONF_CUSTOM_EFFECTS] = _parse_custom_effects(
platform_config[CONF_CUSTOM_EFFECTS] = \
hass_config.get(DOMAIN, {}).get(CONF_CUSTOM_EFFECTS, {})
)
load_platform(hass, LIGHT_DOMAIN, DOMAIN, platform_config, hass_config)
load_platform(hass, BINARY_SENSOR_DOMAIN, DOMAIN, platform_config,

View file

@ -7,7 +7,7 @@ from homeassistant.helpers.service import extract_entity_ids
from homeassistant.util.color import (
color_temperature_mired_to_kelvin as mired_to_kelvin,
color_temperature_kelvin_to_mired as kelvin_to_mired)
from homeassistant.const import CONF_HOST, ATTR_ENTITY_ID
from homeassistant.const import CONF_HOST, ATTR_ENTITY_ID, CONF_NAME
from homeassistant.core import callback
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_TRANSITION, ATTR_COLOR_TEMP,
@ -19,8 +19,8 @@ from homeassistant.components.yeelight import (
CONF_TRANSITION, DATA_YEELIGHT, CONF_MODE_MUSIC,
CONF_SAVE_ON_CHANGE, CONF_CUSTOM_EFFECTS, DATA_UPDATED,
YEELIGHT_SERVICE_SCHEMA, DOMAIN, ATTR_TRANSITIONS,
YEELIGHT_FLOW_TRANSITION_SCHEMA, _transitions_config_parser,
ACTION_RECOVER)
YEELIGHT_FLOW_TRANSITION_SCHEMA, ACTION_RECOVER, CONF_FLOW_PARAMS,
ATTR_ACTION, ATTR_COUNT)
DEPENDENCIES = ['yeelight']
@ -81,6 +81,37 @@ YEELIGHT_EFFECT_LIST = [
EFFECT_STOP]
def _transitions_config_parser(transitions):
"""Parse transitions config into initialized objects."""
import yeelight
transition_objects = []
for transition_config in transitions:
transition, params = list(transition_config.items())[0]
transition_objects.append(getattr(yeelight, transition)(*params))
return transition_objects
def _parse_custom_effects(effects_config):
import yeelight
effects = {}
for config in effects_config:
params = config[CONF_FLOW_PARAMS]
action = yeelight.Flow.actions[params[ATTR_ACTION]]
transitions = _transitions_config_parser(
params[ATTR_TRANSITIONS])
effects[config[CONF_NAME]] = {
ATTR_COUNT: params[ATTR_COUNT],
ATTR_ACTION: action,
ATTR_TRANSITIONS: transitions
}
return effects
def _cmd(func):
"""Define a wrapper to catch exceptions from the bulb."""
def _wrap(self, *args, **kwargs):
@ -109,7 +140,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
device = hass.data[DATA_YEELIGHT][discovery_info[CONF_HOST]]
_LOGGER.debug("Adding %s", device.name)
custom_effects = discovery_info[CONF_CUSTOM_EFFECTS]
custom_effects = _parse_custom_effects(discovery_info[CONF_CUSTOM_EFFECTS])
lights = [YeelightLight(device, custom_effects=custom_effects)]