Add devolo binary sensor device class mapping (#37350)
* add device class mapping for binary sensors * change if else statement to or
This commit is contained in:
parent
9ac1475251
commit
b152d59afe
1 changed files with 26 additions and 1 deletions
|
@ -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"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue