From 933d624a4e5e5622e0d2bb42f06e6034db683671 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 14 Dec 2021 00:17:39 +0100 Subject: [PATCH] Use _attr_* in ecoal_boiler (#61363) Co-authored-by: epenet --- .../components/ecoal_boiler/sensor.py | 32 ++++--------------- .../components/ecoal_boiler/switch.py | 16 ++-------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/homeassistant/components/ecoal_boiler/sensor.py b/homeassistant/components/ecoal_boiler/sensor.py index d9689631280..8ed5129b628 100644 --- a/homeassistant/components/ecoal_boiler/sensor.py +++ b/homeassistant/components/ecoal_boiler/sensor.py @@ -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) diff --git a/homeassistant/components/ecoal_boiler/switch.py b/homeassistant/components/ecoal_boiler/switch.py index 995a49554e6..e12d4dbf0a2 100644 --- a/homeassistant/components/ecoal_boiler/switch.py +++ b/homeassistant/components/ecoal_boiler/switch.py @@ -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. 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)