zha: Add metering sensor (#14562)
parent
4395217031
commit
b489519930
|
@ -34,6 +34,7 @@ def make_sensor(discovery_info):
|
||||||
from zigpy.zcl.clusters.measurement import (
|
from zigpy.zcl.clusters.measurement import (
|
||||||
RelativeHumidity, TemperatureMeasurement, PressureMeasurement
|
RelativeHumidity, TemperatureMeasurement, PressureMeasurement
|
||||||
)
|
)
|
||||||
|
from zigpy.zcl.clusters.smartenergy import Metering
|
||||||
in_clusters = discovery_info['in_clusters']
|
in_clusters = discovery_info['in_clusters']
|
||||||
if RelativeHumidity.cluster_id in in_clusters:
|
if RelativeHumidity.cluster_id in in_clusters:
|
||||||
sensor = RelativeHumiditySensor(**discovery_info)
|
sensor = RelativeHumiditySensor(**discovery_info)
|
||||||
|
@ -41,6 +42,8 @@ def make_sensor(discovery_info):
|
||||||
sensor = TemperatureSensor(**discovery_info)
|
sensor = TemperatureSensor(**discovery_info)
|
||||||
elif PressureMeasurement.cluster_id in in_clusters:
|
elif PressureMeasurement.cluster_id in in_clusters:
|
||||||
sensor = PressureSensor(**discovery_info)
|
sensor = PressureSensor(**discovery_info)
|
||||||
|
elif Metering.cluster_id in in_clusters:
|
||||||
|
sensor = MeteringSensor(**discovery_info)
|
||||||
else:
|
else:
|
||||||
sensor = Sensor(**discovery_info)
|
sensor = Sensor(**discovery_info)
|
||||||
|
|
||||||
|
@ -143,3 +146,22 @@ class PressureSensor(Sensor):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return round(float(self._state))
|
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))
|
||||||
|
|
|
@ -48,6 +48,7 @@ def populate_data():
|
||||||
zcl.clusters.measurement.RelativeHumidity: 'sensor',
|
zcl.clusters.measurement.RelativeHumidity: 'sensor',
|
||||||
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
|
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
|
||||||
zcl.clusters.measurement.PressureMeasurement: 'sensor',
|
zcl.clusters.measurement.PressureMeasurement: 'sensor',
|
||||||
|
zcl.clusters.smartenergy.Metering: 'sensor',
|
||||||
zcl.clusters.security.IasZone: 'binary_sensor',
|
zcl.clusters.security.IasZone: 'binary_sensor',
|
||||||
zcl.clusters.hvac.Fan: 'fan',
|
zcl.clusters.hvac.Fan: 'fan',
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue