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
This commit is contained in:
J. Nick Koston
2024-04-13 18:57:12 -04:00
committed by GitHub
parent 927ea14562
commit 09b209245a
@@ -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()