mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Use shorthand attribute for native value in statistics (#129355)
This commit is contained in:
parent
dd9ce34d18
commit
9546bf1dee
@ -360,7 +360,6 @@ class StatisticsSensor(SensorEntity):
|
|||||||
self.samples_keep_last: bool = samples_keep_last
|
self.samples_keep_last: bool = samples_keep_last
|
||||||
self._precision: int = precision
|
self._precision: int = precision
|
||||||
self._percentile: int = percentile
|
self._percentile: int = percentile
|
||||||
self._value: float | int | datetime | None = None
|
|
||||||
self._attr_available: bool = False
|
self._attr_available: bool = False
|
||||||
|
|
||||||
self.states: deque[float | bool] = deque(maxlen=self._samples_max_buffer_size)
|
self.states: deque[float | bool] = deque(maxlen=self._samples_max_buffer_size)
|
||||||
@ -585,11 +584,6 @@ class StatisticsSensor(SensorEntity):
|
|||||||
return None
|
return None
|
||||||
return SensorStateClass.MEASUREMENT
|
return SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self) -> float | int | datetime | None:
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, StateType] | None:
|
def extra_state_attributes(self) -> dict[str, StateType] | None:
|
||||||
"""Return the state attributes of the sensor."""
|
"""Return the state attributes of the sensor."""
|
||||||
@ -776,7 +770,7 @@ class StatisticsSensor(SensorEntity):
|
|||||||
value = round(cast(float, value), self._precision)
|
value = round(cast(float, value), self._precision)
|
||||||
if self._precision == 0:
|
if self._precision == 0:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
self._value = value
|
self._attr_native_value = value
|
||||||
|
|
||||||
def _callable_characteristic_fn(
|
def _callable_characteristic_fn(
|
||||||
self, characteristic: str
|
self, characteristic: str
|
||||||
|
Loading…
x
Reference in New Issue
Block a user