From 0335f88e61e32141f3b9354681bc77f38876a83b Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 21 Sep 2016 07:21:06 +0200 Subject: [PATCH] Migrate to voluptuous (#3342) [Breaking Change] --- homeassistant/components/light/x10.py | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/light/x10.py b/homeassistant/components/light/x10.py index 40f5dfa6b73..499bd7513a6 100644 --- a/homeassistant/components/light/x10.py +++ b/homeassistant/components/light/x10.py @@ -6,22 +6,36 @@ https://home-assistant.io/components/light.x10/ """ import logging from subprocess import check_output, CalledProcessError, STDOUT -from homeassistant.components.light import (ATTR_BRIGHTNESS, - SUPPORT_BRIGHTNESS, Light) + +import voluptuous as vol + +from homeassistant.const import (CONF_NAME, CONF_ID, CONF_DEVICES) +from homeassistant.components.light import ( + ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light, PLATFORM_SCHEMA) +import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) SUPPORT_X10 = SUPPORT_BRIGHTNESS +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_DEVICES): vol.All(cv.ensure_list, [ + { + vol.Required(CONF_ID): cv.string, + vol.Required(CONF_NAME): cv.string, + } + ]), +}) + def x10_command(command): """Execute X10 command and check output.""" - return check_output(["heyu"] + command.split(' '), stderr=STDOUT) + return check_output(['heyu'] + command.split(' '), stderr=STDOUT) def get_status(): """Get on/off status for all x10 units in default housecode.""" - output = check_output("heyu info | grep monitored", shell=True) + output = check_output('heyu info | grep monitored', shell=True) return output.decode('utf-8').split(' ')[-1].strip('\n()') @@ -34,12 +48,12 @@ def get_unit_status(code): def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the x10 Light platform.""" try: - x10_command("info") + x10_command('info') except CalledProcessError as err: _LOGGER.error(err.output) return False - add_devices(X10Light(light) for light in config['lights']) + add_devices(X10Light(light) for light in config[CONF_DEVICES]) class X10Light(Light): @@ -74,13 +88,13 @@ class X10Light(Light): def turn_on(self, **kwargs): """Instruct the light to turn on.""" - x10_command("on " + self._id) + x10_command('on ' + self._id) self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255) self._is_on = True def turn_off(self, **kwargs): """Instruct the light to turn off.""" - x10_command("off " + self._id) + x10_command('off ' + self._id) self._is_on = False def update(self):