2015-03-08 14:14:44 +00:00
|
|
|
"""
|
2015-10-20 20:07:24 +00:00
|
|
|
Support for Vera lights.
|
2015-03-08 12:52:50 +00:00
|
|
|
|
2015-10-20 20:07:24 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 12:12:18 +00:00
|
|
|
https://home-assistant.io/components/light.vera/
|
2015-03-08 12:52:50 +00:00
|
|
|
"""
|
2015-03-02 10:09:00 +00:00
|
|
|
import logging
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2016-09-12 13:52:22 +00:00
|
|
|
from homeassistant.components.light import (
|
2018-03-18 22:00:29 +00:00
|
|
|
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ENTITY_ID_FORMAT,
|
|
|
|
SUPPORT_BRIGHTNESS, SUPPORT_COLOR, Light)
|
2016-03-15 09:17:09 +00:00
|
|
|
from homeassistant.components.vera import (
|
2017-03-11 18:06:46 +00:00
|
|
|
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
|
2018-03-18 22:00:29 +00:00
|
|
|
import homeassistant.util.color as color_util
|
2015-12-30 19:44:02 +00:00
|
|
|
|
2015-03-08 12:52:50 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2015-03-02 10:09:00 +00:00
|
|
|
|
2016-09-12 13:52:22 +00:00
|
|
|
DEPENDENCIES = ['vera']
|
|
|
|
|
2015-03-08 14:58:11 +00:00
|
|
|
|
2016-09-12 13:52:22 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Vera lights."""
|
2016-09-12 13:52:22 +00:00
|
|
|
add_devices(
|
2018-06-07 19:31:21 +00:00
|
|
|
[VeraLight(device, hass.data[VERA_CONTROLLER]) for
|
|
|
|
device in hass.data[VERA_DEVICES]['light']], True)
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2015-10-27 23:43:06 +00:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
class VeraLight(VeraDevice, Light):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Representation of a Vera Light, including dimmable."""
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
def __init__(self, vera_device, controller):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Initialize the light."""
|
2016-03-15 09:17:09 +00:00
|
|
|
self._state = False
|
2017-06-15 22:28:24 +00:00
|
|
|
self._color = None
|
|
|
|
self._brightness = None
|
2016-03-15 09:17:09 +00:00
|
|
|
VeraDevice.__init__(self, vera_device, controller)
|
2017-03-11 18:06:46 +00:00
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
2016-02-07 21:45:15 +00:00
|
|
|
|
2015-10-27 23:18:46 +00:00
|
|
|
@property
|
2016-02-07 06:28:29 +00:00
|
|
|
def brightness(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return the brightness of the light."""
|
2017-06-15 22:28:24 +00:00
|
|
|
return self._brightness
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2017-06-08 10:28:03 +00:00
|
|
|
@property
|
2018-03-18 22:00:29 +00:00
|
|
|
def hs_color(self):
|
2017-06-08 10:28:03 +00:00
|
|
|
"""Return the color of the light."""
|
2017-06-15 22:28:24 +00:00
|
|
|
return self._color
|
2017-06-08 10:28:03 +00:00
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
2017-06-15 22:28:24 +00:00
|
|
|
if self._color:
|
2018-03-18 22:00:29 +00:00
|
|
|
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
|
2017-07-06 06:30:01 +00:00
|
|
|
return SUPPORT_BRIGHTNESS
|
2016-08-16 06:07:07 +00:00
|
|
|
|
2015-10-27 23:18:46 +00:00
|
|
|
def turn_on(self, **kwargs):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Turn the light on."""
|
2018-03-18 22:00:29 +00:00
|
|
|
if ATTR_HS_COLOR in kwargs and self._color:
|
|
|
|
rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
|
|
|
|
self.vera_device.set_color(rgb)
|
2017-06-08 10:28:03 +00:00
|
|
|
elif ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
|
2015-10-27 23:18:46 +00:00
|
|
|
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
|
|
|
|
else:
|
|
|
|
self.vera_device.switch_on()
|
|
|
|
|
2017-04-04 10:02:09 +00:00
|
|
|
self._state = True
|
2016-11-30 21:33:38 +00:00
|
|
|
self.schedule_update_ha_state(True)
|
2016-02-07 21:45:15 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Turn the light off."""
|
2016-02-07 21:45:15 +00:00
|
|
|
self.vera_device.switch_off()
|
2017-04-04 10:02:09 +00:00
|
|
|
self._state = False
|
2016-11-30 21:33:38 +00:00
|
|
|
self.schedule_update_ha_state()
|
2016-02-07 21:45:15 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Return true if device is on."""
|
2016-03-15 09:17:09 +00:00
|
|
|
return self._state
|
2016-02-07 21:45:15 +00:00
|
|
|
|
|
|
|
def update(self):
|
2017-05-01 03:10:08 +00:00
|
|
|
"""Call to update state."""
|
2016-03-15 09:17:09 +00:00
|
|
|
self._state = self.vera_device.is_switched_on()
|
2017-06-19 07:54:13 +00:00
|
|
|
if self.vera_device.is_dimmable:
|
|
|
|
# If it is dimmable, both functions exist. In case color
|
|
|
|
# is not supported, it will return None
|
|
|
|
self._brightness = self.vera_device.get_brightness()
|
2018-03-18 22:00:29 +00:00
|
|
|
rgb = self.vera_device.get_color()
|
|
|
|
self._color = color_util.color_RGB_to_hs(*rgb) if rgb else None
|