Use entity class attributes for aqualogic (#52668)
This commit is contained in:
parent
9864f2ef8b
commit
fe5abf1a87
2 changed files with 15 additions and 49 deletions
|
@ -69,46 +69,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
class AquaLogicSensor(SensorEntity):
|
||||
"""Sensor implementation for the AquaLogic component."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, processor, sensor_type):
|
||||
"""Initialize sensor."""
|
||||
self._processor = processor
|
||||
self._type = sensor_type
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return f"AquaLogic {SENSOR_TYPES[self._type][0]}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement the value is expressed in."""
|
||||
panel = self._processor.panel
|
||||
if panel is None:
|
||||
return None
|
||||
if panel.is_metric:
|
||||
return SENSOR_TYPES[self._type][1][0]
|
||||
return SENSOR_TYPES[self._type][1][1]
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling state."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||
return SENSOR_TYPES[self._type][3]
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Icon to use in the frontend, if any."""
|
||||
return SENSOR_TYPES[self._type][2]
|
||||
self._attr_name = f"AquaLogic {SENSOR_TYPES[sensor_type][0]}"
|
||||
self._attr_icon = SENSOR_TYPES[sensor_type][2]
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
@ -123,5 +91,11 @@ class AquaLogicSensor(SensorEntity):
|
|||
"""Update callback."""
|
||||
panel = self._processor.panel
|
||||
if panel is not None:
|
||||
self._state = getattr(panel, self._type)
|
||||
self.async_write_ha_state()
|
||||
if panel.is_metric:
|
||||
self._attr_unit_of_measurement = SENSOR_TYPES[self._type][1][0]
|
||||
self._attr_state = getattr(panel, self._type)
|
||||
self.async_write_ha_state()
|
||||
else:
|
||||
self._attr_unit_of_measurement = SENSOR_TYPES[self._type][1][1]
|
||||
else:
|
||||
self._attr_unit_of_measurement = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue