mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Improved x10 state monitoring (#5115)
* Improved x10 state monitoring * Improved x10 state monitoring * Use update mthod to fetch state change * Use update mthod to fetch state change * Use update function to fetch status * remove temp file * Add doc string to update method
This commit is contained in:
parent
c72f8b1a06
commit
e4a45fa857
@ -33,16 +33,10 @@ def x10_command(command):
|
|||||||
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)
|
|
||||||
return output.decode('utf-8').split(' ')[-1].strip('\n()')
|
|
||||||
|
|
||||||
|
|
||||||
def get_unit_status(code):
|
def get_unit_status(code):
|
||||||
"""Get on/off status for given unit."""
|
"""Get on/off status for given unit."""
|
||||||
unit = int(code[1:])
|
output = check_output('heyu onstate ' + code, shell=True)
|
||||||
return get_status()[16 - int(unit)] == '1'
|
return int(output.decode('utf-8')[0])
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
@ -63,8 +57,8 @@ class X10Light(Light):
|
|||||||
"""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._is_on = False
|
|
||||||
self._brightness = 0
|
self._brightness = 0
|
||||||
|
self._state = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -79,7 +73,7 @@ class X10Light(Light):
|
|||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
return self._is_on
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
@ -90,13 +84,13 @@ class X10Light(Light):
|
|||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
x10_command('on ' + self._id)
|
x10_command('on ' + self._id)
|
||||||
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
|
||||||
self._is_on = 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)
|
x10_command('off ' + self._id)
|
||||||
self._is_on = False
|
self._state = False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch update state."""
|
||||||
self._is_on = get_unit_status(self._id)
|
self._state = bool(get_unit_status(self._id))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user