Skip to content

Commit

Permalink
Migrate to voluptuous (#3342) [Breaking Change]
Browse files Browse the repository at this point in the history
  • Loading branch information
fabaff authored and balloob committed Sep 21, 2016
1 parent 769bc37 commit 0335f88
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions homeassistant/components/light/x10.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,36 @@
"""
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()')


Expand All @@ -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):
Expand Down Expand Up @@ -74,13 +88,13 @@ def supported_features(self):

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):
Expand Down

0 comments on commit 0335f88

Please sign in to comment.