Use shorthand attribute for native value in statistics (#129355)

This commit is contained in:
G Johansson 2024-10-28 22:43:09 +01:00 committed by GitHub
parent dd9ce34d18
commit 9546bf1dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -360,7 +360,6 @@ class StatisticsSensor(SensorEntity):
self.samples_keep_last: bool = samples_keep_last
self._precision: int = precision
self._percentile: int = percentile
self._value: float | int | datetime | None = None
self._attr_available: bool = False
self.states: deque[float | bool] = deque(maxlen=self._samples_max_buffer_size)
@ -585,11 +584,6 @@ class StatisticsSensor(SensorEntity):
return None
return SensorStateClass.MEASUREMENT
@property
def native_value(self) -> float | int | datetime | None:
"""Return the state of the sensor."""
return self._value
@property
def extra_state_attributes(self) -> dict[str, StateType] | None:
"""Return the state attributes of the sensor."""
@ -776,7 +770,7 @@ class StatisticsSensor(SensorEntity):
value = round(cast(float, value), self._precision)
if self._precision == 0:
value = int(value)
self._value = value
self._attr_native_value = value
def _callable_characteristic_fn(
self, characteristic: str