mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
Replace Climate CURRENT_HVAC_* constants with HVACAction enum (#70319)
This commit is contained in:
parent
9e213caefc
commit
bfc82b030f
@ -75,6 +75,7 @@ from .const import ( # noqa: F401
|
|||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ class ClimateEntity(Entity):
|
|||||||
_attr_current_temperature: float | None = None
|
_attr_current_temperature: float | None = None
|
||||||
_attr_fan_mode: str | None
|
_attr_fan_mode: str | None
|
||||||
_attr_fan_modes: list[str] | None
|
_attr_fan_modes: list[str] | None
|
||||||
_attr_hvac_action: str | None = None
|
_attr_hvac_action: HVACAction | str | None = None
|
||||||
_attr_hvac_mode: HVACMode | str | None
|
_attr_hvac_mode: HVACMode | str | None
|
||||||
_attr_hvac_modes: list[HVACMode | str]
|
_attr_hvac_modes: list[HVACMode | str]
|
||||||
_attr_is_aux_heat: bool | None
|
_attr_is_aux_heat: bool | None
|
||||||
@ -345,11 +346,8 @@ class ClimateEntity(Entity):
|
|||||||
return self._attr_hvac_modes
|
return self._attr_hvac_modes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str | None:
|
def hvac_action(self) -> HVACAction | str | None:
|
||||||
"""Return the current running hvac operation if supported.
|
"""Return the current running hvac operation if supported."""
|
||||||
|
|
||||||
Need to be one of CURRENT_HVAC_*.
|
|
||||||
"""
|
|
||||||
return self._attr_hvac_action
|
return self._attr_hvac_action
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -87,24 +87,26 @@ SWING_VERTICAL = "vertical"
|
|||||||
SWING_HORIZONTAL = "horizontal"
|
SWING_HORIZONTAL = "horizontal"
|
||||||
|
|
||||||
|
|
||||||
# This are support current states of HVAC
|
class HVACAction(StrEnum):
|
||||||
|
"""HVAC action for climate devices."""
|
||||||
|
|
||||||
|
COOLING = "cooling"
|
||||||
|
DRYING = "drying"
|
||||||
|
FAN = "fan"
|
||||||
|
HEATING = "heating"
|
||||||
|
IDLE = "idle"
|
||||||
|
OFF = "off"
|
||||||
|
|
||||||
|
|
||||||
|
# These CURRENT_HVAC_* constants are deprecated as of Home Assistant 2022.5.
|
||||||
|
# Please use the HVACAction enum instead.
|
||||||
CURRENT_HVAC_OFF = "off"
|
CURRENT_HVAC_OFF = "off"
|
||||||
CURRENT_HVAC_HEAT = "heating"
|
CURRENT_HVAC_HEAT = "heating"
|
||||||
CURRENT_HVAC_COOL = "cooling"
|
CURRENT_HVAC_COOL = "cooling"
|
||||||
CURRENT_HVAC_DRY = "drying"
|
CURRENT_HVAC_DRY = "drying"
|
||||||
CURRENT_HVAC_IDLE = "idle"
|
CURRENT_HVAC_IDLE = "idle"
|
||||||
CURRENT_HVAC_FAN = "fan"
|
CURRENT_HVAC_FAN = "fan"
|
||||||
|
CURRENT_HVAC_ACTIONS = [cls.value for cls in HVACAction]
|
||||||
|
|
||||||
# A list of possible HVAC actions.
|
|
||||||
CURRENT_HVAC_ACTIONS = [
|
|
||||||
CURRENT_HVAC_OFF,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_DRY,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
CURRENT_HVAC_FAN,
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
ATTR_AUX_HEAT = "aux_heat"
|
ATTR_AUX_HEAT = "aux_heat"
|
||||||
|
@ -5,9 +5,8 @@ from homeassistant.components.climate import ClimateEntity
|
|||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -43,7 +42,7 @@ async def async_setup_platform(
|
|||||||
current_humidity=None,
|
current_humidity=None,
|
||||||
swing_mode=None,
|
swing_mode=None,
|
||||||
hvac_mode=HVACMode.HEAT,
|
hvac_mode=HVACMode.HEAT,
|
||||||
hvac_action=CURRENT_HVAC_HEAT,
|
hvac_action=HVACAction.HEATING,
|
||||||
aux=None,
|
aux=None,
|
||||||
target_temp_high=None,
|
target_temp_high=None,
|
||||||
target_temp_low=None,
|
target_temp_low=None,
|
||||||
@ -61,7 +60,7 @@ async def async_setup_platform(
|
|||||||
current_humidity=54,
|
current_humidity=54,
|
||||||
swing_mode="Off",
|
swing_mode="Off",
|
||||||
hvac_mode=HVACMode.COOL,
|
hvac_mode=HVACMode.COOL,
|
||||||
hvac_action=CURRENT_HVAC_COOL,
|
hvac_action=HVACAction.COOLING,
|
||||||
aux=False,
|
aux=False,
|
||||||
target_temp_high=None,
|
target_temp_high=None,
|
||||||
target_temp_low=None,
|
target_temp_low=None,
|
||||||
|
@ -52,7 +52,7 @@ async def test_get_triggers(hass, device_reg, entity_reg):
|
|||||||
entity_id,
|
entity_id,
|
||||||
const.HVAC_MODE_COOL,
|
const.HVAC_MODE_COOL,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: const.CURRENT_HVAC_IDLE,
|
const.ATTR_HVAC_ACTION: const.HVACAction.IDLE,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 23,
|
const.ATTR_CURRENT_HUMIDITY: 23,
|
||||||
const.ATTR_CURRENT_TEMPERATURE: 18,
|
const.ATTR_CURRENT_TEMPERATURE: 18,
|
||||||
},
|
},
|
||||||
@ -92,7 +92,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_COOL,
|
const.HVAC_MODE_COOL,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: const.CURRENT_HVAC_IDLE,
|
const.ATTR_HVAC_ACTION: const.HVACAction.IDLE,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 23,
|
const.ATTR_CURRENT_HUMIDITY: 23,
|
||||||
const.ATTR_CURRENT_TEMPERATURE: 18,
|
const.ATTR_CURRENT_TEMPERATURE: 18,
|
||||||
},
|
},
|
||||||
@ -154,7 +154,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_AUTO,
|
const.HVAC_MODE_AUTO,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: const.CURRENT_HVAC_COOL,
|
const.ATTR_HVAC_ACTION: const.HVACAction.COOLING,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 23,
|
const.ATTR_CURRENT_HUMIDITY: 23,
|
||||||
const.ATTR_CURRENT_TEMPERATURE: 18,
|
const.ATTR_CURRENT_TEMPERATURE: 18,
|
||||||
},
|
},
|
||||||
@ -168,7 +168,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_AUTO,
|
const.HVAC_MODE_AUTO,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: const.CURRENT_HVAC_COOL,
|
const.ATTR_HVAC_ACTION: const.HVACAction.COOLING,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 23,
|
const.ATTR_CURRENT_HUMIDITY: 23,
|
||||||
const.ATTR_CURRENT_TEMPERATURE: 23,
|
const.ATTR_CURRENT_TEMPERATURE: 23,
|
||||||
},
|
},
|
||||||
@ -182,7 +182,7 @@ async def test_if_fires_on_state_change(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_AUTO,
|
const.HVAC_MODE_AUTO,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: const.CURRENT_HVAC_COOL,
|
const.ATTR_HVAC_ACTION: const.HVACAction.COOLING,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 7,
|
const.ATTR_CURRENT_HUMIDITY: 7,
|
||||||
const.ATTR_CURRENT_TEMPERATURE: 23,
|
const.ATTR_CURRENT_TEMPERATURE: 23,
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,6 @@ from homeassistant.components.climate.const import (
|
|||||||
ATTR_SWING_MODE,
|
ATTR_SWING_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_ECO,
|
PRESET_ECO,
|
||||||
@ -31,6 +30,7 @@ from homeassistant.components.climate.const import (
|
|||||||
SERVICE_SET_PRESET_MODE,
|
SERVICE_SET_PRESET_MODE,
|
||||||
SERVICE_SET_SWING_MODE,
|
SERVICE_SET_SWING_MODE,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
HVACAction,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -290,7 +290,7 @@ async def test_set_hvac_bad_attr_and_state(hass):
|
|||||||
Also check the state.
|
Also check the state.
|
||||||
"""
|
"""
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_COOL
|
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.COOLING
|
||||||
assert state.state == HVACMode.COOL
|
assert state.state == HVACMode.COOL
|
||||||
|
|
||||||
with pytest.raises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
@ -302,7 +302,7 @@ async def test_set_hvac_bad_attr_and_state(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_COOL
|
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.COOLING
|
||||||
assert state.state == HVACMode.COOL
|
assert state.state == HVACMode.COOL
|
||||||
|
|
||||||
|
|
||||||
|
@ -1161,7 +1161,7 @@ async def test_get_with_templates(hass, mqtt_mock, caplog):
|
|||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get("hvac_action") == "cooling"
|
assert state.attributes.get("hvac_action") == "cooling"
|
||||||
assert (
|
assert (
|
||||||
"Invalid ['off', 'heating', 'cooling', 'drying', 'idle', 'fan'] action: None, ignoring"
|
"Invalid ['cooling', 'drying', 'fan', 'heating', 'idle', 'off'] action: None, ignoring"
|
||||||
in caplog.text
|
in caplog.text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user