From 775f815afca19415699927148fa730d211c7b98f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 30 Aug 2023 12:11:13 +0200 Subject: [PATCH] Use shorthand attributes for Ecobee (#99239) * Use shorthand attributes for Ecobee * Use shorthand attributes for Ecobee --- .../components/ecobee/binary_sensor.py | 8 +---- homeassistant/components/ecobee/climate.py | 36 +++++-------------- homeassistant/components/ecobee/humidifier.py | 24 +++---------- 3 files changed, 14 insertions(+), 54 deletions(-) diff --git a/homeassistant/components/ecobee/binary_sensor.py b/homeassistant/components/ecobee/binary_sensor.py index f194884f377..4ad0190e01a 100644 --- a/homeassistant/components/ecobee/binary_sensor.py +++ b/homeassistant/components/ecobee/binary_sensor.py @@ -43,7 +43,6 @@ class EcobeeBinarySensor(BinarySensorEntity): self.data = data self.sensor_name = sensor_name.rstrip() self.index = sensor_index - self._state = None @property def unique_id(self): @@ -93,11 +92,6 @@ class EcobeeBinarySensor(BinarySensorEntity): thermostat = self.data.ecobee.get_thermostat(self.index) return thermostat["runtime"]["connected"] - @property - def is_on(self): - """Return the status of the sensor.""" - return self._state == "true" - async def async_update(self) -> None: """Get the latest state of the sensor.""" await self.data.update() @@ -107,5 +101,5 @@ class EcobeeBinarySensor(BinarySensorEntity): for item in sensor["capability"]: if item["type"] != "occupancy": continue - self._state = item["value"] + self._attr_is_on = item["value"] == "true" break diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 5e1cff625a4..b18f646add7 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -310,6 +310,9 @@ class Thermostat(ClimateEntity): _attr_precision = PRECISION_TENTHS _attr_temperature_unit = UnitOfTemperature.FAHRENHEIT + _attr_min_humidity = DEFAULT_MIN_HUMIDITY + _attr_max_humidity = DEFAULT_MAX_HUMIDITY + _attr_fan_modes = [FAN_AUTO, FAN_ON] _attr_name = None _attr_has_entity_name = True @@ -324,20 +327,19 @@ class Thermostat(ClimateEntity): self.vacation = None self._last_active_hvac_mode = HVACMode.HEAT_COOL - self._operation_list = [] + self._attr_hvac_modes = [] if self.settings["heatStages"] or self.settings["hasHeatPump"]: - self._operation_list.append(HVACMode.HEAT) + self._attr_hvac_modes.append(HVACMode.HEAT) if self.settings["coolStages"]: - self._operation_list.append(HVACMode.COOL) - if len(self._operation_list) == 2: - self._operation_list.insert(0, HVACMode.HEAT_COOL) - self._operation_list.append(HVACMode.OFF) + self._attr_hvac_modes.append(HVACMode.COOL) + if len(self._attr_hvac_modes) == 2: + self._attr_hvac_modes.insert(0, HVACMode.HEAT_COOL) + self._attr_hvac_modes.append(HVACMode.OFF) self._preset_modes = { comfort["climateRef"]: comfort["name"] for comfort in self.thermostat["program"]["climates"] } - self._fan_modes = [FAN_AUTO, FAN_ON] self.update_without_throttle = False async def async_update(self) -> None: @@ -432,16 +434,6 @@ class Thermostat(ClimateEntity): return self.thermostat["runtime"]["desiredHumidity"] return None - @property - def min_humidity(self) -> int: - """Return the minimum humidity.""" - return DEFAULT_MIN_HUMIDITY - - @property - def max_humidity(self) -> int: - """Return the maximum humidity.""" - return DEFAULT_MAX_HUMIDITY - @property def target_temperature(self) -> float | None: """Return the temperature we try to reach.""" @@ -465,11 +457,6 @@ class Thermostat(ClimateEntity): """Return the fan setting.""" return self.thermostat["runtime"]["desiredFanMode"] - @property - def fan_modes(self): - """Return the available fan modes.""" - return self._fan_modes - @property def preset_mode(self): """Return current preset mode.""" @@ -498,11 +485,6 @@ class Thermostat(ClimateEntity): """Return current operation.""" return ECOBEE_HVAC_TO_HASS[self.settings["hvacMode"]] - @property - def hvac_modes(self): - """Return the operation modes list.""" - return self._operation_list - @property def current_humidity(self) -> int | None: """Return the current humidity.""" diff --git a/homeassistant/components/ecobee/humidifier.py b/homeassistant/components/ecobee/humidifier.py index 25a2a56ba93..d8ebd3d77d8 100644 --- a/homeassistant/components/ecobee/humidifier.py +++ b/homeassistant/components/ecobee/humidifier.py @@ -44,6 +44,10 @@ class EcobeeHumidifier(HumidifierEntity): """A humidifier class for an ecobee thermostat with humidifier attached.""" _attr_supported_features = HumidifierEntityFeature.MODES + _attr_available_modes = [MODE_OFF, MODE_AUTO, MODE_MANUAL] + _attr_device_class = HumidifierDeviceClass.HUMIDIFIER + _attr_min_humidity = DEFAULT_MIN_HUMIDITY + _attr_max_humidity = DEFAULT_MAX_HUMIDITY _attr_has_entity_name = True _attr_name = None @@ -90,31 +94,11 @@ class EcobeeHumidifier(HumidifierEntity): if self.mode != MODE_OFF: self._last_humidifier_on_mode = self.mode - @property - def available_modes(self): - """Return the list of available modes.""" - return [MODE_OFF, MODE_AUTO, MODE_MANUAL] - - @property - def device_class(self): - """Return the device class type.""" - return HumidifierDeviceClass.HUMIDIFIER - @property def is_on(self): """Return True if the humidifier is on.""" return self.mode != MODE_OFF - @property - def max_humidity(self): - """Return the maximum humidity.""" - return DEFAULT_MAX_HUMIDITY - - @property - def min_humidity(self): - """Return the minimum humidity.""" - return DEFAULT_MIN_HUMIDITY - @property def mode(self): """Return the current mode, e.g., off, auto, manual."""