From 9f428f268c38a0b14e785ddf69669b44d12a593b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 26 Apr 2022 09:59:31 +0200 Subject: [PATCH] Use climate enums in atag (#70623) --- homeassistant/components/atag/climate.py | 13 ++++++------- tests/components/atag/test_climate.py | 11 +++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/atag/climate.py b/homeassistant/components/atag/climate.py index ca1681b4160..cf5624005ed 100644 --- a/homeassistant/components/atag/climate.py +++ b/homeassistant/components/atag/climate.py @@ -1,14 +1,13 @@ """Initialization of ATAG One climate platform.""" from __future__ import annotations -from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature +from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, - CURRENT_HVAC_IDLE, - HVAC_MODE_AUTO, - HVAC_MODE_HEAT, PRESET_AWAY, PRESET_BOOST, + ClimateEntityFeature, + HVACAction, + HVACMode, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, Platform @@ -25,7 +24,7 @@ PRESET_MAP = { PRESET_BOOST: "fireplace", } PRESET_INVERTED = {v: k for k, v in PRESET_MAP.items()} -HVAC_MODES = [HVAC_MODE_AUTO, HVAC_MODE_HEAT] +HVAC_MODES = [HVACMode.AUTO, HVACMode.HEAT] async def async_setup_entry( @@ -61,7 +60,7 @@ class AtagThermostat(AtagEntity, ClimateEntity): def hvac_action(self) -> str | None: """Return the current running hvac operation.""" is_active = self.coordinator.data.climate.status - return CURRENT_HVAC_HEAT if is_active else CURRENT_HVAC_IDLE + return HVACAction.HEATING if is_active else HVACAction.IDLE @property def current_temperature(self) -> float | None: diff --git a/tests/components/atag/test_climate.py b/tests/components/atag/test_climate.py index 8fb7730a4e4..115eb4035df 100644 --- a/tests/components/atag/test_climate.py +++ b/tests/components/atag/test_climate.py @@ -7,12 +7,11 @@ from homeassistant.components.climate import ( ATTR_HVAC_MODE, ATTR_PRESET_MODE, DOMAIN as CLIMATE_DOMAIN, - HVAC_MODE_HEAT, SERVICE_SET_HVAC_MODE, SERVICE_SET_PRESET_MODE, SERVICE_SET_TEMPERATURE, ) -from homeassistant.components.climate.const import CURRENT_HVAC_IDLE, PRESET_AWAY +from homeassistant.components.climate.const import PRESET_AWAY, HVACAction, HVACMode from homeassistant.components.homeassistant import DOMAIN as HA_DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, @@ -40,7 +39,7 @@ async def test_climate( assert entity_registry.async_is_registered(CLIMATE_ID) entity = entity_registry.async_get(CLIMATE_ID) assert entity.unique_id == f"{UID}-{Platform.CLIMATE}" - assert hass.states.get(CLIMATE_ID).attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE + assert hass.states.get(CLIMATE_ID).attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE async def test_setting_climate( @@ -72,11 +71,11 @@ async def test_setting_climate( await hass.services.async_call( CLIMATE_DOMAIN, SERVICE_SET_HVAC_MODE, - {ATTR_ENTITY_ID: CLIMATE_ID, ATTR_HVAC_MODE: HVAC_MODE_HEAT}, + {ATTR_ENTITY_ID: CLIMATE_ID, ATTR_HVAC_MODE: HVACMode.HEAT}, blocking=True, ) await hass.async_block_till_done() - mock_set_hvac.assert_called_once_with(HVAC_MODE_HEAT) + mock_set_hvac.assert_called_once_with(HVACMode.HEAT) async def test_incorrect_modes( @@ -99,7 +98,7 @@ async def test_update_failed( """Test data is not destroyed on update failure.""" entry = await init_integration(hass, aioclient_mock) await async_setup_component(hass, HA_DOMAIN, {}) - assert hass.states.get(CLIMATE_ID).state == HVAC_MODE_HEAT + assert hass.states.get(CLIMATE_ID).state == HVACMode.HEAT coordinator = hass.data[DOMAIN][entry.entry_id] with patch("pyatag.AtagOne.update", side_effect=TimeoutError) as updater: await coordinator.async_refresh()