From 28aab33cd167443f0532e591e4e6be568b051bbe Mon Sep 17 00:00:00 2001 From: Alan Fischer Date: Tue, 25 Apr 2017 01:17:25 -0600 Subject: [PATCH] Added scene controller support to the vera component, along with proper polling when a vera device needs it (#7234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional extended description… --- homeassistant/components/sensor/vera.py | 12 ++++++++++++ homeassistant/components/vera.py | 8 +++++--- requirements_all.txt | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index e0fa16d7907..f6ae00f02a6 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -5,6 +5,7 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.vera/ """ import logging +from datetime import timedelta from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT) @@ -18,6 +19,8 @@ DEPENDENCIES = ['vera'] _LOGGER = logging.getLogger(__name__) +SCAN_INTERVAL = timedelta(seconds=5) + def setup_platform(hass, config, add_devices, discovery_info=None): """Perform the setup for Vera controller devices.""" @@ -33,6 +36,7 @@ class VeraSensor(VeraDevice, Entity): """Initialize the sensor.""" self.current_value = None self._temperature_units = None + self.last_changed_time = None VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) @@ -70,6 +74,14 @@ class VeraSensor(VeraDevice, Entity): self.current_value = self.vera_device.light elif self.vera_device.category == "Humidity Sensor": self.current_value = self.vera_device.humidity + elif self.vera_device.category == "Scene Controller": + value = self.vera_device.get_last_scene_id(True) + time = self.vera_device.get_last_scene_time(True) + if time == self.last_changed_time: + self.current_value = None + else: + self.current_value = value + self.last_changed_time = time elif self.vera_device.category == "Power meter": power = convert(self.vera_device.power, float, 0) self.current_value = int(round(power, 0)) diff --git a/homeassistant/components/vera.py b/homeassistant/components/vera.py index 9d7494147e0..d01a2965cf9 100644 --- a/homeassistant/components/vera.py +++ b/homeassistant/components/vera.py @@ -20,7 +20,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_STOP) from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['pyvera==0.2.26'] +REQUIREMENTS = ['pyvera==0.2.27'] _LOGGER = logging.getLogger(__name__) @@ -118,6 +118,8 @@ def map_vera_device(vera_device, remap): return 'climate' if isinstance(vera_device, veraApi.VeraCurtain): return 'cover' + if isinstance(vera_device, veraApi.VeraSceneController): + return 'sensor' if isinstance(vera_device, veraApi.VeraSwitch): if vera_device.device_id in remap: return 'light' @@ -153,8 +155,8 @@ class VeraDevice(Entity): @property def should_poll(self): - """No polling needed.""" - return False + """Get polling requirement from vera device.""" + return self.vera_device.should_poll @property def device_state_attributes(self): diff --git a/requirements_all.txt b/requirements_all.txt index 5fde3397faa..f2b1185fcf9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -676,7 +676,7 @@ pyunifi==2.0 # pyuserinput==0.1.11 # homeassistant.components.vera -pyvera==0.2.26 +pyvera==0.2.27 # homeassistant.components.notify.html5 pywebpush==0.6.1