mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Use class attribute instead of property in min_max integration (#73175)
This commit is contained in:
parent
0b5c0f8249
commit
981c34f88d
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user