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
|
|
|
|
2019-02-14 15:01:46 +00:00
|
|
|
from homeassistant.components.light import DOMAIN, SUPPORT_BRIGHTNESS, Light
|
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
|
|
|
|
|
|
|
def setup_platform(hass, config: ConfigType,
|
2018-08-24 14:37:30 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
@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."""
|
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
|
|
|
|
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."""
|
|
|
|
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
|