From b5aac9a1c78663d834da5d4ca02ca845ac6182af Mon Sep 17 00:00:00 2001 From: Matrix Date: Wed, 30 Nov 2022 17:11:02 +0800 Subject: [PATCH] Add entity update condition to yolink (#82970) add entity update condition --- homeassistant/components/yolink/sensor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index e2e5fa2a94e..4b658246bc9 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -53,6 +53,7 @@ class YoLinkSensorEntityDescription( """YoLink SensorEntityDescription.""" value: Callable = lambda state: state + should_update_entity: Callable = lambda state: True SENSOR_DEVICE_TYPE = [ @@ -127,6 +128,7 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( name="Temperature", state_class=SensorStateClass.MEASUREMENT, exists_fn=lambda device: device.device_type in MCU_DEV_TEMPERATURE_SENSOR, + should_update_entity=lambda value: value is not None, ), YoLinkSensorEntityDescription( key="loraInfo", @@ -137,6 +139,7 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, + should_update_entity=lambda value: value is not None, ), ) @@ -195,7 +198,7 @@ class YoLinkSensorEntity(YoLinkEntity, SensorEntity): attr_val := self.entity_description.value( state.get(self.entity_description.key) ) - ) is None and self.entity_description.key in ["devTemperature", "loraInfo"]: + ) is None and self.entity_description.should_update_entity(attr_val) is False: return self._attr_native_value = attr_val self.async_write_ha_state()