diff --git a/homeassistant/components/sensor/zha.py b/homeassistant/components/sensor/zha.py index 6202f8cb7efd29..884d30a67862d1 100644 --- a/homeassistant/components/sensor/zha.py +++ b/homeassistant/components/sensor/zha.py @@ -36,6 +36,7 @@ def make_sensor(discovery_info): RelativeHumidity, TemperatureMeasurement, PressureMeasurement, IlluminanceMeasurement ) + from zigpy.zcl.clusters.general import PowerConfiguration from zigpy.zcl.clusters.smartenergy import Metering from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement in_clusters = discovery_info['in_clusters'] @@ -52,6 +53,8 @@ def make_sensor(discovery_info): elif ElectricalMeasurement.cluster_id in in_clusters: sensor = ElectricalMeasurementSensor(**discovery_info) return sensor + elif PowerConfiguration.cluster_id in in_clusters: + sensor = BatterySensor(**discovery_info) else: sensor = Sensor(**discovery_info) @@ -100,6 +103,35 @@ async def async_update(self): self._state = result.get(self.value_attribute, self._state) +class BatterySensor(Sensor): + """ZHA generic battery sensor.""" + + value_attribute = 32 + + @property + def unit_of_measurement(self): + """Return the unit of measurement of this entity.""" + return '%' + + async def async_update(self): + """Retrieve latest state.""" + _LOGGER.debug("%s async_update", self.entity_id) + + result = await zha.safe_read( + self._endpoint.power, + ['battery_voltage'] + ) + self._state = result.get('battery_voltage', self._state) + + @property + def state(self): + """Return the state of the entity.""" + if self._state == 'unknown': + return 'unknown' + + return self._state + + class TemperatureSensor(Sensor): """ZHA temperature sensor.""" diff --git a/homeassistant/components/zha/const.py b/homeassistant/components/zha/const.py index 37c7f5592a02e8..68dc72049fb34a 100644 --- a/homeassistant/components/zha/const.py +++ b/homeassistant/components/zha/const.py @@ -51,6 +51,7 @@ def populate_data(): zcl.clusters.measurement.IlluminanceMeasurement: 'sensor', zcl.clusters.smartenergy.Metering: 'sensor', zcl.clusters.homeautomation.ElectricalMeasurement: 'sensor', + zcl.clusters.general.PowerConfiguration: 'sensor', zcl.clusters.security.IasZone: 'binary_sensor', zcl.clusters.hvac.Fan: 'fan', })