mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Add VeraLight class based on VeraSwitch - add dimmer support
This commit is contained in:
parent
49f4d92c62
commit
6ef0d089ea
@ -7,9 +7,13 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/light.vera.html
|
https://home-assistant.io/components/light.vera.html
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
from homeassistant.components.switch.vera import VeraSwitch
|
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/'
|
REQUIREMENTS = ['https://github.com/balloob/home-assistant-vera-api/archive/'
|
||||||
'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip'
|
'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip'
|
||||||
'#python-vera==0.1']
|
'#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)
|
exclude = extra_data.get('exclude', False)
|
||||||
|
|
||||||
if exclude is not True:
|
if exclude is not True:
|
||||||
lights.append(VeraSwitch(device, extra_data))
|
lights.append(VeraLight(device, extra_data))
|
||||||
|
|
||||||
add_devices_callback(lights)
|
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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user