From b152d59afe9e30ca8a126b84a207e338befd60be Mon Sep 17 00:00:00 2001 From: Markus Bong Date: Mon, 13 Jul 2020 20:56:22 +0200 Subject: [PATCH] Add devolo binary sensor device class mapping (#37350) * add device class mapping for binary sensors * change if else statement to or --- .../devolo_home_control/binary_sensor.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/devolo_home_control/binary_sensor.py b/homeassistant/components/devolo_home_control/binary_sensor.py index 87af86f02af..3f88212646d 100644 --- a/homeassistant/components/devolo_home_control/binary_sensor.py +++ b/homeassistant/components/devolo_home_control/binary_sensor.py @@ -1,7 +1,14 @@ """Platform for binary sensor integration.""" import logging -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_DOOR, + DEVICE_CLASS_HEAT, + DEVICE_CLASS_MOISTURE, + DEVICE_CLASS_MOTION, + DEVICE_CLASS_SMOKE, + BinarySensorEntity, +) from homeassistant.config_entries import ConfigEntry from homeassistant.helpers.typing import HomeAssistantType @@ -10,6 +17,14 @@ from .devolo_device import DevoloDeviceEntity _LOGGER = logging.getLogger(__name__) +DEVICE_CLASS_MAPPING = { + "Water alarm": DEVICE_CLASS_MOISTURE, + "Home Security": DEVICE_CLASS_MOTION, + "Smoke Alarm": DEVICE_CLASS_SMOKE, + "Heat Alarm": DEVICE_CLASS_HEAT, + "door": DEVICE_CLASS_DOOR, +} + async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -52,6 +67,11 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity): self._unique_id ) + self._device_class = DEVICE_CLASS_MAPPING.get( + self._binary_sensor_property.sub_type + or self._binary_sensor_property.sensor_type + ) + self._state = self._binary_sensor_property.state self._subscriber = None @@ -61,6 +81,11 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity): """Return the state.""" return self._state + @property + def device_class(self): + """Return device class.""" + return self._device_class + def _sync(self, message=None): """Update the binary sensor state.""" if message[0].startswith("devolo.BinarySensor"):