From c8699dc066aa20fc86899bcf72673b24f897cf19 Mon Sep 17 00:00:00 2001 From: John Barreiros Date: Thu, 2 Jan 2025 04:44:15 -0500 Subject: [PATCH] Add `current_humidity` state attribute to Google Nest climate entity (#134426) --- homeassistant/components/nest/climate.py | 10 +++++++++- tests/components/nest/test_climate.py | 25 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/nest/climate.py b/homeassistant/components/nest/climate.py index d5ad28c2dfd..3193d592120 100644 --- a/homeassistant/components/nest/climate.py +++ b/homeassistant/components/nest/climate.py @@ -5,7 +5,7 @@ from __future__ import annotations from typing import Any, cast from google_nest_sdm.device import Device -from google_nest_sdm.device_traits import FanTrait, TemperatureTrait +from google_nest_sdm.device_traits import FanTrait, HumidityTrait, TemperatureTrait from google_nest_sdm.exceptions import ApiException from google_nest_sdm.thermostat_traits import ( ThermostatEcoTrait, @@ -133,6 +133,14 @@ class ThermostatEntity(ClimateEntity): trait: TemperatureTrait = self._device.traits[TemperatureTrait.NAME] return trait.ambient_temperature_celsius + @property + def current_humidity(self) -> float | None: + """Return the current humidity.""" + if HumidityTrait.NAME not in self._device.traits: + return None + trait: HumidityTrait = self._device.traits[HumidityTrait.NAME] + return trait.ambient_humidity_percent + @property def target_temperature(self) -> float | None: """Return the temperature currently set to be reached.""" diff --git a/tests/components/nest/test_climate.py b/tests/components/nest/test_climate.py index 39b5bf5aed7..fe148c2529d 100644 --- a/tests/components/nest/test_climate.py +++ b/tests/components/nest/test_climate.py @@ -13,6 +13,7 @@ import aiohttp import pytest from homeassistant.components.climate import ( + ATTR_CURRENT_HUMIDITY, ATTR_CURRENT_TEMPERATURE, ATTR_FAN_MODE, ATTR_FAN_MODES, @@ -122,6 +123,9 @@ async def test_thermostat_off( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, }, ) await setup_platform() @@ -131,6 +135,7 @@ async def test_thermostat_off( assert thermostat is not None assert thermostat.state == HVACMode.OFF assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.OFF + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT, @@ -163,6 +168,9 @@ async def test_thermostat_heat( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, "sdm.devices.traits.ThermostatTemperatureSetpoint": { "heatCelsius": 22.0, }, @@ -175,6 +183,7 @@ async def test_thermostat_heat( assert thermostat is not None assert thermostat.state == HVACMode.HEAT assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.HEATING + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT, @@ -883,6 +892,9 @@ async def test_thermostat_fan_off( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, } ) await setup_platform() @@ -892,6 +904,7 @@ async def test_thermostat_fan_off( assert thermostat is not None assert thermostat.state == HVACMode.COOL assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT, @@ -932,6 +945,9 @@ async def test_thermostat_fan_on( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, } ) await setup_platform() @@ -941,6 +957,7 @@ async def test_thermostat_fan_on( assert thermostat is not None assert thermostat.state == HVACMode.COOL assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT, @@ -1128,6 +1145,9 @@ async def test_thermostat_fan_empty( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, } ) await setup_platform() @@ -1137,6 +1157,7 @@ async def test_thermostat_fan_empty( assert thermostat is not None assert thermostat.state == HVACMode.OFF assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.OFF + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT, @@ -1181,6 +1202,9 @@ async def test_thermostat_invalid_fan_mode( "sdm.devices.traits.Temperature": { "ambientTemperatureCelsius": 16.2, }, + "sdm.devices.traits.Humidity": { + "ambientHumidityPercent": 40.6, + }, } ) await setup_platform() @@ -1190,6 +1214,7 @@ async def test_thermostat_invalid_fan_mode( assert thermostat is not None assert thermostat.state == HVACMode.COOL assert thermostat.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE + assert thermostat.attributes[ATTR_CURRENT_HUMIDITY] == 40.6 assert thermostat.attributes[ATTR_CURRENT_TEMPERATURE] == 16.2 assert set(thermostat.attributes[ATTR_HVAC_MODES]) == { HVACMode.HEAT,