mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
parent
1be440a72b
commit
c931619269
@ -41,24 +41,26 @@ def get_unit_status(code):
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the x10 Light platform."""
|
"""Set up the x10 Light platform."""
|
||||||
|
is_cm11a = True
|
||||||
try:
|
try:
|
||||||
x10_command('info')
|
x10_command('info')
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
_LOGGER.error(err.output)
|
_LOGGER.info("Assuming that the device is CM17A: %s", err.output)
|
||||||
return False
|
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):
|
class X10Light(Light):
|
||||||
"""Representation of an X10 Light."""
|
"""Representation of an X10 Light."""
|
||||||
|
|
||||||
def __init__(self, light):
|
def __init__(self, light, is_cm11a):
|
||||||
"""Initialize an X10 Light."""
|
"""Initialize an X10 Light."""
|
||||||
self._name = light['name']
|
self._name = light['name']
|
||||||
self._id = light['id']
|
self._id = light['id']
|
||||||
self._brightness = 0
|
self._brightness = 0
|
||||||
self._state = False
|
self._state = False
|
||||||
|
self._is_cm11a = is_cm11a
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -82,15 +84,25 @@ class X10Light(Light):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Instruct the light to turn on."""
|
"""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._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
||||||
self._state = True
|
self._state = True
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Instruct the light to turn off."""
|
"""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
|
self._state = False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch update state."""
|
"""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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user