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 (
|
|
|
|
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
|
|
|
from homeassistant.const import (STATE_OFF, STATE_ON)
|
2016-03-15 09:17:09 +00:00
|
|
|
from homeassistant.components.vera import (
|
|
|
|
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
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']
|
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
SUPPORT_VERA = SUPPORT_BRIGHTNESS
|
|
|
|
|
2015-03-08 14:58:11 +00:00
|
|
|
|
2015-03-08 14:14:44 +00:00
|
|
|
# pylint: disable=unused-argument
|
2016-09-12 13:52:22 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Setup Vera lights."""
|
2016-09-12 13:52:22 +00:00
|
|
|
add_devices(
|
2016-03-15 09:17:09 +00:00
|
|
|
VeraLight(device, VERA_CONTROLLER) for device in VERA_DEVICES['light'])
|
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
|
|
|
|
VeraDevice.__init__(self, vera_device, controller)
|
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."""
|
2016-02-07 21:45:15 +00:00
|
|
|
if self.vera_device.is_dimmable:
|
|
|
|
return self.vera_device.get_brightness()
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2016-08-16 06:07:07 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_VERA
|
|
|
|
|
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."""
|
2015-10-27 23:18:46 +00:00
|
|
|
if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
|
|
|
|
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
|
|
|
|
else:
|
|
|
|
self.vera_device.switch_on()
|
|
|
|
|
2016-01-10 12:30:47 +00:00
|
|
|
self._state = STATE_ON
|
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()
|
|
|
|
self._state = STATE_OFF
|
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):
|
2016-03-07 21:08:21 +00:00
|
|
|
"""Called by the vera device callback to update state."""
|
2016-03-15 09:17:09 +00:00
|
|
|
self._state = self.vera_device.is_switched_on()
|