mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Only calculate native value once per update in systemmonitor (#113921)
This commit is contained in:
parent
0b0d3a2091
commit
f662e7e3cf
@ -776,6 +776,7 @@ class SystemMonitorSensor(CoordinatorEntity[SystemMonitorCoordinator], SensorEnt
|
|||||||
self.argument = argument
|
self.argument = argument
|
||||||
self.value: int | None = None
|
self.value: int | None = None
|
||||||
self.update_time: float | None = None
|
self.update_time: float | None = None
|
||||||
|
self._attr_native_value = self.entity_description.value_fn(self)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""When added to hass."""
|
"""When added to hass."""
|
||||||
@ -791,16 +792,19 @@ class SystemMonitorSensor(CoordinatorEntity[SystemMonitorCoordinator], SensorEnt
|
|||||||
].remove(self.entity_id)
|
].remove(self.entity_id)
|
||||||
return await super().async_will_remove_from_hass()
|
return await super().async_will_remove_from_hass()
|
||||||
|
|
||||||
@property
|
@callback
|
||||||
def native_value(self) -> StateType | datetime:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Return the state."""
|
"""Handle updated data from the coordinator."""
|
||||||
return self.entity_description.value_fn(self)
|
# Set the native value here so we can use it in available property
|
||||||
|
# without having to recalculate it
|
||||||
|
self._attr_native_value = self.entity_description.value_fn(self)
|
||||||
|
super()._handle_coordinator_update()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
if self.entity_description.none_is_unavailable:
|
if self.entity_description.none_is_unavailable:
|
||||||
return bool(
|
return (
|
||||||
self.coordinator.last_update_success is True
|
self.coordinator.last_update_success is True
|
||||||
and self.native_value is not None
|
and self.native_value is not None
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user