2015-08-11 12:55:47 +00:00
|
|
|
"""
|
|
|
|
Support for ISY994 lights.
|
2015-11-09 12:12:18 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
2016-09-11 18:18:53 +00:00
|
|
|
https://home-assistant.io/components/light.isy994/
|
2015-08-11 12:55:47 +00:00
|
|
|
"""
|
2015-04-04 10:13:27 +00:00
|
|
|
import logging
|
2016-09-11 18:18:53 +00:00
|
|
|
from typing import Callable
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2016-11-04 21:28:22 +00:00
|
|
|
from homeassistant.components.light import (
|
2017-01-20 06:22:33 +00:00
|
|
|
Light, SUPPORT_BRIGHTNESS)
|
2016-09-11 18:18:53 +00:00
|
|
|
import homeassistant.components.isy994 as isy
|
2017-01-20 06:22:33 +00:00
|
|
|
from homeassistant.const import STATE_ON, STATE_OFF
|
2016-09-11 18:18:53 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2016-08-16 06:07:07 +00:00
|
|
|
|
2016-09-20 03:16:51 +00:00
|
|
|
UOM = ['2', '51', '78']
|
|
|
|
STATES = [STATE_OFF, STATE_ON, 'true', 'false', '%']
|
2016-03-07 21:08:21 +00:00
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def setup_platform(hass, config: ConfigType,
|
|
|
|
add_devices: Callable[[list], None], discovery_info=None):
|
|
|
|
"""Set up the ISY994 light platform."""
|
|
|
|
if isy.ISY is None or not isy.ISY.connected:
|
2017-05-10 10:06:57 +00:00
|
|
|
_LOGGER.error("A connection has not been made to the ISY controller")
|
2015-04-04 10:13:27 +00:00
|
|
|
return False
|
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
devices = []
|
|
|
|
|
2017-05-10 10:06:57 +00:00
|
|
|
for node in isy.filter_nodes(isy.NODES, units=UOM, states=STATES):
|
2016-09-21 15:03:26 +00:00
|
|
|
if node.dimmable or '51' in node.uom:
|
2016-09-11 18:18:53 +00:00
|
|
|
devices.append(ISYLightDevice(node))
|
|
|
|
|
|
|
|
add_devices(devices)
|
2015-04-04 10:13:27 +00:00
|
|
|
|
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
class ISYLightDevice(isy.ISYDevice, Light):
|
|
|
|
"""Representation of an ISY994 light devie."""
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
def __init__(self, node: object) -> None:
|
|
|
|
"""Initialize the ISY994 light device."""
|
|
|
|
isy.ISYDevice.__init__(self, node)
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Get whether the ISY994 light is on."""
|
2017-01-20 06:22:33 +00:00
|
|
|
return self.value > 0
|
2015-08-29 00:17:07 +00:00
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
@property
|
2017-01-20 06:22:33 +00:00
|
|
|
def brightness(self) -> float:
|
|
|
|
"""Get the brightness of the ISY994 light."""
|
|
|
|
return self.value
|
2016-09-11 18:18:53 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs) -> None:
|
|
|
|
"""Send the turn off command to the ISY994 light device."""
|
2016-11-29 16:50:12 +00:00
|
|
|
if not self._node.off():
|
2017-06-21 07:38:12 +00:00
|
|
|
_LOGGER.debug("Unable to turn off light")
|
2016-09-11 18:18:53 +00:00
|
|
|
|
2016-11-29 16:50:12 +00:00
|
|
|
def turn_on(self, brightness=None, **kwargs) -> None:
|
2016-09-11 18:18:53 +00:00
|
|
|
"""Send the turn on command to the ISY994 light device."""
|
|
|
|
if not self._node.on(val=brightness):
|
2017-05-10 10:06:57 +00:00
|
|
|
_LOGGER.debug("Unable to turn on light")
|
2016-09-20 03:16:51 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_BRIGHTNESS
|