2016-01-19 13:10:17 +00:00
|
|
|
"""
|
|
|
|
Support for Insteon Hub lights.
|
|
|
|
|
2016-03-07 21:08:21 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/insteon_hub/
|
|
|
|
"""
|
2016-09-02 19:18:32 +00:00
|
|
|
from homeassistant.components.insteon_hub import INSTEON
|
2016-08-16 06:07:07 +00:00
|
|
|
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
|
|
|
SUPPORT_BRIGHTNESS, Light)
|
|
|
|
|
2016-11-05 06:38:27 +00:00
|
|
|
DEPENDENCIES = ['insteon_hub']
|
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
SUPPORT_INSTEON_HUB = SUPPORT_BRIGHTNESS
|
2016-01-19 13:10:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Setup the Insteon Hub light platform."""
|
2016-01-19 13:10:17 +00:00
|
|
|
devs = []
|
|
|
|
for device in INSTEON.devices:
|
|
|
|
if device.DeviceCategory == "Switched Lighting Control":
|
2016-09-02 19:18:32 +00:00
|
|
|
devs.append(InsteonToggleDevice(device))
|
2016-01-29 04:36:40 +00:00
|
|
|
if device.DeviceCategory == "Dimmable Lighting Control":
|
2016-09-02 19:18:32 +00:00
|
|
|
devs.append(InsteonToggleDevice(device))
|
2016-01-19 13:10:17 +00:00
|
|
|
add_devices(devs)
|
2016-05-29 21:31:14 +00:00
|
|
|
|
|
|
|
|
2016-09-02 19:18:32 +00:00
|
|
|
class InsteonToggleDevice(Light):
|
|
|
|
"""An abstract Class for an Insteon node."""
|
2016-05-29 21:31:14 +00:00
|
|
|
|
2016-09-02 19:18:32 +00:00
|
|
|
def __init__(self, node):
|
2016-05-29 21:31:14 +00:00
|
|
|
"""Initialize the device."""
|
2016-09-02 19:18:32 +00:00
|
|
|
self.node = node
|
2016-05-29 21:31:14 +00:00
|
|
|
self._value = 0
|
|
|
|
|
2016-09-02 19:18:32 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the the name of the node."""
|
|
|
|
return self.node.DeviceName
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return the ID of this insteon node."""
|
|
|
|
return self.node.DeviceID
|
|
|
|
|
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light between 0..255."""
|
|
|
|
return self._value / 100 * 255
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update state of the sensor."""
|
|
|
|
resp = self.node.send_command('get_status', wait=True)
|
2016-05-29 21:31:14 +00:00
|
|
|
try:
|
|
|
|
self._value = resp['response']['level']
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
2016-09-02 19:18:32 +00:00
|
|
|
def is_on(self):
|
2016-05-29 21:31:14 +00:00
|
|
|
"""Return the boolean response if the node is on."""
|
|
|
|
return self._value != 0
|
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
@property
|
2016-09-02 19:18:32 +00:00
|
|
|
def supported_features(self):
|
2016-08-16 06:07:07 +00:00
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_INSTEON_HUB
|
|
|
|
|
2016-09-02 19:18:32 +00:00
|
|
|
def turn_on(self, **kwargs):
|
2016-05-29 21:31:14 +00:00
|
|
|
"""Turn device on."""
|
|
|
|
if ATTR_BRIGHTNESS in kwargs:
|
2016-09-02 19:18:32 +00:00
|
|
|
self._value = kwargs[ATTR_BRIGHTNESS] / 255 * 100
|
|
|
|
self.node.send_command('on', self._value)
|
|
|
|
else:
|
|
|
|
self._value = 100
|
|
|
|
self.node.send_command('on')
|
2016-05-29 21:31:14 +00:00
|
|
|
|
2016-09-02 19:18:32 +00:00
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
"""Turn device off."""
|
|
|
|
self.node.send_command('off')
|