2019-02-14 04:35:12 +00:00
|
|
|
"""Support for device connected via Lightwave WiFi-link hub."""
|
2018-12-02 19:58:31 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from homeassistant.const import (CONF_HOST, CONF_LIGHTS, CONF_NAME,
|
|
|
|
CONF_SWITCHES)
|
|
|
|
from homeassistant.helpers.discovery import async_load_platform
|
|
|
|
|
|
|
|
LIGHTWAVE_LINK = 'lightwave_link'
|
2019-02-14 04:35:12 +00:00
|
|
|
|
2018-12-02 19:58:31 +00:00
|
|
|
DOMAIN = 'lightwave'
|
|
|
|
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
|
|
DOMAIN: vol.Schema(
|
2019-03-31 14:19:39 +00:00
|
|
|
vol.All(cv.has_at_least_one_key(CONF_LIGHTS, CONF_SWITCHES), {
|
2018-12-02 19:58:31 +00:00
|
|
|
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}),
|
|
|
|
}
|
|
|
|
})
|
2019-03-31 14:19:39 +00:00
|
|
|
)
|
2018-12-02 19:58:31 +00:00
|
|
|
}, 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:
|
|
|
|
hass.async_create_task(async_load_platform(
|
|
|
|
hass, 'light', DOMAIN, lights, config))
|
|
|
|
|
|
|
|
switches = config[DOMAIN][CONF_SWITCHES]
|
|
|
|
if switches:
|
|
|
|
hass.async_create_task(async_load_platform(
|
|
|
|
hass, 'switch', DOMAIN, switches, config))
|
|
|
|
|
|
|
|
return True
|