Fix the optional friendly name of the Yeelight (Closes: #14088) (#14110)

This commit is contained in:
Sebastian Muszynski 2018-04-28 12:35:19 +02:00 committed by Fabian Affolter
parent 7e39a5c4d5
commit 58ae8d91f9

View File

@ -32,16 +32,17 @@ LEGACY_DEVICE_TYPE_MAP = {
'ceiling1': 'ceiling',
}
CONF_TRANSITION = 'transition'
DEFAULT_NAME = 'Yeelight'
DEFAULT_TRANSITION = 350
CONF_TRANSITION = 'transition'
CONF_SAVE_ON_CHANGE = 'save_on_change'
CONF_MODE_MUSIC = 'use_music_mode'
DATA_KEY = 'light.yeelight'
DEVICE_SCHEMA = vol.Schema({
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_TRANSITION, default=DEFAULT_TRANSITION): cv.positive_int,
vol.Optional(CONF_MODE_MUSIC, default=False): cv.boolean,
vol.Optional(CONF_SAVE_ON_CHANGE, default=True): cv.boolean,
@ -136,20 +137,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# Not using hostname, as it seems to vary.
name = "yeelight_%s_%s" % (device_type,
discovery_info['properties']['mac'])
device = {'name': name, 'ipaddr': discovery_info['host']}
host = discovery_info['host']
device = {'name': name, 'ipaddr': host}
light = YeelightLight(device, DEVICE_SCHEMA({}))
lights.append(light)
hass.data[DATA_KEY][name] = light
hass.data[DATA_KEY][host] = light
else:
for ipaddr, device_config in config[CONF_DEVICES].items():
name = device_config[CONF_NAME]
_LOGGER.debug("Adding configured %s", name)
device = {'name': name, 'ipaddr': ipaddr}
for host, device_config in config[CONF_DEVICES].items():
device = {'name': device_config[CONF_NAME], 'ipaddr': host}
light = YeelightLight(device, device_config)
lights.append(light)
hass.data[DATA_KEY][name] = light
hass.data[DATA_KEY][host] = light
add_devices(lights, True)