From 1d2a9732890820da1dbafd55d80ca15bd1d84b60 Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Tue, 20 Jun 2023 21:10:21 +0300 Subject: [PATCH] Generic hygrostat current humidity (#94912) --- .../components/generic_hygrostat/humidifier.py | 5 +++++ .../generic_hygrostat/test_humidifier.py | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/generic_hygrostat/humidifier.py b/homeassistant/components/generic_hygrostat/humidifier.py index a6e76330f29..be36da643e9 100644 --- a/homeassistant/components/generic_hygrostat/humidifier.py +++ b/homeassistant/components/generic_hygrostat/humidifier.py @@ -248,6 +248,11 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity): """Return true if the hygrostat is on.""" return self._state + @property + def current_humidity(self): + """Return the measured humidity.""" + return self._cur_humidity + @property def target_humidity(self): """Return the humidity we try to reach.""" diff --git a/tests/components/generic_hygrostat/test_humidifier.py b/tests/components/generic_hygrostat/test_humidifier.py index a87f2472fd3..341571fe9ad 100644 --- a/tests/components/generic_hygrostat/test_humidifier.py +++ b/tests/components/generic_hygrostat/test_humidifier.py @@ -414,16 +414,26 @@ async def test_set_away_mode_twice_and_restore_prev_humidity( assert state.attributes.get("humidity") == 44 +async def test_sensor_affects_attribute(hass: HomeAssistant, setup_comp_2) -> None: + """Test that the sensor changes are reflected in the current_humidity attribute.""" + state = hass.states.get(ENTITY) + assert state.attributes.get("current_humidity") == 45 + + _setup_sensor(hass, 47) + await hass.async_block_till_done() + + state = hass.states.get(ENTITY) + assert state.attributes.get("current_humidity") == 47 + + async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None: """Test sensor that have None as state.""" - state = hass.states.get(ENTITY) - humidity = state.attributes.get("current_humidity") + assert hass.states.get(ENTITY).state == STATE_ON _setup_sensor(hass, None) await hass.async_block_till_done() - state = hass.states.get(ENTITY) - assert humidity == state.attributes.get("current_humidity") + assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE async def test_set_target_humidity_humidifier_on(