From 3d48d81cfcf8423ab232a6fe50319126437022f0 Mon Sep 17 00:00:00 2001 From: pavoni Date: Sun, 16 Apr 2017 12:59:09 +0100 Subject: [PATCH 1/2] Add vera power meter. --- homeassistant/components/sensor/vera.py | 13 +++++++++++++ homeassistant/components/vera.py | 7 ++++++- requirements_all.txt | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index 81f69001f82c6d..a2b8330ab39ad0 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -10,6 +10,7 @@ TEMP_CELSIUS, TEMP_FAHRENHEIT) from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import ENTITY_ID_FORMAT +from homeassistant.util import convert from homeassistant.components.vera import ( VERA_CONTROLLER, VERA_DEVICES, VeraDevice) @@ -49,6 +50,12 @@ def unit_of_measurement(self): return 'lux' elif self.vera_device.category == "Humidity Sensor": return '%' + elif self.vera_device.category == "Power meter": + power = convert(self.vera_device.power, float, 0) + if power >= 1000.0: + return 'kW' + else: + return 'watts' def update(self): """Update the state.""" @@ -67,6 +74,12 @@ def update(self): 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 == "Power meter": + power = convert(self.vera_device.power, float, 0) + if power >= 1000.0: + self.current_value = round(power / 1000.0, 2) + else: + self.current_value = round(power, 0) elif self.vera_device.category == "Sensor": tripped = self.vera_device.is_tripped self.current_value = 'Tripped' if tripped else 'Not Tripped' diff --git a/homeassistant/components/vera.py b/homeassistant/components/vera.py index 555a800708c9d5..9d7494147e0466 100644 --- a/homeassistant/components/vera.py +++ b/homeassistant/components/vera.py @@ -20,7 +20,7 @@ EVENT_HOMEASSISTANT_STOP) from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['pyvera==0.2.25'] +REQUIREMENTS = ['pyvera==0.2.26'] _LOGGER = logging.getLogger(__name__) @@ -35,6 +35,7 @@ VERA_ID_FORMAT = '{}_{}' ATTR_CURRENT_POWER_W = "current_power_w" +ATTR_CURRENT_ENERGY_KWH = "current_energy_kwh" VERA_DEVICES = defaultdict(list) @@ -181,6 +182,10 @@ def device_state_attributes(self): if power: attr[ATTR_CURRENT_POWER_W] = convert(power, float, 0.0) + energy = self.vera_device.energy + if energy: + attr[ATTR_CURRENT_ENERGY_KWH] = convert(energy, float, 0.0) + attr['Vera Device Id'] = self.vera_device.vera_device_id return attr diff --git a/requirements_all.txt b/requirements_all.txt index f82fbaeaaad790..1f5d33272a86a8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -665,7 +665,7 @@ pyunifi==2.0 # pyuserinput==0.1.11 # homeassistant.components.vera -pyvera==0.2.25 +pyvera==0.2.26 # homeassistant.components.notify.html5 pywebpush==0.6.1 From 6c925f5563b4ea2b9a833806be113731660b67e4 Mon Sep 17 00:00:00 2001 From: pavoni Date: Sun, 16 Apr 2017 17:23:52 +0100 Subject: [PATCH 2/2] Use W for power. --- homeassistant/components/sensor/vera.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index a2b8330ab39ad0..e0fa16d790737c 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -51,11 +51,7 @@ def unit_of_measurement(self): elif self.vera_device.category == "Humidity Sensor": return '%' elif self.vera_device.category == "Power meter": - power = convert(self.vera_device.power, float, 0) - if power >= 1000.0: - return 'kW' - else: - return 'watts' + return 'watts' def update(self): """Update the state.""" @@ -76,10 +72,7 @@ def update(self): self.current_value = self.vera_device.humidity elif self.vera_device.category == "Power meter": power = convert(self.vera_device.power, float, 0) - if power >= 1000.0: - self.current_value = round(power / 1000.0, 2) - else: - self.current_value = round(power, 0) + self.current_value = int(round(power, 0)) elif self.vera_device.category == "Sensor": tripped = self.vera_device.is_tripped self.current_value = 'Tripped' if tripped else 'Not Tripped'