Merge pull request #902 from balloob/fix_vera_sensor_subscriptions

Another Vera fix
pull/905/head^2
Greg Dowling 2016-01-15 21:46:27 +00:00
commit 3d27dd3ec4
4 changed files with 30 additions and 26 deletions

View File

@ -15,7 +15,7 @@ from homeassistant.components.light import ATTR_BRIGHTNESS
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_ON from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_ON
REQUIREMENTS = ['pyvera==0.2.5'] REQUIREMENTS = ['pyvera==0.2.6']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -86,4 +86,4 @@ class VeraLight(VeraSwitch):
self.vera_device.switch_on() self.vera_device.switch_on()
self._state = STATE_ON self._state = STATE_ON
self.update_ha_state() self.update_ha_state(True)

View File

@ -15,7 +15,7 @@ from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME, ATTR_BATTERY_LEVEL, ATTR_TRIPPED, ATTR_ARMED, ATTR_LAST_TRIP_TIME,
TEMP_CELCIUS, TEMP_FAHRENHEIT, EVENT_HOMEASSISTANT_STOP) TEMP_CELCIUS, TEMP_FAHRENHEIT, EVENT_HOMEASSISTANT_STOP)
REQUIREMENTS = ['pyvera==0.2.5'] REQUIREMENTS = ['pyvera==0.2.6']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -89,6 +89,7 @@ class VeraSensor(Entity):
self._temperature_units = None self._temperature_units = None
self.controller.register(vera_device, self._update_callback) self.controller.register(vera_device, self._update_callback)
self.update()
def _update_callback(self, _device): def _update_callback(self, _device):
""" Called by the vera device callback to update state. """ """ Called by the vera device callback to update state. """
@ -123,19 +124,19 @@ class VeraSensor(Entity):
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%' attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
if self.vera_device.is_armable: if self.vera_device.is_armable:
armed = self.vera_device.get_value('Armed') armed = self.vera_device.is_armed
attr[ATTR_ARMED] = 'True' if armed == '1' else 'False' attr[ATTR_ARMED] = 'True' if armed else 'False'
if self.vera_device.is_trippable: if self.vera_device.is_trippable:
last_tripped = self.vera_device.get_value('LastTrip') last_tripped = self.vera_device.last_trip
if last_tripped is not None: if last_tripped is not None:
utc_time = dt_util.utc_from_timestamp(int(last_tripped)) utc_time = dt_util.utc_from_timestamp(int(last_tripped))
attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str( attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(
utc_time) utc_time)
else: else:
attr[ATTR_LAST_TRIP_TIME] = None attr[ATTR_LAST_TRIP_TIME] = None
tripped = self.vera_device.get_value('Tripped') tripped = self.vera_device.is_tripped
attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False' attr[ATTR_TRIPPED] = 'True' if tripped else 'False'
attr['Vera Device Id'] = self.vera_device.vera_device_id attr['Vera Device Id'] = self.vera_device.vera_device_id
return attr return attr
@ -147,7 +148,7 @@ class VeraSensor(Entity):
def update(self): def update(self):
if self.vera_device.category == "Temperature Sensor": if self.vera_device.category == "Temperature Sensor":
current_temp = self.vera_device.get_value('CurrentTemperature') current_temp = self.vera_device.temperature
vera_temp_units = ( vera_temp_units = (
self.vera_device.vera_controller.temperature_units) self.vera_device.vera_controller.temperature_units)
@ -165,11 +166,11 @@ class VeraSensor(Entity):
self.current_value = current_temp self.current_value = current_temp
elif self.vera_device.category == "Light Sensor": elif self.vera_device.category == "Light Sensor":
self.current_value = self.vera_device.get_value('CurrentLevel') self.current_value = self.vera_device.light
elif self.vera_device.category == "Humidity Sensor": elif self.vera_device.category == "Humidity Sensor":
self.current_value = self.vera_device.get_value('CurrentLevel') self.current_value = self.vera_device.humidity
elif self.vera_device.category == "Sensor": elif self.vera_device.category == "Sensor":
tripped = self.vera_device.get_value('Tripped') tripped = self.vera_device.is_tripped
self.current_value = 'Tripped' if tripped == '1' else 'Not Tripped' self.current_value = 'Tripped' if tripped else 'Not Tripped'
else: else:
self.current_value = 'Unknown' self.current_value = 'Unknown'

View File

@ -21,7 +21,7 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
STATE_OFF) STATE_OFF)
REQUIREMENTS = ['pyvera==0.2.5'] REQUIREMENTS = ['pyvera==0.2.6']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -91,14 +91,10 @@ class VeraSwitch(SwitchDevice):
self._state = STATE_OFF self._state = STATE_OFF
self.controller.register(vera_device, self._update_callback) self.controller.register(vera_device, self._update_callback)
self.update()
def _update_callback(self, _device): def _update_callback(self, _device):
""" Called by the vera device callback to update state. """ self.update_ha_state(True)
if self.vera_device.is_switched_on():
self._state = STATE_ON
else:
self._state = STATE_OFF
self.update_ha_state()
@property @property
def name(self): def name(self):
@ -113,19 +109,19 @@ class VeraSwitch(SwitchDevice):
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%' attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
if self.vera_device.is_armable: if self.vera_device.is_armable:
armed = self.vera_device.get_value('Armed') armed = self.vera_device.is_armed
attr[ATTR_ARMED] = 'True' if armed == '1' else 'False' attr[ATTR_ARMED] = 'True' if armed else 'False'
if self.vera_device.is_trippable: if self.vera_device.is_trippable:
last_tripped = self.vera_device.get_value('LastTrip') last_tripped = self.vera_device.last_trip
if last_tripped is not None: if last_tripped is not None:
utc_time = dt_util.utc_from_timestamp(int(last_tripped)) utc_time = dt_util.utc_from_timestamp(int(last_tripped))
attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str( attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(
utc_time) utc_time)
else: else:
attr[ATTR_LAST_TRIP_TIME] = None attr[ATTR_LAST_TRIP_TIME] = None
tripped = self.vera_device.get_value('Tripped') tripped = self.vera_device.is_tripped
attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False' attr[ATTR_TRIPPED] = 'True' if tripped else 'False'
attr['Vera Device Id'] = self.vera_device.vera_device_id attr['Vera Device Id'] = self.vera_device.vera_device_id
@ -150,3 +146,10 @@ class VeraSwitch(SwitchDevice):
def is_on(self): def is_on(self):
""" True if device is on. """ """ True if device is on. """
return self._state == STATE_ON return self._state == STATE_ON
def update(self):
""" Called by the vera device callback to update state. """
if self.vera_device.is_switched_on():
self._state = STATE_ON
else:
self._state = STATE_OFF

View File

@ -62,7 +62,7 @@ tellcore-py==1.1.2
# homeassistant.components.light.vera # homeassistant.components.light.vera
# homeassistant.components.sensor.vera # homeassistant.components.sensor.vera
# homeassistant.components.switch.vera # homeassistant.components.switch.vera
pyvera==0.2.5 pyvera==0.2.6
# homeassistant.components.wink # homeassistant.components.wink
# homeassistant.components.light.wink # homeassistant.components.light.wink