Add EntityFeature enum to Humidifier (#69092)
parent
325a260cfd
commit
02dbd617b9
|
@ -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
|
||||
|
@ -71,7 +71,7 @@ class DemoHumidifier(HumidifierEntity):
|
|||
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
|
||||
|
|
|
@ -41,6 +41,7 @@ from .const import ( # noqa: F401
|
|||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_SET_MODE,
|
||||
SUPPORT_MODES,
|
||||
HumidifierEntityFeature,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -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,
|
||||
|
@ -142,7 +143,7 @@ class HumidifierEntity(ToggleEntity):
|
|||
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
|
||||
|
@ -166,7 +167,7 @@ class HumidifierEntity(ToggleEntity):
|
|||
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
|
||||
|
@ -180,7 +181,7 @@ class HumidifierEntity(ToggleEntity):
|
|||
def mode(self) -> str | None:
|
||||
"""Return the current mode, e.g., home, auto, baby.
|
||||
|
||||
Requires SUPPORT_MODES.
|
||||
Requires HumidifierEntityFeature.MODES.
|
||||
"""
|
||||
return self._attr_mode
|
||||
|
||||
|
@ -188,7 +189,7 @@ class HumidifierEntity(ToggleEntity):
|
|||
def available_modes(self) -> list[str] | None:
|
||||
"""Return a list of available modes.
|
||||
|
||||
Requires SUPPORT_MODES.
|
||||
Requires HumidifierEntityFeature.MODES.
|
||||
"""
|
||||
return self._attr_available_modes
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Provides the constants needed for component."""
|
||||
from enum import IntEnum
|
||||
|
||||
MODE_NORMAL = "normal"
|
||||
MODE_ECO = "eco"
|
||||
MODE_AWAY = "away"
|
||||
|
@ -27,4 +29,13 @@ DEVICE_CLASS_DEHUMIDIFIER = "dehumidifier"
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -13,7 +13,7 @@ from . import (
|
|||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_SET_MODE,
|
||||
SERVICE_TURN_ON,
|
||||
SUPPORT_MODES,
|
||||
HumidifierEntityFeature,
|
||||
)
|
||||
|
||||
INTENT_HUMIDITY = "HassHumidifierSetpoint"
|
||||
|
@ -90,7 +90,7 @@ class SetModeHandler(intent.IntentHandler):
|
|||
|
||||
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, []):
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue