From c9316192691e096397964ac30b85b1919b9443f1 Mon Sep 17 00:00:00 2001 From: Sean Wilson Date: Thu, 6 Dec 2018 10:25:59 -0500 Subject: [PATCH] Add CM17A support (#19041) * Add CM17A support. * Update log entry --- homeassistant/components/light/x10.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/light/x10.py b/homeassistant/components/light/x10.py index ef2211a4469..9618a13a1a9 100644 --- a/homeassistant/components/light/x10.py +++ b/homeassistant/components/light/x10.py @@ -41,24 +41,26 @@ def get_unit_status(code): def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the x10 Light platform.""" + is_cm11a = True try: x10_command('info') except CalledProcessError as err: - _LOGGER.error(err.output) - return False + _LOGGER.info("Assuming that the device is CM17A: %s", err.output) + is_cm11a = False - add_entities(X10Light(light) for light in config[CONF_DEVICES]) + add_entities(X10Light(light, is_cm11a) for light in config[CONF_DEVICES]) class X10Light(Light): """Representation of an X10 Light.""" - def __init__(self, light): + def __init__(self, light, is_cm11a): """Initialize an X10 Light.""" self._name = light['name'] self._id = light['id'] self._brightness = 0 self._state = False + self._is_cm11a = is_cm11a @property def name(self): @@ -82,15 +84,25 @@ class X10Light(Light): def turn_on(self, **kwargs): """Instruct the light to turn on.""" - x10_command('on ' + self._id) + if self._is_cm11a: + x10_command('on ' + self._id) + else: + x10_command('fon ' + self._id) self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255) self._state = True def turn_off(self, **kwargs): """Instruct the light to turn off.""" - x10_command('off ' + self._id) + if self._is_cm11a: + x10_command('off ' + self._id) + else: + x10_command('foff ' + self._id) self._state = False def update(self): """Fetch update state.""" - self._state = bool(get_unit_status(self._id)) + if self._is_cm11a: + self._state = bool(get_unit_status(self._id)) + else: + # Not supported on CM17A + pass