From d6b89b6f7bc51cdc7cc748b268b96a78d2518cb3 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 20 Jun 2023 22:46:07 +0200 Subject: [PATCH] Add current_humidity attribute on homekit_controller humidifier (#94937) --- .../components/homekit_controller/humidifier.py | 10 ++++++++++ .../homekit_controller/test_humidifier.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/homeassistant/components/homekit_controller/humidifier.py b/homeassistant/components/homekit_controller/humidifier.py index e396b3c9c97..cd2cf4022e7 100644 --- a/homeassistant/components/homekit_controller/humidifier.py +++ b/homeassistant/components/homekit_controller/humidifier.py @@ -73,6 +73,11 @@ class HomeKitHumidifier(HomeKitEntity, HumidifierEntity): CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD ) + @property + def current_humidity(self) -> int | None: + """Return the current humidity.""" + return self.service.value(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT) + @property def mode(self) -> str | None: """Return the current mode, e.g., home, auto, baby. @@ -177,6 +182,11 @@ class HomeKitDehumidifier(HomeKitEntity, HumidifierEntity): CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD ) + @property + def current_humidity(self) -> int | None: + """Return the current humidity.""" + return self.service.value(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT) + @property def mode(self) -> str | None: """Return the current mode, e.g., home, auto, baby. diff --git a/tests/components/homekit_controller/test_humidifier.py b/tests/components/homekit_controller/test_humidifier.py index a1909158d33..e412fed0878 100644 --- a/tests/components/homekit_controller/test_humidifier.py +++ b/tests/components/homekit_controller/test_humidifier.py @@ -118,20 +118,24 @@ async def test_humidifier_read_humidity(hass: HomeAssistant, utcnow) -> None: { CharacteristicsTypes.ACTIVE: True, CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD: 75, + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: 45, }, ) assert state.state == "on" assert state.attributes["humidity"] == 75 + assert state.attributes["current_humidity"] == 45 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, { CharacteristicsTypes.ACTIVE: False, CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD: 10, + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: 30, }, ) assert state.state == "off" assert state.attributes["humidity"] == 10 + assert state.attributes["current_humidity"] == 30 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -140,6 +144,7 @@ async def test_humidifier_read_humidity(hass: HomeAssistant, utcnow) -> None: }, ) assert state.attributes["humidity"] == 10 + assert state.attributes["current_humidity"] == 30 assert state.state == "off" @@ -152,20 +157,24 @@ async def test_dehumidifier_read_humidity(hass: HomeAssistant, utcnow) -> None: { CharacteristicsTypes.ACTIVE: True, CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD: 75, + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: 45, }, ) assert state.state == "on" assert state.attributes["humidity"] == 75 + assert state.attributes["current_humidity"] == 45 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, { CharacteristicsTypes.ACTIVE: False, CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD: 40, + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: 39, }, ) assert state.state == "off" assert state.attributes["humidity"] == 40 + assert state.attributes["current_humidity"] == 39 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -368,6 +377,7 @@ async def test_humidifier_target_humidity_modes(hass: HomeAssistant, utcnow) -> ) assert state.attributes["mode"] == "auto" assert state.attributes["humidity"] == 37 + assert state.attributes["current_humidity"] == 51 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -377,6 +387,7 @@ async def test_humidifier_target_humidity_modes(hass: HomeAssistant, utcnow) -> ) assert state.attributes["mode"] == "normal" assert state.attributes["humidity"] == 37 + assert state.attributes["current_humidity"] == 51 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -411,6 +422,7 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant, utcnow) - ) assert state.attributes["mode"] == "auto" assert state.attributes["humidity"] == 73 + assert state.attributes["current_humidity"] == 51 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -420,6 +432,7 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant, utcnow) - ) assert state.attributes["mode"] == "normal" assert state.attributes["humidity"] == 73 + assert state.attributes["current_humidity"] == 51 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -429,6 +442,7 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant, utcnow) - ) assert state.attributes["mode"] == "normal" assert state.attributes["humidity"] == 73 + assert state.attributes["current_humidity"] == 51 state = await helper.async_update( ServicesTypes.HUMIDIFIER_DEHUMIDIFIER, @@ -438,6 +452,7 @@ async def test_dehumidifier_target_humidity_modes(hass: HomeAssistant, utcnow) - ) assert state.attributes["mode"] == "normal" assert state.attributes["humidity"] == 73 + assert state.attributes["current_humidity"] == 51 async def test_migrate_entity_ids(hass: HomeAssistant, utcnow) -> None: