Add VeraLight class based on VeraSwitch - add dimmer support

pull/560/head
pavoni 2015-10-27 23:18:46 +00:00
parent 49f4d92c62
commit 6ef0d089ea
1 changed files with 28 additions and 1 deletions

View File

@ -7,9 +7,13 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.vera.html
"""
import logging
import time
from requests.exceptions import RequestException
from homeassistant.components.switch.vera import VeraSwitch
from homeassistant.components.light import Light, ATTR_BRIGHTNESS
REQUIREMENTS = ['https://github.com/balloob/home-assistant-vera-api/archive/'
'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip'
'#python-vera==0.1']
@ -47,6 +51,29 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
exclude = extra_data.get('exclude', False)
if exclude is not True:
lights.append(VeraSwitch(device, extra_data))
lights.append(VeraLight(device, extra_data))
add_devices_callback(lights)
class VeraLight(VeraSwitch):
""" Represents a Vera Light, including dimmable. """
@property
def state_attributes(self):
attr = super().state_attributes or {}
if self.vera_device.is_dimmable:
attr[ATTR_BRIGHTNESS] = self.vera_device.get_brightness()
return attr
def turn_on(self, **kwargs):
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.last_command_send = time.time()
self.is_on_status = True