Added scene controller support to the vera component, along with proper polling when a vera device needs it (#7234)

Add an optional extended description…
pull/7291/head
Alan Fischer 2017-04-25 01:17:25 -06:00 committed by Pascal Vizeli
parent d79f89e168
commit 28aab33cd1
3 changed files with 18 additions and 4 deletions

View File

@ -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))

View File

@ -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):

View File

@ -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