mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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,7 +1,14 @@
|
|||||||
"""Platform for binary sensor integration."""
|
"""Platform for binary sensor integration."""
|
||||||
import logging
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
@ -10,6 +17,14 @@ from .devolo_device import DevoloDeviceEntity
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
|
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
|
||||||
@ -52,6 +67,11 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
|
|||||||
self._unique_id
|
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._state = self._binary_sensor_property.state
|
||||||
|
|
||||||
self._subscriber = None
|
self._subscriber = None
|
||||||
@ -61,6 +81,11 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
|
|||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return device class."""
|
||||||
|
return self._device_class
|
||||||
|
|
||||||
def _sync(self, message=None):
|
def _sync(self, message=None):
|
||||||
"""Update the binary sensor state."""
|
"""Update the binary sensor state."""
|
||||||
if message[0].startswith("devolo.BinarySensor"):
|
if message[0].startswith("devolo.BinarySensor"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user