From c9ce848b4b65f4cf9771d5716adc4fb97c5a3d44 Mon Sep 17 00:00:00 2001 From: Brent Petit Date: Fri, 5 Apr 2024 14:54:40 -0500 Subject: [PATCH] Add current_humidity to Ecobee humidifier (#114753) * Ecobee: add current_humidity to humidifier * Ecobee: Add test for current_humidity property * Update current_humidity handling in climate and humidifier entity to support the ecobee API not returning actualHumidity, which is an optional value. Also updated tests to add a thermostat which covers a non-populated humidity. In passing, set up the new test thermostat to cover a missing condition where the code doens't recognize the ecobee model number. This gets ecobee humidifier test coverage to 100% --- homeassistant/components/ecobee/climate.py | 5 +- homeassistant/components/ecobee/humidifier.py | 8 ++ .../ecobee/fixtures/ecobee-data.json | 75 +++++++++++++++++++ tests/components/ecobee/test_humidifier.py | 3 + 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 0df8a42c566..e341f4176ad 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -509,7 +509,10 @@ class Thermostat(ClimateEntity): @property def current_humidity(self) -> int | None: """Return the current humidity.""" - return self.thermostat["runtime"]["actualHumidity"] + try: + return int(self.thermostat["runtime"]["actualHumidity"]) + except KeyError: + return None @property def hvac_action(self): diff --git a/homeassistant/components/ecobee/humidifier.py b/homeassistant/components/ecobee/humidifier.py index 0de7de2e803..d9616383ab6 100644 --- a/homeassistant/components/ecobee/humidifier.py +++ b/homeassistant/components/ecobee/humidifier.py @@ -110,6 +110,14 @@ class EcobeeHumidifier(HumidifierEntity): """Return the desired humidity set point.""" return int(self.thermostat["runtime"]["desiredHumidity"]) + @property + def current_humidity(self) -> int | None: + """Return the current humidity.""" + try: + return int(self.thermostat["runtime"]["actualHumidity"]) + except KeyError: + return None + def set_mode(self, mode): """Set humidifier mode (auto, off, manual).""" if mode.lower() not in (self.available_modes): diff --git a/tests/components/ecobee/fixtures/ecobee-data.json b/tests/components/ecobee/fixtures/ecobee-data.json index d9406c20c3b..d8621bd8c4b 100644 --- a/tests/components/ecobee/fixtures/ecobee-data.json +++ b/tests/components/ecobee/fixtures/ecobee-data.json @@ -139,6 +139,81 @@ ] } ] + }, + { + "identifier": 8675307, + "name": "unknownEcobeeName", + "modelNumber": "unknownEcobeeModel", + "program": { + "climates": [ + { + "name": "Climate1", + "climateRef": "c1" + }, + { + "name": "Climate2", + "climateRef": "c2" + } + ], + "currentClimateRef": "c1" + }, + "runtime": { + "connected": true, + "actualTemperature": 300, + "desiredHeat": 400, + "desiredCool": 200, + "desiredFanMode": "on", + "desiredHumidity": 40 + }, + "settings": { + "hvacMode": "auto", + "heatStages": 1, + "coolStages": 1, + "fanMinOnTime": 10, + "heatCoolMinDelta": 50, + "holdAction": "nextTransition", + "ventilatorType": "none", + "ventilatorMinOnTimeHome": 20, + "ventilatorMinOnTimeAway": 10, + "isVentilatorTimerOn": false, + "hasHumidifier": true, + "humidifierMode": "manual", + "humidity": "30" + }, + "equipmentStatus": "fan", + "events": [ + { + "name": "Event1", + "running": true, + "type": "hold", + "holdClimateRef": "away", + "startDate": "2022-02-02", + "startTime": "11:00:00", + "endDate": "2022-01-01", + "endTime": "10:00:00" + } + ], + "remoteSensors": [ + { + "id": "rs:100", + "name": "Remote Sensor 1", + "type": "ecobee3_remote_sensor", + "code": "WKRP", + "inUse": false, + "capability": [ + { + "id": "1", + "type": "temperature", + "value": "782" + }, + { + "id": "2", + "type": "occupancy", + "value": "false" + } + ] + } + ] } ] } diff --git a/tests/components/ecobee/test_humidifier.py b/tests/components/ecobee/test_humidifier.py index 36b52c9c357..f35a7dc9237 100644 --- a/tests/components/ecobee/test_humidifier.py +++ b/tests/components/ecobee/test_humidifier.py @@ -7,6 +7,7 @@ import pytest from homeassistant.components.ecobee.humidifier import MODE_MANUAL, MODE_OFF from homeassistant.components.humidifier import ( ATTR_AVAILABLE_MODES, + ATTR_CURRENT_HUMIDITY, ATTR_HUMIDITY, ATTR_MAX_HUMIDITY, ATTR_MIN_HUMIDITY, @@ -43,6 +44,8 @@ async def test_attributes(hass: HomeAssistant) -> None: state = hass.states.get(DEVICE_ID) assert state.state == STATE_ON + if state.attributes.get(ATTR_CURRENT_HUMIDITY): + assert state.attributes.get(ATTR_CURRENT_HUMIDITY) == 15 assert state.attributes.get(ATTR_MIN_HUMIDITY) == DEFAULT_MIN_HUMIDITY assert state.attributes.get(ATTR_MAX_HUMIDITY) == DEFAULT_MAX_HUMIDITY assert state.attributes.get(ATTR_HUMIDITY) == 40