Use new enums in devolo_home_control (#61345)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
bcdeb06a4e
commit
b1a8e0b796
3 changed files with 34 additions and 46 deletions
|
@ -5,30 +5,24 @@ from devolo_home_control_api.devices.zwave import Zwave
|
|||
from devolo_home_control_api.homecontrol import HomeControl
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_DOOR,
|
||||
DEVICE_CLASS_HEAT,
|
||||
DEVICE_CLASS_MOISTURE,
|
||||
DEVICE_CLASS_MOTION,
|
||||
DEVICE_CLASS_PROBLEM,
|
||||
DEVICE_CLASS_SAFETY,
|
||||
DEVICE_CLASS_SMOKE,
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .devolo_device import DevoloDeviceEntity
|
||||
|
||||
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,
|
||||
"overload": DEVICE_CLASS_SAFETY,
|
||||
"Water alarm": BinarySensorDeviceClass.MOISTURE,
|
||||
"Home Security": BinarySensorDeviceClass.MOTION,
|
||||
"Smoke Alarm": BinarySensorDeviceClass.SMOKE,
|
||||
"Heat Alarm": BinarySensorDeviceClass.HEAT,
|
||||
"door": BinarySensorDeviceClass.DOOR,
|
||||
"overload": BinarySensorDeviceClass.SAFETY,
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,12 +89,12 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
|
|||
|
||||
self._value = self._binary_sensor_property.state
|
||||
|
||||
if self._attr_device_class == DEVICE_CLASS_SAFETY:
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
if self._attr_device_class == BinarySensorDeviceClass.SAFETY:
|
||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
|
||||
if element_uid.startswith("devolo.WarningBinaryFI:"):
|
||||
self._attr_device_class = DEVICE_CLASS_PROBLEM
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
self._attr_device_class = BinarySensorDeviceClass.PROBLEM
|
||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
self._attr_entity_registry_enabled_default = False
|
||||
|
||||
@property
|
||||
|
|
|
@ -7,10 +7,10 @@ from devolo_home_control_api.devices.zwave import Zwave
|
|||
from devolo_home_control_api.homecontrol import HomeControl
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
DEVICE_CLASS_BLIND,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_OPEN,
|
||||
SUPPORT_SET_POSITION,
|
||||
CoverDeviceClass,
|
||||
CoverEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -55,7 +55,7 @@ class DevoloCoverDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, CoverEntity):
|
|||
element_uid=element_uid,
|
||||
)
|
||||
|
||||
self._attr_device_class = DEVICE_CLASS_BLIND
|
||||
self._attr_device_class = CoverDeviceClass.BLIND
|
||||
self._attr_supported_features = (
|
||||
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
||||
)
|
||||
|
|
|
@ -5,43 +5,37 @@ from devolo_home_control_api.devices.zwave import Zwave
|
|||
from devolo_home_control_api.homecontrol import HomeControl
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC, PERCENTAGE
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .devolo_device import DevoloDeviceEntity
|
||||
|
||||
DEVICE_CLASS_MAPPING = {
|
||||
"battery": DEVICE_CLASS_BATTERY,
|
||||
"temperature": DEVICE_CLASS_TEMPERATURE,
|
||||
"light": DEVICE_CLASS_ILLUMINANCE,
|
||||
"humidity": DEVICE_CLASS_HUMIDITY,
|
||||
"current": DEVICE_CLASS_POWER,
|
||||
"total": DEVICE_CLASS_ENERGY,
|
||||
"voltage": DEVICE_CLASS_VOLTAGE,
|
||||
"battery": SensorDeviceClass.BATTERY,
|
||||
"temperature": SensorDeviceClass.TEMPERATURE,
|
||||
"light": SensorDeviceClass.ILLUMINANCE,
|
||||
"humidity": SensorDeviceClass.HUMIDITY,
|
||||
"current": SensorDeviceClass.POWER,
|
||||
"total": SensorDeviceClass.ENERGY,
|
||||
"voltage": SensorDeviceClass.VOLTAGE,
|
||||
}
|
||||
|
||||
STATE_CLASS_MAPPING = {
|
||||
"battery": STATE_CLASS_MEASUREMENT,
|
||||
"temperature": STATE_CLASS_MEASUREMENT,
|
||||
"light": STATE_CLASS_MEASUREMENT,
|
||||
"humidity": STATE_CLASS_MEASUREMENT,
|
||||
"current": STATE_CLASS_MEASUREMENT,
|
||||
"total": STATE_CLASS_TOTAL_INCREASING,
|
||||
"voltage": STATE_CLASS_MEASUREMENT,
|
||||
"battery": SensorStateClass.MEASUREMENT,
|
||||
"temperature": SensorStateClass.MEASUREMENT,
|
||||
"light": SensorStateClass.MEASUREMENT,
|
||||
"humidity": SensorStateClass.MEASUREMENT,
|
||||
"current": SensorStateClass.MEASUREMENT,
|
||||
"total": SensorStateClass.TOTAL_INCREASING,
|
||||
"voltage": SensorStateClass.MEASUREMENT,
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,7 +141,7 @@ class DevoloBatteryEntity(DevoloMultiLevelDeviceEntity):
|
|||
|
||||
self._attr_device_class = DEVICE_CLASS_MAPPING.get("battery")
|
||||
self._attr_state_class = STATE_CLASS_MAPPING.get("battery")
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
self._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
self._value = device_instance.battery_level
|
||||
|
@ -179,7 +173,7 @@ class DevoloConsumptionEntity(DevoloMultiLevelDeviceEntity):
|
|||
)
|
||||
|
||||
if consumption == "total":
|
||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
|
||||
self._value = getattr(
|
||||
device_instance.consumption_property[element_uid], consumption
|
||||
|
|
Loading…
Add table
Reference in a new issue