From 22f843d7ff8e947c2d81436f37cc2e4d2f5e83b5 Mon Sep 17 00:00:00 2001 From: topsworld Date: Fri, 17 Jan 2025 11:54:06 +0800 Subject: [PATCH] fix: fix sensor entity type error --- custom_components/xiaomi_home/sensor.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/custom_components/xiaomi_home/sensor.py b/custom_components/xiaomi_home/sensor.py index 6151b50..0a2540c 100644 --- a/custom_components/xiaomi_home/sensor.py +++ b/custom_components/xiaomi_home/sensor.py @@ -106,18 +106,15 @@ class Sensor(MIoTPropertyEntity, SensorEntity): # device_class is not empty but unit is empty. # Set the default unit according to device_class. unit_sets = DEVICE_CLASS_UNITS.get( - self._attr_device_class, None) + self._attr_device_class, None) # type: ignore self._attr_native_unit_of_measurement = list( unit_sets)[0] if unit_sets else None + # Set state_class + if spec.state_class: + self._attr_state_class = spec.state_class # Set icon if spec.icon: self._attr_icon = spec.icon - # Set state_class - if spec.state_class: - self._attr_state_class = spec.state_class - else: - # Set default state_class - self._attr_state_class = SensorStateClass.MEASUREMENT @property def native_value(self) -> Any: