Revise to depend on vera subscription data updates, rather than talking to device.

This commit is contained in:
pavoni 2016-01-09 21:13:34 +00:00
parent d61eb93c03
commit b64680e4a8
2 changed files with 9 additions and 13 deletions

View File

@ -119,18 +119,18 @@ 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.refresh_value('Armed') armed = self.vera_device.get_value('Armed')
attr[ATTR_ARMED] = 'True' if armed == '1' else 'False' attr[ATTR_ARMED] = 'True' if armed == '1' else 'False'
if self.vera_device.is_trippable: if self.vera_device.is_trippable:
last_tripped = self.vera_device.refresh_value('LastTrip') last_tripped = self.vera_device.get_value('LastTrip')
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.refresh_value('Tripped') tripped = self.vera_device.get_value('Tripped')
attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False' attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False'
attr['Vera Device Id'] = self.vera_device.vera_device_id attr['Vera Device Id'] = self.vera_device.vera_device_id
@ -143,7 +143,6 @@ class VeraSensor(Entity):
def update(self): def update(self):
if self.vera_device.category == "Temperature Sensor": if self.vera_device.category == "Temperature Sensor":
self.vera_device.refresh_value('CurrentTemperature')
current_temp = self.vera_device.get_value('CurrentTemperature') current_temp = self.vera_device.get_value('CurrentTemperature')
vera_temp_units = self.vera_device.veraController.temperature_units vera_temp_units = self.vera_device.veraController.temperature_units
@ -161,10 +160,9 @@ 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.vera_device.refresh_value('CurrentLevel')
self.current_value = self.vera_device.get_value('CurrentLevel') self.current_value = self.vera_device.get_value('CurrentLevel')
elif self.vera_device.category == "Sensor": elif self.vera_device.category == "Sensor":
tripped = self.vera_device.refresh_value('Tripped') tripped = self.vera_device.get_value('Tripped')
self.current_value = 'Tripped' if tripped == '1' else 'Not Tripped' self.current_value = 'Tripped' if tripped == '1' else 'Not Tripped'
else: else:
self.current_value = 'Unknown' self.current_value = 'Unknown'

View File

@ -111,18 +111,18 @@ class VeraSwitch(ToggleEntity):
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.refresh_value('Armed') armed = self.vera_device.get_value('Armed')
attr[ATTR_ARMED] = 'True' if armed == '1' else 'False' attr[ATTR_ARMED] = 'True' if armed == '1' else 'False'
if self.vera_device.is_trippable: if self.vera_device.is_trippable:
last_tripped = self.vera_device.refresh_value('LastTrip') last_tripped = self.vera_device.get_value('LastTrip')
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.refresh_value('Tripped') tripped = self.vera_device.get_value('Tripped')
attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False' attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False'
attr['Vera Device Id'] = self.vera_device.vera_device_id attr['Vera Device Id'] = self.vera_device.vera_device_id
@ -133,6 +133,7 @@ class VeraSwitch(ToggleEntity):
self.vera_device.switch_on() self.vera_device.switch_on()
self.is_on_status = True self.is_on_status = True
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
self.vera_device.switch_off() self.vera_device.switch_off()
self.is_on_status = False self.is_on_status = False
@ -148,7 +149,4 @@ class VeraSwitch(ToggleEntity):
return self.is_on_status return self.is_on_status
def update(self): def update(self):
try:
self.is_on_status = self.vera_device.is_switched_on() self.is_on_status = self.vera_device.is_switched_on()
except RequestException:
_LOGGER.warning('Could not update status for %s', self.name)