From 09b209245a8b149859296a6b7d8fd1372395f708 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 13 Apr 2024 17:57:12 -0500 Subject: [PATCH] Only calculate native_value once in mobile_app (#115550) native_value is read a few times during the state write. Use _attr_native_value so its only calculated once --- homeassistant/components/mobile_app/sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index 6f049d6f2d5..dd70cf1e22e 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -103,8 +103,7 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor): self._async_update_attr_from_config() - @property - def native_value(self) -> StateType | date | datetime: + def _calculate_native_value(self) -> StateType | date | datetime: """Return the state of the sensor.""" if (state := self._config[ATTR_SENSOR_STATE]) in (None, STATE_UNKNOWN): return None @@ -131,3 +130,4 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor): config = self._config self._attr_native_unit_of_measurement = config.get(ATTR_SENSOR_UOM) self._attr_state_class = config.get(ATTR_SENSOR_STATE_CLASS) + self._attr_native_value = self._calculate_native_value()