core/homeassistant/components/lightwave/__init__.py

53 lines
1.5 KiB
Python
Raw Normal View History

"""Support for device connected via Lightwave WiFi-link hub."""
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
2019-07-31 19:25:30 +00:00
from homeassistant.const import CONF_HOST, CONF_LIGHTS, CONF_NAME, CONF_SWITCHES
from homeassistant.helpers.discovery import async_load_platform
2019-07-31 19:25:30 +00:00
LIGHTWAVE_LINK = "lightwave_link"
2019-07-31 19:25:30 +00:00
DOMAIN = "lightwave"
2019-07-31 19:25:30 +00:00
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
vol.All(
cv.has_at_least_one_key(CONF_LIGHTS, CONF_SWITCHES),
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_LIGHTS, default={}): {
cv.string: vol.Schema({vol.Required(CONF_NAME): cv.string})
},
vol.Optional(CONF_SWITCHES, default={}): {
cv.string: vol.Schema({vol.Required(CONF_NAME): cv.string})
},
},
)
)
},
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass, config):
"""Try to start embedded Lightwave broker."""
from lightwave.lightwave import LWLink
host = config[DOMAIN][CONF_HOST]
hass.data[LIGHTWAVE_LINK] = LWLink(host)
lights = config[DOMAIN][CONF_LIGHTS]
if lights:
2019-07-31 19:25:30 +00:00
hass.async_create_task(
async_load_platform(hass, "light", DOMAIN, lights, config)
)
switches = config[DOMAIN][CONF_SWITCHES]
if switches:
2019-07-31 19:25:30 +00:00
hass.async_create_task(
async_load_platform(hass, "switch", DOMAIN, switches, config)
)
return True