From 6c14e7afa7ff12dfadd673ef6f337d9ee56770fe Mon Sep 17 00:00:00 2001 From: Markus Jankowski Date: Tue, 2 Apr 2019 19:29:48 +0200 Subject: [PATCH] Add battery sensor to Homematic IP (#22630) --- .../homematicip_cloud/binary_sensor.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index 786a28a70a5..071b4a0a3fb 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -29,8 +29,8 @@ async def async_setup_platform( async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the HomematicIP Cloud binary sensor from a config entry.""" from homematicip.aio.device import ( - AsyncShutterContact, AsyncMotionDetectorIndoor, AsyncSmokeDetector, - AsyncWaterSensor, AsyncRotaryHandleSensor, + AsyncDevice, AsyncShutterContact, AsyncMotionDetectorIndoor, + AsyncSmokeDetector, AsyncWaterSensor, AsyncRotaryHandleSensor, AsyncMotionDetectorPushButton, AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro) @@ -56,6 +56,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): AsyncWeatherSensorPro)): devices.append(HomematicipStormSensor(home, device)) devices.append(HomematicipSunshineSensor(home, device)) + if isinstance(device, AsyncDevice) and device.lowBat is not None: + devices.append(HomematicipBatterySensor(home, device)) for group in home.groups: if isinstance(group, AsyncSecurityGroup): @@ -197,6 +199,24 @@ class HomematicipSunshineSensor(HomematicipGenericDevice, BinarySensorDevice): return attr +class HomematicipBatterySensor(HomematicipGenericDevice, BinarySensorDevice): + """Representation of a HomematicIP Cloud low battery sensor.""" + + def __init__(self, home, device): + """Initialize battery sensor.""" + super().__init__(home, device, 'Battery') + + @property + def device_class(self): + """Return the class of this sensor.""" + return 'battery' + + @property + def is_on(self): + """Return true if battery is low.""" + return self._device.lowBat + + class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorDevice): """Representation of a HomematicIP Cloud security zone group."""