Skip to content

Commit 82ac3e3

Browse files
SLakszweckj
andauthored
Ecobee: Report Humidifier Action (#138756)
Co-authored-by: Josef Zweck <[email protected]>
1 parent c487978 commit 82ac3e3

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

homeassistant/components/ecobee/humidifier.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from __future__ import annotations
44

55
from datetime import timedelta
6+
from typing import Any
67

78
from homeassistant.components.humidifier import (
89
DEFAULT_MAX_HUMIDITY,
910
DEFAULT_MIN_HUMIDITY,
1011
MODE_AUTO,
12+
HumidifierAction,
1113
HumidifierDeviceClass,
1214
HumidifierEntity,
1315
HumidifierEntityFeature,
@@ -41,6 +43,12 @@ async def async_setup_entry(
4143
async_add_entities(entities, True)
4244

4345

46+
ECOBEE_HUMIDIFIER_ACTION_TO_HASS = {
47+
"humidifier": HumidifierAction.HUMIDIFYING,
48+
"dehumidifier": HumidifierAction.DRYING,
49+
}
50+
51+
4452
class EcobeeHumidifier(HumidifierEntity):
4553
"""A humidifier class for an ecobee thermostat with humidifier attached."""
4654

@@ -52,7 +60,7 @@ class EcobeeHumidifier(HumidifierEntity):
5260
_attr_has_entity_name = True
5361
_attr_name = None
5462

55-
def __init__(self, data, thermostat_index):
63+
def __init__(self, data, thermostat_index) -> None:
5664
"""Initialize ecobee humidifier platform."""
5765
self.data = data
5866
self.thermostat_index = thermostat_index
@@ -80,11 +88,11 @@ def device_info(self) -> DeviceInfo:
8088
)
8189

8290
@property
83-
def available(self):
91+
def available(self) -> bool:
8492
"""Return if device is available."""
8593
return self.thermostat["runtime"]["connected"]
8694

87-
async def async_update(self):
95+
async def async_update(self) -> None:
8896
"""Get the latest state from the thermostat."""
8997
if self.update_without_throttle:
9098
await self.data.update(no_throttle=True)
@@ -96,12 +104,20 @@ async def async_update(self):
96104
self._last_humidifier_on_mode = self.mode
97105

98106
@property
99-
def is_on(self):
107+
def action(self) -> HumidifierAction:
108+
"""Return the current action."""
109+
for status in self.thermostat["equipmentStatus"].split(","):
110+
if status in ECOBEE_HUMIDIFIER_ACTION_TO_HASS:
111+
return ECOBEE_HUMIDIFIER_ACTION_TO_HASS[status]
112+
return HumidifierAction.IDLE if self.is_on else HumidifierAction.OFF
113+
114+
@property
115+
def is_on(self) -> bool:
100116
"""Return True if the humidifier is on."""
101117
return self.mode != MODE_OFF
102118

103119
@property
104-
def mode(self):
120+
def mode(self) -> str:
105121
"""Return the current mode, e.g., off, auto, manual."""
106122
return self.thermostat["settings"]["humidifierMode"]
107123

@@ -118,9 +134,11 @@ def current_humidity(self) -> int | None:
118134
except KeyError:
119135
return None
120136

121-
def set_mode(self, mode):
137+
def set_mode(self, mode: str) -> None:
122138
"""Set humidifier mode (auto, off, manual)."""
123-
if mode.lower() not in (self.available_modes):
139+
if self.available_modes is None:
140+
raise NotImplementedError("Humidifier does not support modes.")
141+
if mode.lower() not in self.available_modes:
124142
raise ValueError(
125143
f"Invalid mode value: {mode} Valid values are"
126144
f" {', '.join(self.available_modes)}."
@@ -134,10 +152,10 @@ def set_humidity(self, humidity: int) -> None:
134152
self.data.ecobee.set_humidity(self.thermostat_index, humidity)
135153
self.update_without_throttle = True
136154

137-
def turn_off(self, **kwargs):
155+
def turn_off(self, **kwargs: Any) -> None:
138156
"""Set humidifier to off mode."""
139157
self.set_mode(MODE_OFF)
140158

141-
def turn_on(self, **kwargs):
159+
def turn_on(self, **kwargs: Any) -> None:
142160
"""Set humidifier to on mode."""
143161
self.set_mode(self._last_humidifier_on_mode)

tests/components/ecobee/fixtures/ecobee-data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"hasHeatPump": false,
6868
"humidity": "30"
6969
},
70-
"equipmentStatus": "fan",
70+
"equipmentStatus": "fan,humidifier",
7171
"events": [
7272
{
7373
"name": "Event1",

tests/components/ecobee/test_humidifier.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from homeassistant.components.ecobee.humidifier import MODE_MANUAL, MODE_OFF
88
from homeassistant.components.humidifier import (
9+
ATTR_ACTION,
910
ATTR_AVAILABLE_MODES,
1011
ATTR_CURRENT_HUMIDITY,
1112
ATTR_HUMIDITY,
@@ -17,6 +18,7 @@
1718
MODE_AUTO,
1819
SERVICE_SET_HUMIDITY,
1920
SERVICE_SET_MODE,
21+
HumidifierAction,
2022
HumidifierDeviceClass,
2123
HumidifierEntityFeature,
2224
)
@@ -44,6 +46,7 @@ async def test_attributes(hass: HomeAssistant) -> None:
4446

4547
state = hass.states.get(DEVICE_ID)
4648
assert state.state == STATE_ON
49+
assert state.attributes[ATTR_ACTION] == HumidifierAction.HUMIDIFYING
4750
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 15
4851
assert state.attributes[ATTR_MIN_HUMIDITY] == DEFAULT_MIN_HUMIDITY
4952
assert state.attributes[ATTR_MAX_HUMIDITY] == DEFAULT_MAX_HUMIDITY

0 commit comments

Comments
 (0)