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-12-26 08:26:37 +00:00
|
|
|
Light, SUPPORT_BRIGHTNESS, DOMAIN)
|
|
|
|
from homeassistant.components.isy994 import ISY994_NODES, ISYDevice
|
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-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."""
|
|
|
|
devices = []
|
2017-12-26 08:26:37 +00:00
|
|
|
for node in hass.data[ISY994_NODES][DOMAIN]:
|
|
|
|
devices.append(ISYLightDevice(node))
|
2016-09-11 18:18:53 +00:00
|
|
|
|
|
|
|
add_devices(devices)
|
2015-04-04 10:13:27 +00:00
|
|
|
|
|
|
|
|
2017-12-26 08:26:37 +00:00
|
|
|
class ISYLightDevice(ISYDevice, Light):
|
2018-01-29 22:37:19 +00:00
|
|
|
"""Representation of an ISY994 light device."""
|
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."""
|
2017-12-26 08:26:37 +00:00
|
|
|
super().__init__(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
|