mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
zha: Add support for humidity sensors (#12496)
* zha: Add support for humidity sensors * Fix lint issue
This commit is contained in:
parent
17b57099ae
commit
63fcf9d425
@ -31,19 +31,22 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
@asyncio.coroutine
|
||||
def make_sensor(discovery_info):
|
||||
"""Create ZHA sensors factory."""
|
||||
from zigpy.zcl.clusters.measurement import TemperatureMeasurement
|
||||
from zigpy.zcl.clusters.measurement import (
|
||||
RelativeHumidity, TemperatureMeasurement
|
||||
)
|
||||
in_clusters = discovery_info['in_clusters']
|
||||
if TemperatureMeasurement.cluster_id in in_clusters:
|
||||
if RelativeHumidity.cluster_id in in_clusters:
|
||||
sensor = RelativeHumiditySensor(**discovery_info)
|
||||
elif TemperatureMeasurement.cluster_id in in_clusters:
|
||||
sensor = TemperatureSensor(**discovery_info)
|
||||
else:
|
||||
sensor = Sensor(**discovery_info)
|
||||
|
||||
attr = sensor.value_attribute
|
||||
if discovery_info['new_join']:
|
||||
cluster = list(in_clusters.values())[0]
|
||||
yield from cluster.bind()
|
||||
yield from cluster.configure_reporting(
|
||||
attr, 300, 600, sensor.min_reportable_change,
|
||||
sensor.value_attribute, 300, 600, sensor.min_reportable_change,
|
||||
)
|
||||
|
||||
return sensor
|
||||
@ -89,3 +92,22 @@ class TemperatureSensor(Sensor):
|
||||
celsius = round(float(self._state) / 100, 1)
|
||||
return convert_temperature(
|
||||
celsius, TEMP_CELSIUS, self.unit_of_measurement)
|
||||
|
||||
|
||||
class RelativeHumiditySensor(Sensor):
|
||||
"""ZHA relative humidity sensor."""
|
||||
|
||||
min_reportable_change = 50 # 0.5%
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return '%'
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
if self._state == 'unknown':
|
||||
return 'unknown'
|
||||
|
||||
return round(float(self._state) / 100, 1)
|
||||
|
@ -33,6 +33,7 @@ def populate_data():
|
||||
|
||||
SINGLE_CLUSTER_DEVICE_CLASS.update({
|
||||
zcl.clusters.general.OnOff: 'switch',
|
||||
zcl.clusters.measurement.RelativeHumidity: 'sensor',
|
||||
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
|
||||
zcl.clusters.security.IasZone: 'binary_sensor',
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user