From 49f4d92c62a28a3ebddf7f36b0c7983b603fccbb Mon Sep 17 00:00:00 2001 From: pavoni Date: Mon, 26 Oct 2015 10:51:23 +0000 Subject: [PATCH 1/4] Add dimmer as switch --- homeassistant/components/light/vera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index dc447f2e4b5..2c9cac640f0 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -35,7 +35,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): controller = veraApi.VeraController(base_url) devices = [] try: - devices = controller.get_devices(['Switch', 'On/Off Switch']) + devices = controller.get_devices(['Switch', 'On/Off Switch', 'Dimmable Switch']) except RequestException: # There was a network related error connecting to the vera controller _LOGGER.exception("Error communicating with Vera API") From 6ef0d089eae6dc7bc5ab754aefc36d47a84c0706 Mon Sep 17 00:00:00 2001 From: pavoni Date: Tue, 27 Oct 2015 23:18:46 +0000 Subject: [PATCH 2/4] Add VeraLight class based on VeraSwitch - add dimmer support --- homeassistant/components/light/vera.py | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 + From 031d5ce2553120b23f38019d66f919469cc9c4d3 Mon Sep 17 00:00:00 2001 From: pavoni Date: Tue, 27 Oct 2015 23:43:06 +0000 Subject: [PATCH 3/4] Fix style issues, update pyvera version. --- homeassistant/components/light/vera.py | 16 +++++++++------- homeassistant/components/switch/vera.py | 6 +++--- requirements_all.txt | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 21df4485527..2e9e02ebbe5 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -12,11 +12,11 @@ import time from requests.exceptions import RequestException from homeassistant.components.switch.vera import VeraSwitch -from homeassistant.components.light import Light, ATTR_BRIGHTNESS +from homeassistant.components.light import ATTR_BRIGHTNESS -REQUIREMENTS = ['https://github.com/balloob/home-assistant-vera-api/archive/' - 'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip' - '#python-vera==0.1'] +REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/' + '90e203b58c5897930a9567252943b7c96c39652b.zip' + '#python-vera==0.1.1'] _LOGGER = logging.getLogger(__name__) @@ -39,7 +39,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): controller = veraApi.VeraController(base_url) devices = [] try: - devices = controller.get_devices(['Switch', 'On/Off Switch', 'Dimmable Switch']) + devices = controller.get_devices([ + 'Switch', + 'On/Off Switch', + 'Dimmable Switch']) except RequestException: # There was a network related error connecting to the vera controller _LOGGER.exception("Error communicating with Vera API") @@ -55,6 +58,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): add_devices_callback(lights) + class VeraLight(VeraSwitch): """ Represents a Vera Light, including dimmable. """ @@ -67,7 +71,6 @@ class VeraLight(VeraSwitch): 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]) @@ -76,4 +79,3 @@ class VeraLight(VeraSwitch): self.last_command_send = time.time() self.is_on_status = True - diff --git a/homeassistant/components/switch/vera.py b/homeassistant/components/switch/vera.py index ecf922e8cfa..55e519d8616 100644 --- a/homeassistant/components/switch/vera.py +++ b/homeassistant/components/switch/vera.py @@ -15,9 +15,9 @@ from homeassistant.helpers.entity import ToggleEntity from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME) -REQUIREMENTS = ['https://github.com/balloob/home-assistant-vera-api/archive/' - 'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip' - '#python-vera==0.1'] +REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/' + '90e203b58c5897930a9567252943b7c96c39652b.zip' + '#python-vera==0.1.1'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index 11d91043d12..d04ea496cea 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -128,7 +128,7 @@ pyfttt==0.3 https://github.com/balloob/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1 # Vera (*.vera) -https://github.com/balloob/home-assistant-vera-api/archive/a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip#python-vera==0.1 +https://github.com/pavoni/home-assistant-vera-api/archive/90e203b58c5897930a9567252943b7c96c39652b.zip#python-vera==0.1.1 # Sonos (media_player.sonos) SoCo==0.11.1 From 0269be581355f811a98326e73f188ac5e4f0f7fc Mon Sep 17 00:00:00 2001 From: pavoni Date: Fri, 30 Oct 2015 09:30:22 +0000 Subject: [PATCH 4/4] Update pyvera version --- homeassistant/components/light/vera.py | 2 +- homeassistant/components/switch/vera.py | 2 +- requirements_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 2e9e02ebbe5..f4c46976626 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -15,7 +15,7 @@ from homeassistant.components.switch.vera import VeraSwitch from homeassistant.components.light import ATTR_BRIGHTNESS REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/' - '90e203b58c5897930a9567252943b7c96c39652b.zip' + 'efdba4e63d58a30bc9b36d9e01e69858af9130b8.zip' '#python-vera==0.1.1'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/switch/vera.py b/homeassistant/components/switch/vera.py index 55e519d8616..51d682bcdc1 100644 --- a/homeassistant/components/switch/vera.py +++ b/homeassistant/components/switch/vera.py @@ -16,7 +16,7 @@ from homeassistant.const import ( ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME) REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/' - '90e203b58c5897930a9567252943b7c96c39652b.zip' + 'efdba4e63d58a30bc9b36d9e01e69858af9130b8.zip' '#python-vera==0.1.1'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index d04ea496cea..6b7f57d79bc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -128,7 +128,7 @@ pyfttt==0.3 https://github.com/balloob/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1 # Vera (*.vera) -https://github.com/pavoni/home-assistant-vera-api/archive/90e203b58c5897930a9567252943b7c96c39652b.zip#python-vera==0.1.1 +https://github.com/pavoni/home-assistant-vera-api/archive/efdba4e63d58a30bc9b36d9e01e69858af9130b8.zip#python-vera==0.1.1 # Sonos (media_player.sonos) SoCo==0.11.1