Skip to content

Commit

Permalink
Add support for pressure sensors (home-assistant#14361)
Browse files Browse the repository at this point in the history
  • Loading branch information
damarco authored and Jacob Mansfield committed Sep 4, 2018
1 parent dca04b2 commit c78dc83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion homeassistant/components/sensor/zha.py
Expand Up @@ -32,13 +32,15 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
def make_sensor(discovery_info):
"""Create ZHA sensors factory."""
from zigpy.zcl.clusters.measurement import (
RelativeHumidity, TemperatureMeasurement
RelativeHumidity, TemperatureMeasurement, PressureMeasurement
)
in_clusters = discovery_info['in_clusters']
if RelativeHumidity.cluster_id in in_clusters:
sensor = RelativeHumiditySensor(**discovery_info)
elif TemperatureMeasurement.cluster_id in in_clusters:
sensor = TemperatureSensor(**discovery_info)
elif PressureMeasurement.cluster_id in in_clusters:
sensor = PressureSensor(**discovery_info)
else:
sensor = Sensor(**discovery_info)

Expand Down Expand Up @@ -111,3 +113,20 @@ def state(self):
return 'unknown'

return round(float(self._state) / 100, 1)


class PressureSensor(Sensor):
"""ZHA pressure sensor."""

@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return 'hPa'

@property
def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'

return round(float(self._state))
1 change: 1 addition & 0 deletions homeassistant/components/zha/const.py
Expand Up @@ -47,6 +47,7 @@ def populate_data():
zcl.clusters.general.OnOff: 'switch',
zcl.clusters.measurement.RelativeHumidity: 'sensor',
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
zcl.clusters.measurement.PressureMeasurement: 'sensor',
zcl.clusters.security.IasZone: 'binary_sensor',
zcl.clusters.hvac.Fan: 'fan',
})
Expand Down

0 comments on commit c78dc83

Please sign in to comment.