Tidy / Refactor Vera (#2569)

* Add power attribute to switch.

* Move device_state_attributes into base class.

* Fix imports following refactor.

* Bump pyvera version - should add contributed support for older (UI5) version dimmers and locks.

* Refactor device lookup to be based on vera classes, push category back into library.

* Add generic power attribute, fix inherited class order bug.

* Tidy.
This commit is contained in:
Greg Dowling 2016-07-20 04:13:33 +02:00 committed by Paulus Schoutsen
parent 7c431911d1
commit e34bfb7381
7 changed files with 73 additions and 140 deletions

View file

@ -6,9 +6,7 @@ https://home-assistant.io/components/sensor.vera/
"""
import logging
import homeassistant.util.dt as dt_util
from homeassistant.const import (
ATTR_ARMED, ATTR_BATTERY_LEVEL, ATTR_LAST_TRIP_TIME, ATTR_TRIPPED,
TEMP_CELSIUS, TEMP_FAHRENHEIT)
from homeassistant.helpers.entity import Entity
from homeassistant.components.vera import (
@ -50,30 +48,6 @@ class VeraSensor(VeraDevice, Entity):
elif self.vera_device.category == "Humidity Sensor":
return '%'
@property
def device_state_attributes(self):
"""Return the state attributes."""
attr = {}
if self.vera_device.has_battery:
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
if self.vera_device.is_armable:
armed = self.vera_device.is_armed
attr[ATTR_ARMED] = 'True' if armed else 'False'
if self.vera_device.is_trippable:
last_tripped = self.vera_device.last_trip
if last_tripped is not None:
utc_time = dt_util.utc_from_timestamp(int(last_tripped))
attr[ATTR_LAST_TRIP_TIME] = utc_time.isoformat()
else:
attr[ATTR_LAST_TRIP_TIME] = None
tripped = self.vera_device.is_tripped
attr[ATTR_TRIPPED] = 'True' if tripped else 'False'
attr['Vera Device Id'] = self.vera_device.vera_device_id
return attr
def update(self):
"""Update the state."""
if self.vera_device.category == "Temperature Sensor":