Migrate to voluptuous (#3342) [Breaking Change]

This commit is contained in:
Fabian Affolter 2016-09-21 07:21:06 +02:00 committed by Paulus Schoutsen
parent 769bc37150
commit 0335f88e61

View File

@ -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):