Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CM17A support #19041

Merged
merged 2 commits into from Dec 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 19 additions & 7 deletions homeassistant/components/light/x10.py
Expand Up @@ -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):
Expand All @@ -82,15 +84,25 @@ def supported_features(self):

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