1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Use shorthand attributes for Ecobee (#99239)

* Use shorthand attributes for Ecobee

* Use shorthand attributes for Ecobee
This commit is contained in:
Joost Lekkerkerker 2023-08-30 12:11:13 +02:00 committed by GitHub
parent a4818c5f54
commit 775f815afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 54 deletions

View File

@ -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

View File

@ -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."""

View File

@ -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."""