Use _attr_* in ecoal_boiler (#61363)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/61520/head^2
parent
3b80cbc495
commit
933d624a4e
|
@ -1,6 +1,6 @@
|
|||
"""Allows reading temperatures from ecoal/esterownik.pl controller."""
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
|
||||
from . import AVAILABLE_SENSORS, DATA_ECOAL_BOILER
|
||||
|
||||
|
@ -20,32 +20,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class EcoalTempSensor(SensorEntity):
|
||||
"""Representation of a temperature sensor using ecoal status data."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
|
||||
def __init__(self, ecoal_contr, name, status_attr):
|
||||
"""Initialize the sensor."""
|
||||
self._ecoal_contr = ecoal_contr
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
self._status_attr = status_attr
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||
return DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor.
|
||||
|
@ -54,4 +36,4 @@ class EcoalTempSensor(SensorEntity):
|
|||
"""
|
||||
# Old values read 0.5 back can still be used
|
||||
status = self._ecoal_contr.get_cached_status()
|
||||
self._state = getattr(status, self._status_attr)
|
||||
self._attr_native_value = getattr(status, self._status_attr)
|
||||
|
|
|
@ -28,7 +28,7 @@ class EcoalSwitch(SwitchEntity):
|
|||
Sets HA switch to state as read from controller.
|
||||
"""
|
||||
self._ecoal_contr = ecoal_contr
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
self._state_attr = state_attr
|
||||
# Ecoalcotroller holds convention that same postfix is used
|
||||
# to set attribute
|
||||
|
@ -36,13 +36,6 @@ class EcoalSwitch(SwitchEntity):
|
|||
# as attribute name in status instance:
|
||||
# status.<attr>
|
||||
self._contr_set_fun = getattr(self._ecoal_contr, f"set_{state_attr}")
|
||||
# No value set, will be read from controller instead
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor.
|
||||
|
@ -50,7 +43,7 @@ class EcoalSwitch(SwitchEntity):
|
|||
This is the only method that should fetch new data for Home Assistant.
|
||||
"""
|
||||
status = self._ecoal_contr.get_cached_status()
|
||||
self._state = getattr(status, self._state_attr)
|
||||
self._attr_is_on = getattr(status, self._state_attr)
|
||||
|
||||
def invalidate_ecoal_cache(self):
|
||||
"""Invalidate ecoal interface cache.
|
||||
|
@ -59,11 +52,6 @@ class EcoalSwitch(SwitchEntity):
|
|||
"""
|
||||
self._ecoal_contr.status = None
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs) -> None:
|
||||
"""Turn the device on."""
|
||||
self._contr_set_fun(1)
|
||||
|
|
Loading…
Reference in New Issue