From 73f2d972e451fcd77b7f2822f478aab8e93f1ccd Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 28 Oct 2024 21:01:34 +0100 Subject: [PATCH] Use shorthand attribute for available in statistics (#129354) --- homeassistant/components/statistics/sensor.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 7edffc54fcd..0bde1271720 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -361,7 +361,7 @@ class StatisticsSensor(SensorEntity): self._precision: int = precision self._percentile: int = percentile self._value: float | int | datetime | None = None - self._available: bool = False + self._attr_available: bool = False self.states: deque[float | bool] = deque(maxlen=self._samples_max_buffer_size) self.ages: deque[datetime] = deque(maxlen=self._samples_max_buffer_size) @@ -385,7 +385,7 @@ class StatisticsSensor(SensorEntity): if not self._source_entity_id or ( self._samples_max_buffer_size is None and self._samples_max_age is None ): - self._available = False + self._attr_available = False calculated_state = self._async_calculate_state() preview_callback(calculated_state.state, calculated_state.attributes) return self._call_on_remove_callbacks @@ -461,7 +461,7 @@ class StatisticsSensor(SensorEntity): # Attention: it is not safe to store the new_state object, # since the "last_reported" value will be updated over time. # Here we make a copy the current value, which is okay. - self._available = new_state.state != STATE_UNAVAILABLE + self._attr_available = new_state.state != STATE_UNAVAILABLE if new_state.state == STATE_UNAVAILABLE: self.attributes[STAT_SOURCE_VALUE_VALID] = None return @@ -590,11 +590,6 @@ class StatisticsSensor(SensorEntity): """Return the state of the sensor.""" return self._value - @property - def available(self) -> bool: - """Return the availability of the sensor linked to the source sensor.""" - return self._available - @property def extra_state_attributes(self) -> dict[str, StateType] | None: """Return the state attributes of the sensor."""