hass-core/homeassistant/components/lightwave.py
GeoffAtHome eb584a26e2 Add lightwave components for switches and lights (#18026)
* Added lightwave components for switches and lights.

* Address warnings raised by Hound

* Correcting lint messages and major typo. This time tested before commit.

* Trying to fix author

* Minor lint changes

* Attempt to correct other lint error.

* Another lint attempt.

* More lint issues.

* Last two lint errors! Hurrah.

* Changes after review from fabaff.

* Moved device dependent code to PyPi.

* Replaced DEPENDENCIES with REQUIREMENTS

* Updated following code review from Martin Hjelmare.

* Added lightwave to requirements_all.txt

* Omit lightwave from tests.

* Updated requirements_all.txt

* Refactored how lightwave lights and switches load.

* Removed imports that were no longer required.

* Add guard for no discovery_info.

* Make it a guard clause and save indentation. Rename LRFxxx to LWRFxxx.

* Sorted imports to match style guidelines.

* Correct return value.

* Update requirements_all.txt

* Catch case where we have no lights or switches configured.

* Improve configuration validation.
2018-12-02 20:58:31 +01:00

49 lines
1.6 KiB
Python

"""
Support for device connected via Lightwave WiFi-link hub.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/lightwave/
"""
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
REQUIREMENTS = ['lightwave==0.15']
LIGHTWAVE_LINK = 'lightwave_link'
DOMAIN = 'lightwave'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema(
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:
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