zha: Add metering sensor (#14562)

pull/14563/head
David F. Mulcahey 2018-05-20 19:01:56 -04:00 committed by Russell Cloran
parent 4395217031
commit b489519930
2 changed files with 23 additions and 0 deletions

View File

@ -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))

View File

@ -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',
})