From b489519930750bbee1acb1f2d1e98c1ff9241be0 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Sun, 20 May 2018 19:01:56 -0400 Subject: [PATCH] zha: Add metering sensor (#14562) --- homeassistant/components/sensor/zha.py | 22 ++++++++++++++++++++++ homeassistant/components/zha/const.py | 1 + 2 files changed, 23 insertions(+) diff --git a/homeassistant/components/sensor/zha.py b/homeassistant/components/sensor/zha.py index 3ca908a679d..abb4c651e78 100644 --- a/homeassistant/components/sensor/zha.py +++ b/homeassistant/components/sensor/zha.py @@ -34,6 +34,7 @@ def make_sensor(discovery_info): from zigpy.zcl.clusters.measurement import ( RelativeHumidity, TemperatureMeasurement, PressureMeasurement ) + from zigpy.zcl.clusters.smartenergy import Metering in_clusters = discovery_info['in_clusters'] if RelativeHumidity.cluster_id in in_clusters: sensor = RelativeHumiditySensor(**discovery_info) @@ -41,6 +42,8 @@ def make_sensor(discovery_info): sensor = TemperatureSensor(**discovery_info) elif PressureMeasurement.cluster_id in in_clusters: sensor = PressureSensor(**discovery_info) + elif Metering.cluster_id in in_clusters: + sensor = MeteringSensor(**discovery_info) else: sensor = Sensor(**discovery_info) @@ -143,3 +146,22 @@ class PressureSensor(Sensor): return None return round(float(self._state)) + + +class MeteringSensor(Sensor): + """ZHA Metering sensor.""" + + value_attribute = 1024 + + @property + def unit_of_measurement(self): + """Return the unit of measurement of this entity.""" + return 'W' + + @property + def state(self): + """Return the state of the entity.""" + if self._state is None: + return None + + return round(float(self._state)) diff --git a/homeassistant/components/zha/const.py b/homeassistant/components/zha/const.py index 1c083c3ca93..71f0ea17490 100644 --- a/homeassistant/components/zha/const.py +++ b/homeassistant/components/zha/const.py @@ -48,6 +48,7 @@ def populate_data(): zcl.clusters.measurement.RelativeHumidity: 'sensor', zcl.clusters.measurement.TemperatureMeasurement: 'sensor', zcl.clusters.measurement.PressureMeasurement: 'sensor', + zcl.clusters.smartenergy.Metering: 'sensor', zcl.clusters.security.IasZone: 'binary_sensor', zcl.clusters.hvac.Fan: 'fan', })