Use SensorDeviceClass enum in KNX (#82947)

This commit is contained in:
Franck Nijhof 2022-11-29 20:29:47 +01:00 committed by GitHub
parent c36dd17780
commit b4e30c4033
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
"""Support for KNX/IP sensors."""
from __future__ import annotations
from contextlib import suppress
from typing import Any
from xknx import XKNX
@ -9,7 +10,7 @@ from xknx.devices import Sensor as XknxSensor
from homeassistant import config_entries
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES,
SensorDeviceClass,
SensorEntity,
)
from homeassistant.const import (
@ -63,11 +64,10 @@ class KNXSensor(KnxEntity, SensorEntity):
if device_class := config.get(CONF_DEVICE_CLASS):
self._attr_device_class = device_class
else:
self._attr_device_class = (
self._device.ha_device_class()
if self._device.ha_device_class() in DEVICE_CLASSES
else None
)
with suppress(ValueError):
self._attr_device_class = SensorDeviceClass(
str(self._device.ha_device_class())
)
self._attr_force_update = self._device.always_callback
self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY)
self._attr_unique_id = str(self._device.sensor_value.group_address_state)