Replace Climate CURRENT_HVAC_* constants with HVACAction enum (#70319)

pull/70342/head
Franck Nijhof 2022-04-20 22:41:05 +02:00 committed by GitHub
parent 9e213caefc
commit bfc82b030f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 31 deletions

View File

@ -75,6 +75,7 @@ from .const import ( # noqa: F401
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
@ -188,7 +189,7 @@ class ClimateEntity(Entity):
_attr_current_temperature: float | None = None
_attr_fan_mode: 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_modes: list[HVACMode | str]
_attr_is_aux_heat: bool | None
@ -345,11 +346,8 @@ class ClimateEntity(Entity):
return self._attr_hvac_modes
@property
def hvac_action(self) -> str | None:
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
def hvac_action(self) -> HVACAction | str | None:
"""Return the current running hvac operation if supported."""
return self._attr_hvac_action
@property

View File

@ -87,24 +87,26 @@ SWING_VERTICAL = "vertical"
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_HEAT = "heating"
CURRENT_HVAC_COOL = "cooling"
CURRENT_HVAC_DRY = "drying"
CURRENT_HVAC_IDLE = "idle"
CURRENT_HVAC_FAN = "fan"
# 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,
]
CURRENT_HVAC_ACTIONS = [cls.value for cls in HVACAction]
ATTR_AUX_HEAT = "aux_heat"

View File

@ -5,9 +5,8 @@ from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
@ -43,7 +42,7 @@ async def async_setup_platform(
current_humidity=None,
swing_mode=None,
hvac_mode=HVACMode.HEAT,
hvac_action=CURRENT_HVAC_HEAT,
hvac_action=HVACAction.HEATING,
aux=None,
target_temp_high=None,
target_temp_low=None,
@ -61,7 +60,7 @@ async def async_setup_platform(
current_humidity=54,
swing_mode="Off",
hvac_mode=HVACMode.COOL,
hvac_action=CURRENT_HVAC_COOL,
hvac_action=HVACAction.COOLING,
aux=False,
target_temp_high=None,
target_temp_low=None,

View File

@ -52,7 +52,7 @@ async def test_get_triggers(hass, device_reg, entity_reg):
entity_id,
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_TEMPERATURE: 18,
},
@ -92,7 +92,7 @@ async def test_if_fires_on_state_change(hass, calls):
"climate.entity",
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_TEMPERATURE: 18,
},
@ -154,7 +154,7 @@ async def test_if_fires_on_state_change(hass, calls):
"climate.entity",
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_TEMPERATURE: 18,
},
@ -168,7 +168,7 @@ async def test_if_fires_on_state_change(hass, calls):
"climate.entity",
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_TEMPERATURE: 23,
},
@ -182,7 +182,7 @@ async def test_if_fires_on_state_change(hass, calls):
"climate.entity",
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_TEMPERATURE: 23,
},

View File

@ -20,7 +20,6 @@ from homeassistant.components.climate.const import (
ATTR_SWING_MODE,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL,
DOMAIN,
PRESET_AWAY,
PRESET_ECO,
@ -31,6 +30,7 @@ from homeassistant.components.climate.const import (
SERVICE_SET_PRESET_MODE,
SERVICE_SET_SWING_MODE,
SERVICE_SET_TEMPERATURE,
HVACAction,
HVACMode,
)
from homeassistant.const import (
@ -290,7 +290,7 @@ async def test_set_hvac_bad_attr_and_state(hass):
Also check the state.
"""
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
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)
assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_COOL
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.COOLING
assert state.state == HVACMode.COOL

View File

@ -1161,7 +1161,7 @@ async def test_get_with_templates(hass, mqtt_mock, caplog):
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hvac_action") == "cooling"
assert (
"Invalid ['off', 'heating', 'cooling', 'drying', 'idle', 'fan'] action: None, ignoring"
"Invalid ['cooling', 'drying', 'fan', 'heating', 'idle', 'off'] action: None, ignoring"
in caplog.text
)