diff --git a/homeassistant/components/demo/humidifier.py b/homeassistant/components/demo/humidifier.py index 772726ac1d5..75c2cf3120a 100644 --- a/homeassistant/components/demo/humidifier.py +++ b/homeassistant/components/demo/humidifier.py @@ -29,12 +29,14 @@ async def async_setup_platform( name="Humidifier", mode=None, target_humidity=68, + current_humidity=45, device_class=HumidifierDeviceClass.HUMIDIFIER, ), DemoHumidifier( name="Dehumidifier", mode=None, target_humidity=54, + current_humidity=59, device_class=HumidifierDeviceClass.DEHUMIDIFIER, ), DemoHumidifier( @@ -66,6 +68,7 @@ class DemoHumidifier(HumidifierEntity): name: str, mode: str | None, target_humidity: int, + current_humidity: int | None = None, available_modes: list[str] | None = None, is_on: bool = True, device_class: HumidifierDeviceClass | None = None, @@ -77,6 +80,7 @@ class DemoHumidifier(HumidifierEntity): if mode is not None: self._attr_supported_features |= HumidifierEntityFeature.MODES self._attr_target_humidity = target_humidity + self._attr_current_humidity = current_humidity self._attr_mode = mode self._attr_available_modes = available_modes self._attr_device_class = device_class diff --git a/homeassistant/components/humidifier/__init__.py b/homeassistant/components/humidifier/__init__.py index 0bc7e242d55..49c3f4681a8 100644 --- a/homeassistant/components/humidifier/__init__.py +++ b/homeassistant/components/humidifier/__init__.py @@ -30,6 +30,7 @@ from homeassistant.loader import bind_hass from .const import ( # noqa: F401 ATTR_AVAILABLE_MODES, + ATTR_CURRENT_HUMIDITY, ATTR_HUMIDITY, ATTR_MAX_HUMIDITY, ATTR_MIN_HUMIDITY, @@ -133,6 +134,7 @@ class HumidifierEntity(ToggleEntity): entity_description: HumidifierEntityDescription _attr_available_modes: list[str] | None + _attr_current_humidity: int | None = None _attr_device_class: HumidifierDeviceClass | None _attr_max_humidity: int = DEFAULT_MAX_HUMIDITY _attr_min_humidity: int = DEFAULT_MIN_HUMIDITY @@ -168,6 +170,9 @@ class HumidifierEntity(ToggleEntity): """Return the optional state attributes.""" data: dict[str, int | str | None] = {} + if self.current_humidity is not None: + data[ATTR_CURRENT_HUMIDITY] = self.current_humidity + if self.target_humidity is not None: data[ATTR_HUMIDITY] = self.target_humidity @@ -176,6 +181,11 @@ class HumidifierEntity(ToggleEntity): return data + @property + def current_humidity(self) -> int | None: + """Return the current humidity.""" + return self._attr_current_humidity + @property def target_humidity(self) -> int | None: """Return the humidity we try to reach.""" diff --git a/homeassistant/components/humidifier/const.py b/homeassistant/components/humidifier/const.py index 1f802f7fa36..27e181fe63c 100644 --- a/homeassistant/components/humidifier/const.py +++ b/homeassistant/components/humidifier/const.py @@ -12,6 +12,7 @@ MODE_AUTO = "auto" MODE_BABY = "baby" ATTR_AVAILABLE_MODES = "available_modes" +ATTR_CURRENT_HUMIDITY = "current_humidity" ATTR_HUMIDITY = "humidity" ATTR_MAX_HUMIDITY = "max_humidity" ATTR_MIN_HUMIDITY = "min_humidity" diff --git a/homeassistant/components/humidifier/strings.json b/homeassistant/components/humidifier/strings.json index 015b3c08e9a..e4f5961a3cf 100644 --- a/homeassistant/components/humidifier/strings.json +++ b/homeassistant/components/humidifier/strings.json @@ -31,6 +31,9 @@ "available_modes": { "name": "Available modes" }, + "current_humidity": { + "name": "Current humidity" + }, "humidity": { "name": "Target humidity" }, diff --git a/tests/components/demo/test_humidifier.py b/tests/components/demo/test_humidifier.py index d0b1e15ea61..501362d6533 100644 --- a/tests/components/demo/test_humidifier.py +++ b/tests/components/demo/test_humidifier.py @@ -4,6 +4,7 @@ import pytest import voluptuous as vol from homeassistant.components.humidifier import ( + ATTR_CURRENT_HUMIDITY, ATTR_HUMIDITY, ATTR_MAX_HUMIDITY, ATTR_MIN_HUMIDITY, @@ -43,6 +44,7 @@ def test_setup_params(hass: HomeAssistant) -> None: state = hass.states.get(ENTITY_DEHUMIDIFIER) assert state.state == STATE_ON assert state.attributes.get(ATTR_HUMIDITY) == 54 + assert state.attributes.get(ATTR_CURRENT_HUMIDITY) == 59 def test_default_setup_params(hass: HomeAssistant) -> None: