Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/demo/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ async def async_setup_entry(
DemoHumidifier(
name="Humidifier",
mode=None,
target_humidity=68,
target_humidity=65,
current_humidity=45,
action=HumidifierAction.HUMIDIFYING,
device_class=HumidifierDeviceClass.HUMIDIFIER,
target_humidity_step=5,
),
DemoHumidifier(
name="Dehumidifier",
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(
is_on: bool = True,
action: HumidifierAction | None = None,
device_class: HumidifierDeviceClass | None = None,
target_humidity_step: float | None = None,
) -> None:
"""Initialize the humidifier device."""
self._attr_name = name
Expand All @@ -79,6 +81,7 @@ def __init__(
self._attr_mode = mode
self._attr_available_modes = available_modes
self._attr_device_class = device_class
self._attr_target_humidity_step = target_humidity_step

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
Expand Down
17 changes: 16 additions & 1 deletion homeassistant/components/humidifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ATTR_HUMIDITY,
ATTR_MAX_HUMIDITY,
ATTR_MIN_HUMIDITY,
ATTR_TARGET_HUMIDITY_STEP,
DEFAULT_MAX_HUMIDITY,
DEFAULT_MIN_HUMIDITY,
DOMAIN,
Expand Down Expand Up @@ -141,14 +142,20 @@ class HumidifierEntityDescription(ToggleEntityDescription, frozen_or_thawed=True
"min_humidity",
"max_humidity",
"supported_features",
"target_humidity_step",
}


class HumidifierEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
"""Base class for humidifier entities."""

_entity_component_unrecorded_attributes = frozenset(
{ATTR_MIN_HUMIDITY, ATTR_MAX_HUMIDITY, ATTR_AVAILABLE_MODES}
{
ATTR_MIN_HUMIDITY,
ATTR_MAX_HUMIDITY,
ATTR_AVAILABLE_MODES,
ATTR_TARGET_HUMIDITY_STEP,
}
)

entity_description: HumidifierEntityDescription
Expand All @@ -161,6 +168,7 @@ class HumidifierEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_AT
_attr_mode: str | None
_attr_supported_features: HumidifierEntityFeature = HumidifierEntityFeature(0)
_attr_target_humidity: float | None = None
_attr_target_humidity_step: float | None = None

@property
def capability_attributes(self) -> dict[str, Any]:
Expand All @@ -169,6 +177,8 @@ def capability_attributes(self) -> dict[str, Any]:
ATTR_MIN_HUMIDITY: self.min_humidity,
ATTR_MAX_HUMIDITY: self.max_humidity,
}
if target_humidity_step := self.target_humidity_step:
data[ATTR_TARGET_HUMIDITY_STEP] = target_humidity_step

if HumidifierEntityFeature.MODES in self.supported_features:
data[ATTR_AVAILABLE_MODES] = self.available_modes
Expand Down Expand Up @@ -251,6 +261,11 @@ async def async_set_mode(self, mode: str) -> None:
"""Set new mode."""
await self.hass.async_add_executor_job(self.set_mode, mode)

@cached_property
def target_humidity_step(self) -> float | None:
"""Return the supported step of humidity."""
return self._attr_target_humidity_step

@cached_property
def min_humidity(self) -> float:
"""Return the minimum humidity."""
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/humidifier/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HumidifierAction(StrEnum):
ATTR_HUMIDITY = "humidity"
ATTR_MAX_HUMIDITY = "max_humidity"
ATTR_MIN_HUMIDITY = "min_humidity"
ATTR_TARGET_HUMIDITY_STEP = "target_humidity_step"

DEFAULT_MIN_HUMIDITY = 0
DEFAULT_MAX_HUMIDITY = 100
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_assistant/test_google_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ async def test_query_humidifier_request(
assert devices["humidifier.humidifier"] == {
"on": True,
"online": True,
"humiditySetpointPercent": 68,
"humiditySetpointPercent": 65,
"humidityAmbientPercent": 45,
}
assert devices["humidifier.dehumidifier"] == {
Expand Down
Loading