2015-03-09 01:14:44 +11:00
|
|
|
"""
|
2015-10-20 22:07:24 +02:00
|
|
|
Support for Vera lights.
|
2015-03-08 23:52:50 +11:00
|
|
|
|
2015-10-20 22:07:24 +02:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 13:12:18 +01:00
|
|
|
https://home-assistant.io/components/light.vera/
|
2015-03-08 23:52:50 +11:00
|
|
|
"""
|
2015-03-02 21:09:00 +11:00
|
|
|
import logging
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2016-08-16 09:07:07 +03:00
|
|
|
from homeassistant.components.light import (ATTR_BRIGHTNESS,
|
|
|
|
SUPPORT_BRIGHTNESS, Light)
|
2016-02-07 21:45:15 +00:00
|
|
|
from homeassistant.const import (
|
2016-03-15 09:17:09 +00:00
|
|
|
STATE_OFF, STATE_ON)
|
|
|
|
from homeassistant.components.vera import (
|
|
|
|
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
|
2015-12-30 19:44:02 +00:00
|
|
|
|
2016-03-15 09:17:09 +00:00
|
|
|
DEPENDENCIES = ['vera']
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2015-03-08 23:52:50 +11:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2015-03-02 21:09:00 +11:00
|
|
|
|
2016-08-16 09:07:07 +03:00
|
|
|
SUPPORT_VERA = SUPPORT_BRIGHTNESS
|
|
|
|
|
2015-03-09 01:58:11 +11:00
|
|
|
|
2015-03-09 01:14:44 +11:00
|
|
|
# pylint: disable=unused-argument
|
2015-03-02 21:09:00 +11:00
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2016-03-07 22:08:21 +01:00
|
|
|
"""Setup Vera lights."""
|
2016-03-15 09:17:09 +00:00
|
|
|
add_devices_callback(
|
|
|
|
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 22:08:21 +01: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 22:08:21 +01: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-06 22:28:29 -08:00
|
|
|
def brightness(self):
|
2016-03-07 22:08:21 +01: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 09:07:07 +03: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 22:08:21 +01: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-01-15 21:30:58 +00:00
|
|
|
self.update_ha_state(True)
|
2016-02-07 21:45:15 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2016-03-07 22:08:21 +01:00
|
|
|
"""Turn the light off."""
|
2016-02-07 21:45:15 +00:00
|
|
|
self.vera_device.switch_off()
|
|
|
|
self._state = STATE_OFF
|
|
|
|
self.update_ha_state()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-07 22:08:21 +01: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 22:08:21 +01: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()
|