mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Use climate enums in atag (#70623)
This commit is contained in:
parent
59b7318db4
commit
9f428f268c
@ -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:
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user