Humidifier current humidity (#94874)
parent
2be5bab5e1
commit
185aaa9e07
|
@ -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
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
"available_modes": {
|
||||
"name": "Available modes"
|
||||
},
|
||||
"current_humidity": {
|
||||
"name": "Current humidity"
|
||||
},
|
||||
"humidity": {
|
||||
"name": "Target humidity"
|
||||
},
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue