From 981c34f88d9aa7b9c68db47d1c1b3a8f9af7d1e1 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Tue, 7 Jun 2022 19:15:25 +0200 Subject: [PATCH] Use class attribute instead of property in min_max integration (#73175) --- homeassistant/components/min_max/sensor.py | 28 +++++----------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/min_max/sensor.py b/homeassistant/components/min_max/sensor.py index 99aec4e9e7b..c5a51cdda7a 100644 --- a/homeassistant/components/min_max/sensor.py +++ b/homeassistant/components/min_max/sensor.py @@ -161,6 +161,10 @@ def calc_median(sensor_values, round_digits): class MinMaxSensor(SensorEntity): """Representation of a min/max sensor.""" + _attr_icon = ICON + _attr_should_poll = False + _attr_state_class = SensorStateClass.MEASUREMENT + def __init__(self, entity_ids, name, sensor_type, round_digits, unique_id): """Initialize the min/max sensor.""" self._attr_unique_id = unique_id @@ -169,9 +173,9 @@ class MinMaxSensor(SensorEntity): self._round_digits = round_digits if name: - self._name = name + self._attr_name = name else: - self._name = f"{sensor_type} sensor".capitalize() + self._attr_name = f"{sensor_type} sensor".capitalize() self._sensor_attr = SENSOR_TYPE_TO_ATTR[self._sensor_type] self._unit_of_measurement = None self._unit_of_measurement_mismatch = False @@ -196,11 +200,6 @@ class MinMaxSensor(SensorEntity): self._calc_values() - @property - def name(self): - """Return the name of the sensor.""" - return self._name - @property def native_value(self): """Return the state of the sensor.""" @@ -215,11 +214,6 @@ class MinMaxSensor(SensorEntity): return "ERR" return self._unit_of_measurement - @property - def should_poll(self): - """No polling needed.""" - return False - @property def extra_state_attributes(self): """Return the state attributes of the sensor.""" @@ -231,16 +225,6 @@ class MinMaxSensor(SensorEntity): return {ATTR_LAST_ENTITY_ID: self.last_entity_id} return None - @property - def icon(self): - """Return the icon to use in the frontend, if any.""" - return ICON - - @property - def state_class(self) -> SensorStateClass: - """Return the state class.""" - return SensorStateClass.MEASUREMENT - @callback def _async_min_max_sensor_state_listener(self, event, update_state=True): """Handle the sensor state changes."""