2019-02-14 15:01:46 +00:00
|
|
|
"""Support for ISY994 lights."""
|
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
|
|
|
|
2020-04-26 16:49:41 +00:00
|
|
|
from homeassistant.components.light import DOMAIN, SUPPORT_BRIGHTNESS, LightEntity
|
2016-09-11 18:18:53 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import ISY994_NODES, ISYDevice
|
|
|
|
|
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
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass, config: ConfigType, add_entities: Callable[[list], None], discovery_info=None
|
|
|
|
):
|
2016-09-11 18:18:53 +00:00
|
|
|
"""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
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices)
|
2015-04-04 10:13:27 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:49:41 +00:00
|
|
|
class ISYLightDevice(ISYDevice, LightEntity):
|
2018-01-29 22:37:19 +00:00
|
|
|
"""Representation of an ISY994 light device."""
|
2015-04-04 10:13:27 +00:00
|
|
|
|
2020-04-17 00:26:34 +00:00
|
|
|
def __init__(self, node) -> None:
|
|
|
|
"""Initialize the ISY994 light device."""
|
|
|
|
super().__init__(node)
|
|
|
|
self._last_brightness = self.brightness
|
|
|
|
|
2016-09-11 18:18:53 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Get whether the ISY994 light is on."""
|
2018-09-30 07:21:27 +00:00
|
|
|
if self.is_unknown():
|
|
|
|
return False
|
2018-09-24 09:43:00 +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."""
|
2018-09-30 07:21:27 +00:00
|
|
|
return None if self.is_unknown() else 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."""
|
2020-04-17 00:26:34 +00:00
|
|
|
self._last_brightness = self.brightness
|
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
|
|
|
|
2020-04-17 00:26:34 +00:00
|
|
|
def on_update(self, event: object) -> None:
|
|
|
|
"""Save brightness in the update event from the ISY994 Node."""
|
|
|
|
if not self.is_unknown() and self.value != 0:
|
|
|
|
self._last_brightness = self.value
|
|
|
|
super().on_update(event)
|
|
|
|
|
2018-02-11 17:20:28 +00:00
|
|
|
# pylint: disable=arguments-differ
|
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."""
|
2020-04-17 00:26:34 +00:00
|
|
|
if brightness is None and self._last_brightness is not None:
|
|
|
|
brightness = self._last_brightness
|
2016-09-11 18:18:53 +00:00
|
|
|
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
|