diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 2c9cac640f0..21df4485527 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -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 +