Skip to content

Commit

Permalink
Use shorthand attributes for Ecobee (home-assistant#99239)
Browse files Browse the repository at this point in the history
* Use shorthand attributes for Ecobee

* Use shorthand attributes for Ecobee
  • Loading branch information
joostlek authored Aug 30, 2023
1 parent a4818c5 commit 775f815
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 54 deletions.
8 changes: 1 addition & 7 deletions homeassistant/components/ecobee/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(self, data, sensor_name, sensor_index):
self.data = data
self.sensor_name = sensor_name.rstrip()
self.index = sensor_index
self._state = None

@property
def unique_id(self):
Expand Down Expand Up @@ -93,11 +92,6 @@ def available(self) -> bool:
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()
Expand All @@ -107,5 +101,5 @@ async def async_update(self) -> None:
for item in sensor["capability"]:
if item["type"] != "occupancy":
continue
self._state = item["value"]
self._attr_is_on = item["value"] == "true"
break
36 changes: 9 additions & 27 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -324,20 +327,19 @@ def __init__(
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:
Expand Down Expand Up @@ -432,16 +434,6 @@ def target_humidity(self) -> int | None:
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."""
Expand All @@ -465,11 +457,6 @@ def fan_mode(self):
"""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."""
Expand Down Expand Up @@ -498,11 +485,6 @@ def hvac_mode(self):
"""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."""
Expand Down
24 changes: 4 additions & 20 deletions homeassistant/components/ecobee/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -90,31 +94,11 @@ async def async_update(self):
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."""
Expand Down

0 comments on commit 775f815

Please sign in to comment.