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):
|
class AquaLogicSensor(SensorEntity):
|
||||||
"""Sensor implementation for the AquaLogic component."""
|
"""Sensor implementation for the AquaLogic component."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, processor, sensor_type):
|
def __init__(self, processor, sensor_type):
|
||||||
"""Initialize sensor."""
|
"""Initialize sensor."""
|
||||||
self._processor = processor
|
self._processor = processor
|
||||||
self._type = sensor_type
|
self._type = sensor_type
|
||||||
self._state = None
|
self._attr_name = f"AquaLogic {SENSOR_TYPES[sensor_type][0]}"
|
||||||
|
self._attr_icon = SENSOR_TYPES[sensor_type][2]
|
||||||
@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]
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
|
@ -123,5 +91,11 @@ class AquaLogicSensor(SensorEntity):
|
||||||
"""Update callback."""
|
"""Update callback."""
|
||||||
panel = self._processor.panel
|
panel = self._processor.panel
|
||||||
if panel is not None:
|
if panel is not None:
|
||||||
self._state = getattr(panel, self._type)
|
if panel.is_metric:
|
||||||
self.async_write_ha_state()
|
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
|
||||||
|
|
|
@ -44,10 +44,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
class AquaLogicSwitch(SwitchEntity):
|
class AquaLogicSwitch(SwitchEntity):
|
||||||
"""Switch implementation for the AquaLogic component."""
|
"""Switch implementation for the AquaLogic component."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, processor, switch_type):
|
def __init__(self, processor, switch_type):
|
||||||
"""Initialize switch."""
|
"""Initialize switch."""
|
||||||
self._processor = processor
|
self._processor = processor
|
||||||
self._type = switch_type
|
|
||||||
self._state_name = {
|
self._state_name = {
|
||||||
"lights": States.LIGHTS,
|
"lights": States.LIGHTS,
|
||||||
"filter": States.FILTER,
|
"filter": States.FILTER,
|
||||||
|
@ -60,16 +61,7 @@ class AquaLogicSwitch(SwitchEntity):
|
||||||
"aux_6": States.AUX_6,
|
"aux_6": States.AUX_6,
|
||||||
"aux_7": States.AUX_7,
|
"aux_7": States.AUX_7,
|
||||||
}[switch_type]
|
}[switch_type]
|
||||||
|
self._attr_name = f"AquaLogic {SWITCH_TYPES[switch_type]}"
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the switch."""
|
|
||||||
return f"AquaLogic {SWITCH_TYPES[self._type]}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return the polling state."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue