2017-01-08 23:33:35 +00:00
|
|
|
"""
|
|
|
|
Support for Insteon dimmers via local hub control.
|
|
|
|
|
|
|
|
For more details about this component, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/light.insteon_local/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from datetime import timedelta
|
2017-01-14 17:42:45 +00:00
|
|
|
|
|
|
|
from homeassistant.components.light import (
|
|
|
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
2017-01-08 23:33:35 +00:00
|
|
|
import homeassistant.util as util
|
|
|
|
|
2017-01-14 17:42:45 +00:00
|
|
|
_CONFIGURING = {}
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ['insteon_local']
|
2017-01-14 17:42:45 +00:00
|
|
|
DOMAIN = 'light'
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
2017-01-14 17:42:45 +00:00
|
|
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
|
2017-01-08 23:33:35 +00:00
|
|
|
|
2017-01-14 17:42:45 +00:00
|
|
|
SUPPORT_INSTEON_LOCAL = SUPPORT_BRIGHTNESS
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-01-14 17:42:45 +00:00
|
|
|
"""Set up the Insteon local light platform."""
|
2017-01-08 23:33:35 +00:00
|
|
|
insteonhub = hass.data['insteon_local']
|
2018-01-08 17:18:10 +00:00
|
|
|
if discovery_info is None:
|
2017-01-08 23:33:35 +00:00
|
|
|
return
|
|
|
|
|
2018-01-08 17:18:10 +00:00
|
|
|
linked = discovery_info['linked']
|
|
|
|
device_list = []
|
|
|
|
for device_id in linked:
|
|
|
|
if linked[device_id]['cat_type'] == 'dimmer':
|
|
|
|
device = insteonhub.dimmer(device_id)
|
|
|
|
device_list.append(
|
|
|
|
InsteonLocalDimmerDevice(device)
|
|
|
|
)
|
2017-01-08 23:33:35 +00:00
|
|
|
|
2018-01-08 17:18:10 +00:00
|
|
|
add_devices(device_list)
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class InsteonLocalDimmerDevice(Light):
|
|
|
|
"""An abstract Class for an Insteon node."""
|
|
|
|
|
2018-01-08 17:18:10 +00:00
|
|
|
def __init__(self, node):
|
2017-01-08 23:33:35 +00:00
|
|
|
"""Initialize the device."""
|
|
|
|
self.node = node
|
|
|
|
self._value = 0
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2017-09-23 15:15:46 +00:00
|
|
|
"""Return the name of the node."""
|
2018-01-08 17:18:10 +00:00
|
|
|
return self.node.device_id
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
2017-01-14 17:42:45 +00:00
|
|
|
"""Return the ID of this Insteon node."""
|
2018-01-30 09:39:39 +00:00
|
|
|
return self.node.device_id
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light between 0..255."""
|
|
|
|
return self._value
|
|
|
|
|
|
|
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
|
|
|
def update(self):
|
|
|
|
"""Update state of the light."""
|
|
|
|
resp = self.node.status(0)
|
2017-03-10 10:14:31 +00:00
|
|
|
|
|
|
|
while 'error' in resp and resp['error'] is True:
|
|
|
|
resp = self.node.status(0)
|
|
|
|
|
2017-01-08 23:33:35 +00:00
|
|
|
if 'cmd2' in resp:
|
|
|
|
self._value = int(resp['cmd2'], 16)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
|
|
|
return self._value != 0
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_INSTEON_LOCAL
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
"""Turn device on."""
|
|
|
|
brightness = 100
|
|
|
|
if ATTR_BRIGHTNESS in kwargs:
|
|
|
|
brightness = int(kwargs[ATTR_BRIGHTNESS]) / 255 * 100
|
|
|
|
|
2017-03-31 06:53:11 +00:00
|
|
|
self.node.change_level(brightness)
|
2017-01-08 23:33:35 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
"""Turn device off."""
|
|
|
|
self.node.off()
|