core/homeassistant/components/light/vera.py

73 lines
2.1 KiB
Python
Raw Normal View History

2015-03-08 14:14:44 +00:00
"""
2015-10-20 20:07:24 +00:00
Support for Vera lights.
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-02 10:09:00 +00:00
import logging
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ENTITY_ID_FORMAT, Light, SUPPORT_BRIGHTNESS)
from homeassistant.const import (STATE_OFF, STATE_ON)
2016-03-15 09:17:09 +00:00
from homeassistant.components.vera import (
VERA_CONTROLLER, VERA_DEVICES, VeraDevice)
2015-12-30 19:44:02 +00:00
_LOGGER = logging.getLogger(__name__)
2015-03-02 10:09:00 +00:00
DEPENDENCIES = ['vera']
SUPPORT_VERA = SUPPORT_BRIGHTNESS
2015-03-08 14:58:11 +00:00
2015-03-08 14:14:44 +00:00
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-03-07 21:08:21 +00:00
"""Setup Vera lights."""
add_devices(
2016-03-15 09:17:09 +00:00
VeraLight(device, VERA_CONTROLLER) for device in VERA_DEVICES['light'])
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."""
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)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
@property
def brightness(self):
2016-03-07 21:08:21 +00:00
"""Return the brightness of the light."""
if self.vera_device.is_dimmable:
return self.vera_device.get_brightness()
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_VERA
def turn_on(self, **kwargs):
2016-03-07 21:08:21 +00:00
"""Turn the light on."""
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()
self._state = STATE_ON
self.schedule_update_ha_state(True)
def turn_off(self, **kwargs):
2016-03-07 21:08:21 +00:00
"""Turn the light off."""
self.vera_device.switch_off()
self._state = STATE_OFF
self.schedule_update_ha_state()
@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
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()