mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
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:
parent
927ea14562
commit
09b209245a
@ -103,8 +103,7 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor):
|
|||||||
|
|
||||||
self._async_update_attr_from_config()
|
self._async_update_attr_from_config()
|
||||||
|
|
||||||
@property
|
def _calculate_native_value(self) -> StateType | date | datetime:
|
||||||
def native_value(self) -> StateType | date | datetime:
|
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
if (state := self._config[ATTR_SENSOR_STATE]) in (None, STATE_UNKNOWN):
|
if (state := self._config[ATTR_SENSOR_STATE]) in (None, STATE_UNKNOWN):
|
||||||
return None
|
return None
|
||||||
@ -131,3 +130,4 @@ class MobileAppSensor(MobileAppEntity, RestoreSensor):
|
|||||||
config = self._config
|
config = self._config
|
||||||
self._attr_native_unit_of_measurement = config.get(ATTR_SENSOR_UOM)
|
self._attr_native_unit_of_measurement = config.get(ATTR_SENSOR_UOM)
|
||||||
self._attr_state_class = config.get(ATTR_SENSOR_STATE_CLASS)
|
self._attr_state_class = config.get(ATTR_SENSOR_STATE_CLASS)
|
||||||
|
self._attr_native_value = self._calculate_native_value()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user