mirror of
				https://github.com/home-assistant/core.git
				synced 2025-11-04 08:29:37 +00:00 
			
		
		
		
	Use SensorDeviceClass enum in KNX (#82947)
This commit is contained in:
		@@ -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,10 +64,9 @@ 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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user