mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Add entity update condition to yolink (#82970)
add entity update condition
This commit is contained in:
parent
e88e8862db
commit
b5aac9a1c7
@ -53,6 +53,7 @@ class YoLinkSensorEntityDescription(
|
|||||||
"""YoLink SensorEntityDescription."""
|
"""YoLink SensorEntityDescription."""
|
||||||
|
|
||||||
value: Callable = lambda state: state
|
value: Callable = lambda state: state
|
||||||
|
should_update_entity: Callable = lambda state: True
|
||||||
|
|
||||||
|
|
||||||
SENSOR_DEVICE_TYPE = [
|
SENSOR_DEVICE_TYPE = [
|
||||||
@ -127,6 +128,7 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = (
|
|||||||
name="Temperature",
|
name="Temperature",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
exists_fn=lambda device: device.device_type in MCU_DEV_TEMPERATURE_SENSOR,
|
exists_fn=lambda device: device.device_type in MCU_DEV_TEMPERATURE_SENSOR,
|
||||||
|
should_update_entity=lambda value: value is not None,
|
||||||
),
|
),
|
||||||
YoLinkSensorEntityDescription(
|
YoLinkSensorEntityDescription(
|
||||||
key="loraInfo",
|
key="loraInfo",
|
||||||
@ -137,6 +139,7 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = (
|
|||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
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(
|
attr_val := self.entity_description.value(
|
||||||
state.get(self.entity_description.key)
|
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
|
return
|
||||||
self._attr_native_value = attr_val
|
self._attr_native_value = attr_val
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user