Add configuration check and use default var names (#7963)

This commit is contained in:
Fabian Affolter 2017-06-09 00:21:06 +02:00 committed by Pascal Vizeli
parent 055db05946
commit aaaf9637eb
2 changed files with 18 additions and 8 deletions

View File

@ -11,14 +11,14 @@ from homeassistant.components.light import (
from homeassistant.components.lutron import ( from homeassistant.components.lutron import (
LutronDevice, LUTRON_DEVICES, LUTRON_CONTROLLER) LutronDevice, LUTRON_DEVICES, LUTRON_CONTROLLER)
DEPENDENCIES = ['lutron']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['lutron']
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Lutron lights.""" """Set up the Lutron lights."""
devs = [] devs = []
for (area_name, device) in hass.data[LUTRON_DEVICES]['light']: for (area_name, device) in hass.data[LUTRON_DEVICES]['light']:
dev = LutronLight(area_name, device, hass.data[LUTRON_CONTROLLER]) dev = LutronLight(area_name, device, hass.data[LUTRON_CONTROLLER])

View File

@ -7,6 +7,10 @@ https://home-assistant.io/components/lutron/
import asyncio import asyncio
import logging import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import discovery from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -19,6 +23,14 @@ _LOGGER = logging.getLogger(__name__)
LUTRON_CONTROLLER = 'lutron_controller' LUTRON_CONTROLLER = 'lutron_controller'
LUTRON_DEVICES = 'lutron_devices' LUTRON_DEVICES = 'lutron_devices'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
})
}, extra=vol.ALLOW_EXTRA)
def setup(hass, base_config): def setup(hass, base_config):
"""Set up the Lutron component.""" """Set up the Lutron component."""
@ -29,13 +41,11 @@ def setup(hass, base_config):
config = base_config.get(DOMAIN) config = base_config.get(DOMAIN)
hass.data[LUTRON_CONTROLLER] = Lutron( hass.data[LUTRON_CONTROLLER] = Lutron(
config['lutron_host'], config[CONF_HOST], config[CONF_USERNAME], config[CONF_USERNAME])
config['lutron_user'],
config['lutron_password']
)
hass.data[LUTRON_CONTROLLER].load_xml_db() hass.data[LUTRON_CONTROLLER].load_xml_db()
hass.data[LUTRON_CONTROLLER].connect() hass.data[LUTRON_CONTROLLER].connect()
_LOGGER.info("Connected to Main Repeater at %s", config['lutron_host']) _LOGGER.info("Connected to main repeater at %s", config[CONF_HOST])
# Sort our devices into types # Sort our devices into types
for area in hass.data[LUTRON_CONTROLLER].areas: for area in hass.data[LUTRON_CONTROLLER].areas: