Skip to content

Commit 7822270

Browse files
frenckmarcelveldt
authored andcommitted
Use SensorDeviceClass enum in KNX (#82947)
1 parent 6a15eb4 commit 7822270

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

homeassistant/components/knx/sensor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Support for KNX/IP sensors."""
22
from __future__ import annotations
33

4+
from contextlib import suppress
45
from typing import Any
56

67
from xknx import XKNX
@@ -9,7 +10,7 @@
910
from homeassistant import config_entries
1011
from homeassistant.components.sensor import (
1112
CONF_STATE_CLASS,
12-
DEVICE_CLASSES,
13+
SensorDeviceClass,
1314
SensorEntity,
1415
)
1516
from homeassistant.const import (
@@ -63,11 +64,10 @@ def __init__(self, xknx: XKNX, config: ConfigType) -> None:
6364
if device_class := config.get(CONF_DEVICE_CLASS):
6465
self._attr_device_class = device_class
6566
else:
66-
self._attr_device_class = (
67-
self._device.ha_device_class()
68-
if self._device.ha_device_class() in DEVICE_CLASSES
69-
else None
70-
)
67+
with suppress(ValueError):
68+
self._attr_device_class = SensorDeviceClass(
69+
str(self._device.ha_device_class())
70+
)
7171
self._attr_force_update = self._device.always_callback
7272
self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY)
7373
self._attr_unique_id = str(self._device.sensor_value.group_address_state)

0 commit comments

Comments
 (0)