mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Add EntityFeature enum to Humidifier (#69092)
This commit is contained in:
parent
325a260cfd
commit
02dbd617b9
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.humidifier import HumidifierDeviceClass, HumidifierEntity
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -71,7 +71,7 @@ class DemoHumidifier(HumidifierEntity):
|
|||||||
self._attr_supported_features = SUPPORT_FLAGS
|
self._attr_supported_features = SUPPORT_FLAGS
|
||||||
if mode is not None:
|
if mode is not None:
|
||||||
self._attr_supported_features = (
|
self._attr_supported_features = (
|
||||||
self._attr_supported_features | SUPPORT_MODES
|
self._attr_supported_features | HumidifierEntityFeature.MODES
|
||||||
)
|
)
|
||||||
self._attr_target_humidity = target_humidity
|
self._attr_target_humidity = target_humidity
|
||||||
self._attr_mode = mode
|
self._attr_mode = mode
|
||||||
|
@ -41,6 +41,7 @@ from .const import ( # noqa: F401
|
|||||||
SERVICE_SET_HUMIDITY,
|
SERVICE_SET_HUMIDITY,
|
||||||
SERVICE_SET_MODE,
|
SERVICE_SET_MODE,
|
||||||
SUPPORT_MODES,
|
SUPPORT_MODES,
|
||||||
|
HumidifierEntityFeature,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -88,7 +89,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
SERVICE_SET_MODE,
|
SERVICE_SET_MODE,
|
||||||
{vol.Required(ATTR_MODE): cv.string},
|
{vol.Required(ATTR_MODE): cv.string},
|
||||||
"async_set_mode",
|
"async_set_mode",
|
||||||
[SUPPORT_MODES],
|
[HumidifierEntityFeature.MODES],
|
||||||
)
|
)
|
||||||
component.async_register_entity_service(
|
component.async_register_entity_service(
|
||||||
SERVICE_SET_HUMIDITY,
|
SERVICE_SET_HUMIDITY,
|
||||||
@ -142,7 +143,7 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
ATTR_MAX_HUMIDITY: self.max_humidity,
|
ATTR_MAX_HUMIDITY: self.max_humidity,
|
||||||
}
|
}
|
||||||
|
|
||||||
if supported_features & SUPPORT_MODES:
|
if supported_features & HumidifierEntityFeature.MODES:
|
||||||
data[ATTR_AVAILABLE_MODES] = self.available_modes
|
data[ATTR_AVAILABLE_MODES] = self.available_modes
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -166,7 +167,7 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
if self.target_humidity is not None:
|
if self.target_humidity is not None:
|
||||||
data[ATTR_HUMIDITY] = self.target_humidity
|
data[ATTR_HUMIDITY] = self.target_humidity
|
||||||
|
|
||||||
if supported_features & SUPPORT_MODES:
|
if supported_features & HumidifierEntityFeature.MODES:
|
||||||
data[ATTR_MODE] = self.mode
|
data[ATTR_MODE] = self.mode
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -180,7 +181,7 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
def mode(self) -> str | None:
|
def mode(self) -> str | None:
|
||||||
"""Return the current mode, e.g., home, auto, baby.
|
"""Return the current mode, e.g., home, auto, baby.
|
||||||
|
|
||||||
Requires SUPPORT_MODES.
|
Requires HumidifierEntityFeature.MODES.
|
||||||
"""
|
"""
|
||||||
return self._attr_mode
|
return self._attr_mode
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ class HumidifierEntity(ToggleEntity):
|
|||||||
def available_modes(self) -> list[str] | None:
|
def available_modes(self) -> list[str] | None:
|
||||||
"""Return a list of available modes.
|
"""Return a list of available modes.
|
||||||
|
|
||||||
Requires SUPPORT_MODES.
|
Requires HumidifierEntityFeature.MODES.
|
||||||
"""
|
"""
|
||||||
return self._attr_available_modes
|
return self._attr_available_modes
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Provides the constants needed for component."""
|
"""Provides the constants needed for component."""
|
||||||
|
from enum import IntEnum
|
||||||
|
|
||||||
MODE_NORMAL = "normal"
|
MODE_NORMAL = "normal"
|
||||||
MODE_ECO = "eco"
|
MODE_ECO = "eco"
|
||||||
MODE_AWAY = "away"
|
MODE_AWAY = "away"
|
||||||
@ -27,4 +29,13 @@ DEVICE_CLASS_DEHUMIDIFIER = "dehumidifier"
|
|||||||
SERVICE_SET_MODE = "set_mode"
|
SERVICE_SET_MODE = "set_mode"
|
||||||
SERVICE_SET_HUMIDITY = "set_humidity"
|
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
|
SUPPORT_MODES = 1
|
||||||
|
@ -66,7 +66,7 @@ async def async_get_actions(
|
|||||||
}
|
}
|
||||||
actions.append({**base_action, CONF_TYPE: "set_humidity"})
|
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"})
|
actions.append({**base_action, CONF_TYPE: "set_mode"})
|
||||||
|
|
||||||
return actions
|
return actions
|
||||||
|
@ -51,7 +51,7 @@ async def async_get_conditions(
|
|||||||
|
|
||||||
supported_features = get_supported_features(hass, entry.entity_id)
|
supported_features = get_supported_features(hass, entry.entity_id)
|
||||||
|
|
||||||
if supported_features & const.SUPPORT_MODES:
|
if supported_features & const.HumidifierEntityFeature.MODES:
|
||||||
conditions.append(
|
conditions.append(
|
||||||
{
|
{
|
||||||
CONF_CONDITION: "device",
|
CONF_CONDITION: "device",
|
||||||
|
@ -13,7 +13,7 @@ from . import (
|
|||||||
SERVICE_SET_HUMIDITY,
|
SERVICE_SET_HUMIDITY,
|
||||||
SERVICE_SET_MODE,
|
SERVICE_SET_MODE,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
SUPPORT_MODES,
|
HumidifierEntityFeature,
|
||||||
)
|
)
|
||||||
|
|
||||||
INTENT_HUMIDITY = "HassHumidifierSetpoint"
|
INTENT_HUMIDITY = "HassHumidifierSetpoint"
|
||||||
@ -90,7 +90,7 @@ class SetModeHandler(intent.IntentHandler):
|
|||||||
|
|
||||||
service_data = {ATTR_ENTITY_ID: state.entity_id}
|
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"]
|
mode = slots["mode"]["value"]
|
||||||
|
|
||||||
if mode not in state.attributes.get(ATTR_AVAILABLE_MODES, []):
|
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",
|
"set_state,features_reg,features_state,expected_action_types",
|
||||||
[
|
[
|
||||||
(False, 0, 0, []),
|
(False, 0, 0, []),
|
||||||
(False, const.SUPPORT_MODES, 0, ["set_mode"]),
|
(False, const.HumidifierEntityFeature.MODES, 0, ["set_mode"]),
|
||||||
(True, 0, 0, []),
|
(True, 0, 0, []),
|
||||||
(True, 0, const.SUPPORT_MODES, ["set_mode"]),
|
(True, 0, const.HumidifierEntityFeature.MODES, ["set_mode"]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_get_actions(
|
async def test_get_actions(
|
||||||
|
@ -42,9 +42,9 @@ def calls(hass):
|
|||||||
"set_state,features_reg,features_state,expected_condition_types",
|
"set_state,features_reg,features_state,expected_condition_types",
|
||||||
[
|
[
|
||||||
(False, 0, 0, []),
|
(False, 0, 0, []),
|
||||||
(False, const.SUPPORT_MODES, 0, ["is_mode"]),
|
(False, const.HumidifierEntityFeature.MODES, 0, ["is_mode"]),
|
||||||
(True, 0, 0, []),
|
(True, 0, 0, []),
|
||||||
(True, 0, const.SUPPORT_MODES, ["is_mode"]),
|
(True, 0, const.HumidifierEntityFeature.MODES, ["is_mode"]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_get_conditions(
|
async def test_get_conditions(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user