Skip to content
Merged
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
4 changes: 2 additions & 2 deletions homeassistant/components/demo/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from homeassistant.components.humidifier import HumidifierDeviceClass, HumidifierEntity
from homeassistant.components.humidifier.const import SUPPORT_MODES
from homeassistant.components.humidifier.const import HumidifierEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
self._attr_supported_features = SUPPORT_FLAGS
if mode is not None:
self._attr_supported_features = (
self._attr_supported_features | SUPPORT_MODES
self._attr_supported_features | HumidifierEntityFeature.MODES
)
self._attr_target_humidity = target_humidity
self._attr_mode = mode
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/humidifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
SERVICE_SET_HUMIDITY,
SERVICE_SET_MODE,
SUPPORT_MODES,
HumidifierEntityFeature,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -88,7 +89,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
SERVICE_SET_MODE,
{vol.Required(ATTR_MODE): cv.string},
"async_set_mode",
[SUPPORT_MODES],
[HumidifierEntityFeature.MODES],
)
component.async_register_entity_service(
SERVICE_SET_HUMIDITY,
Expand Down Expand Up @@ -142,7 +143,7 @@ def capability_attributes(self) -> dict[str, Any]:
ATTR_MAX_HUMIDITY: self.max_humidity,
}

if supported_features & SUPPORT_MODES:
if supported_features & HumidifierEntityFeature.MODES:
data[ATTR_AVAILABLE_MODES] = self.available_modes

return data
Expand All @@ -166,7 +167,7 @@ def state_attributes(self) -> dict[str, Any]:
if self.target_humidity is not None:
data[ATTR_HUMIDITY] = self.target_humidity

if supported_features & SUPPORT_MODES:
if supported_features & HumidifierEntityFeature.MODES:
data[ATTR_MODE] = self.mode

return data
Expand All @@ -180,15 +181,15 @@ def target_humidity(self) -> int | None:
def mode(self) -> str | None:
"""Return the current mode, e.g., home, auto, baby.

Requires SUPPORT_MODES.
Requires HumidifierEntityFeature.MODES.
"""
return self._attr_mode

@property
def available_modes(self) -> list[str] | None:
"""Return a list of available modes.

Requires SUPPORT_MODES.
Requires HumidifierEntityFeature.MODES.
"""
return self._attr_available_modes

Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/humidifier/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Provides the constants needed for component."""
from enum import IntEnum

MODE_NORMAL = "normal"
MODE_ECO = "eco"
MODE_AWAY = "away"
Expand Down Expand Up @@ -27,4 +29,13 @@
SERVICE_SET_MODE = "set_mode"
SERVICE_SET_HUMIDITY = "set_humidity"


class HumidifierEntityFeature(IntEnum):
"""Supported features of the alarm control panel entity."""

MODES = 1


# The SUPPORT_MODES constant is deprecated as of Home Assistant 2022.5.
# Please use the HumidifierEntityFeature enum instead.
SUPPORT_MODES = 1
2 changes: 1 addition & 1 deletion homeassistant/components/humidifier/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def async_get_actions(
}
actions.append({**base_action, CONF_TYPE: "set_humidity"})

if supported_features & const.SUPPORT_MODES:
if supported_features & const.HumidifierEntityFeature.MODES:
actions.append({**base_action, CONF_TYPE: "set_mode"})

return actions
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/humidifier/device_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def async_get_conditions(

supported_features = get_supported_features(hass, entry.entity_id)

if supported_features & const.SUPPORT_MODES:
if supported_features & const.HumidifierEntityFeature.MODES:
conditions.append(
{
CONF_CONDITION: "device",
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/humidifier/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SERVICE_SET_HUMIDITY,
SERVICE_SET_MODE,
SERVICE_TURN_ON,
SUPPORT_MODES,
HumidifierEntityFeature,
)

INTENT_HUMIDITY = "HassHumidifierSetpoint"
Expand Down Expand Up @@ -90,7 +90,7 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse

service_data = {ATTR_ENTITY_ID: state.entity_id}

intent.async_test_feature(state, SUPPORT_MODES, "modes")
intent.async_test_feature(state, HumidifierEntityFeature.MODES, "modes")
mode = slots["mode"]["value"]

if mode not in state.attributes.get(ATTR_AVAILABLE_MODES, []):
Expand Down
4 changes: 2 additions & 2 deletions tests/components/humidifier/test_device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def entity_reg(hass):
"set_state,features_reg,features_state,expected_action_types",
[
(False, 0, 0, []),
(False, const.SUPPORT_MODES, 0, ["set_mode"]),
(False, const.HumidifierEntityFeature.MODES, 0, ["set_mode"]),
(True, 0, 0, []),
(True, 0, const.SUPPORT_MODES, ["set_mode"]),
(True, 0, const.HumidifierEntityFeature.MODES, ["set_mode"]),
],
)
async def test_get_actions(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/humidifier/test_device_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def calls(hass):
"set_state,features_reg,features_state,expected_condition_types",
[
(False, 0, 0, []),
(False, const.SUPPORT_MODES, 0, ["is_mode"]),
(False, const.HumidifierEntityFeature.MODES, 0, ["is_mode"]),
(True, 0, 0, []),
(True, 0, const.SUPPORT_MODES, ["is_mode"]),
(True, 0, const.HumidifierEntityFeature.MODES, ["is_mode"]),
],
)
async def test_get_conditions(
Expand Down