mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use climate enums in smartthings (#70737)
This commit is contained in:
parent
c534d0a90e
commit
98d757b2b2
@ -7,26 +7,14 @@ import logging
|
|||||||
|
|
||||||
from pysmartthings import Attribute, Capability
|
from pysmartthings import Attribute, Capability
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, ClimateEntity
|
||||||
DOMAIN as CLIMATE_DOMAIN,
|
|
||||||
ClimateEntity,
|
|
||||||
ClimateEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
ClimateEntityFeature,
|
||||||
CURRENT_HVAC_FAN,
|
HVACAction,
|
||||||
CURRENT_HVAC_HEAT,
|
HVACMode,
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_DRY,
|
|
||||||
HVAC_MODE_FAN_ONLY,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
@ -38,47 +26,47 @@ from .const import DATA_BROKERS, DOMAIN
|
|||||||
|
|
||||||
ATTR_OPERATION_STATE = "operation_state"
|
ATTR_OPERATION_STATE = "operation_state"
|
||||||
MODE_TO_STATE = {
|
MODE_TO_STATE = {
|
||||||
"auto": HVAC_MODE_HEAT_COOL,
|
"auto": HVACMode.HEAT_COOL,
|
||||||
"cool": HVAC_MODE_COOL,
|
"cool": HVACMode.COOL,
|
||||||
"eco": HVAC_MODE_AUTO,
|
"eco": HVACMode.AUTO,
|
||||||
"rush hour": HVAC_MODE_AUTO,
|
"rush hour": HVACMode.AUTO,
|
||||||
"emergency heat": HVAC_MODE_HEAT,
|
"emergency heat": HVACMode.HEAT,
|
||||||
"heat": HVAC_MODE_HEAT,
|
"heat": HVACMode.HEAT,
|
||||||
"off": HVAC_MODE_OFF,
|
"off": HVACMode.OFF,
|
||||||
}
|
}
|
||||||
STATE_TO_MODE = {
|
STATE_TO_MODE = {
|
||||||
HVAC_MODE_HEAT_COOL: "auto",
|
HVACMode.HEAT_COOL: "auto",
|
||||||
HVAC_MODE_COOL: "cool",
|
HVACMode.COOL: "cool",
|
||||||
HVAC_MODE_HEAT: "heat",
|
HVACMode.HEAT: "heat",
|
||||||
HVAC_MODE_OFF: "off",
|
HVACMode.OFF: "off",
|
||||||
}
|
}
|
||||||
|
|
||||||
OPERATING_STATE_TO_ACTION = {
|
OPERATING_STATE_TO_ACTION = {
|
||||||
"cooling": CURRENT_HVAC_COOL,
|
"cooling": HVACAction.COOLING,
|
||||||
"fan only": CURRENT_HVAC_FAN,
|
"fan only": HVACAction.FAN,
|
||||||
"heating": CURRENT_HVAC_HEAT,
|
"heating": HVACAction.HEATING,
|
||||||
"idle": CURRENT_HVAC_IDLE,
|
"idle": HVACAction.IDLE,
|
||||||
"pending cool": CURRENT_HVAC_COOL,
|
"pending cool": HVACAction.COOLING,
|
||||||
"pending heat": CURRENT_HVAC_HEAT,
|
"pending heat": HVACAction.HEATING,
|
||||||
"vent economizer": CURRENT_HVAC_FAN,
|
"vent economizer": HVACAction.FAN,
|
||||||
}
|
}
|
||||||
|
|
||||||
AC_MODE_TO_STATE = {
|
AC_MODE_TO_STATE = {
|
||||||
"auto": HVAC_MODE_HEAT_COOL,
|
"auto": HVACMode.HEAT_COOL,
|
||||||
"cool": HVAC_MODE_COOL,
|
"cool": HVACMode.COOL,
|
||||||
"dry": HVAC_MODE_DRY,
|
"dry": HVACMode.DRY,
|
||||||
"coolClean": HVAC_MODE_COOL,
|
"coolClean": HVACMode.COOL,
|
||||||
"dryClean": HVAC_MODE_DRY,
|
"dryClean": HVACMode.DRY,
|
||||||
"heat": HVAC_MODE_HEAT,
|
"heat": HVACMode.HEAT,
|
||||||
"heatClean": HVAC_MODE_HEAT,
|
"heatClean": HVACMode.HEAT,
|
||||||
"fanOnly": HVAC_MODE_FAN_ONLY,
|
"fanOnly": HVACMode.FAN_ONLY,
|
||||||
}
|
}
|
||||||
STATE_TO_AC_MODE = {
|
STATE_TO_AC_MODE = {
|
||||||
HVAC_MODE_HEAT_COOL: "auto",
|
HVACMode.HEAT_COOL: "auto",
|
||||||
HVAC_MODE_COOL: "cool",
|
HVACMode.COOL: "cool",
|
||||||
HVAC_MODE_DRY: "dry",
|
HVACMode.DRY: "dry",
|
||||||
HVAC_MODE_HEAT: "heat",
|
HVACMode.HEAT: "heat",
|
||||||
HVAC_MODE_FAN_ONLY: "fanOnly",
|
HVACMode.FAN_ONLY: "fanOnly",
|
||||||
}
|
}
|
||||||
|
|
||||||
UNIT_MAP = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT}
|
UNIT_MAP = {"C": TEMP_CELSIUS, "F": TEMP_FAHRENHEIT}
|
||||||
@ -183,7 +171,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
|
|||||||
# the entity state ahead of receiving the confirming push updates
|
# the entity state ahead of receiving the confirming push updates
|
||||||
self.async_schedule_update_ha_state(True)
|
self.async_schedule_update_ha_state(True)
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
mode = STATE_TO_MODE[hvac_mode]
|
mode = STATE_TO_MODE[hvac_mode]
|
||||||
await self._device.set_thermostat_mode(mode, set_status=True)
|
await self._device.set_thermostat_mode(mode, set_status=True)
|
||||||
@ -203,9 +191,9 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
|
|||||||
# Heat/cool setpoint
|
# Heat/cool setpoint
|
||||||
heating_setpoint = None
|
heating_setpoint = None
|
||||||
cooling_setpoint = None
|
cooling_setpoint = None
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
heating_setpoint = kwargs.get(ATTR_TEMPERATURE)
|
heating_setpoint = kwargs.get(ATTR_TEMPERATURE)
|
||||||
elif self.hvac_mode == HVAC_MODE_COOL:
|
elif self.hvac_mode == HVACMode.COOL:
|
||||||
cooling_setpoint = kwargs.get(ATTR_TEMPERATURE)
|
cooling_setpoint = kwargs.get(ATTR_TEMPERATURE)
|
||||||
else:
|
else:
|
||||||
heating_setpoint = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
heating_setpoint = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||||
@ -284,42 +272,42 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
|
|||||||
return self._device.status.supported_thermostat_fan_modes
|
return self._device.status.supported_thermostat_fan_modes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str | None:
|
def hvac_action(self) -> HVACAction | None:
|
||||||
"""Return the current running hvac operation if supported."""
|
"""Return the current running hvac operation if supported."""
|
||||||
return OPERATING_STATE_TO_ACTION.get(
|
return OPERATING_STATE_TO_ACTION.get(
|
||||||
self._device.status.thermostat_operating_state
|
self._device.status.thermostat_operating_state
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return current operation ie. heat, cool, idle."""
|
"""Return current operation ie. heat, cool, idle."""
|
||||||
return self._hvac_mode
|
return self._hvac_mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_modes(self) -> list[HVACMode]:
|
||||||
"""Return the list of available operation modes."""
|
"""Return the list of available operation modes."""
|
||||||
return self._hvac_modes
|
return self._hvac_modes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_COOL:
|
if self.hvac_mode == HVACMode.COOL:
|
||||||
return self._device.status.cooling_setpoint
|
return self._device.status.cooling_setpoint
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
if self.hvac_mode == HVACMode.HEAT:
|
||||||
return self._device.status.heating_setpoint
|
return self._device.status.heating_setpoint
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self):
|
def target_temperature_high(self):
|
||||||
"""Return the highbound target temperature we try to reach."""
|
"""Return the highbound target temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._device.status.cooling_setpoint
|
return self._device.status.cooling_setpoint
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self):
|
def target_temperature_low(self):
|
||||||
"""Return the lowbound target temperature we try to reach."""
|
"""Return the lowbound target temperature we try to reach."""
|
||||||
if self.hvac_mode == HVAC_MODE_HEAT_COOL:
|
if self.hvac_mode == HVACMode.HEAT_COOL:
|
||||||
return self._device.status.heating_setpoint
|
return self._device.status.heating_setpoint
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -348,9 +336,9 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||||||
# the entity state ahead of receiving the confirming push updates
|
# the entity state ahead of receiving the confirming push updates
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
await self.async_turn_off()
|
await self.async_turn_off()
|
||||||
return
|
return
|
||||||
tasks = []
|
tasks = []
|
||||||
@ -372,7 +360,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||||||
tasks = []
|
tasks = []
|
||||||
# operation mode
|
# operation mode
|
||||||
if operation_mode := kwargs.get(ATTR_HVAC_MODE):
|
if operation_mode := kwargs.get(ATTR_HVAC_MODE):
|
||||||
if operation_mode == HVAC_MODE_OFF:
|
if operation_mode == HVACMode.OFF:
|
||||||
tasks.append(self._device.switch_off(set_status=True))
|
tasks.append(self._device.switch_off(set_status=True))
|
||||||
else:
|
else:
|
||||||
if not self._device.status.switch:
|
if not self._device.status.switch:
|
||||||
@ -403,7 +391,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the calculated fields of the AC."""
|
"""Update the calculated fields of the AC."""
|
||||||
modes = {HVAC_MODE_OFF}
|
modes = {HVACMode.OFF}
|
||||||
for mode in self._device.status.supported_ac_modes:
|
for mode in self._device.status.supported_ac_modes:
|
||||||
if (state := AC_MODE_TO_STATE.get(mode)) is not None:
|
if (state := AC_MODE_TO_STATE.get(mode)) is not None:
|
||||||
modes.add(state)
|
modes.add(state)
|
||||||
@ -457,14 +445,14 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||||||
return self._device.status.supported_ac_fan_modes
|
return self._device.status.supported_ac_fan_modes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> HVACMode | None:
|
||||||
"""Return current operation ie. heat, cool, idle."""
|
"""Return current operation ie. heat, cool, idle."""
|
||||||
if not self._device.status.switch:
|
if not self._device.status.switch:
|
||||||
return HVAC_MODE_OFF
|
return HVACMode.OFF
|
||||||
return AC_MODE_TO_STATE.get(self._device.status.air_conditioner_mode)
|
return AC_MODE_TO_STATE.get(self._device.status.air_conditioner_mode)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self):
|
def hvac_modes(self) -> list[HVACMode]:
|
||||||
"""Return the list of available operation modes."""
|
"""Return the list of available operation modes."""
|
||||||
return self._hvac_modes
|
return self._hvac_modes
|
||||||
|
|
||||||
|
@ -18,21 +18,13 @@ from homeassistant.components.climate.const import (
|
|||||||
ATTR_HVAC_MODES,
|
ATTR_HVAC_MODES,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
DOMAIN as CLIMATE_DOMAIN,
|
DOMAIN as CLIMATE_DOMAIN,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_DRY,
|
|
||||||
HVAC_MODE_FAN_ONLY,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_HEAT_COOL,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
SERVICE_SET_FAN_MODE,
|
SERVICE_SET_FAN_MODE,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
SUPPORT_FAN_MODE,
|
ClimateEntityFeature,
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
HVACAction,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.components.smartthings import climate
|
from homeassistant.components.smartthings import climate
|
||||||
from homeassistant.components.smartthings.const import DOMAIN
|
from homeassistant.components.smartthings.const import DOMAIN
|
||||||
@ -203,20 +195,20 @@ async def test_legacy_thermostat_entity_state(hass, legacy_thermostat):
|
|||||||
"""Tests the state attributes properly match the thermostat type."""
|
"""Tests the state attributes properly match the thermostat type."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[legacy_thermostat])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[legacy_thermostat])
|
||||||
state = hass.states.get("climate.legacy_thermostat")
|
state = hass.states.get("climate.legacy_thermostat")
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_FAN_MODE
|
== ClimateEntityFeature.FAN_MODE
|
||||||
| SUPPORT_TARGET_TEMPERATURE_RANGE
|
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
| SUPPORT_TARGET_TEMPERATURE
|
| ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
||||||
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
||||||
HVAC_MODE_AUTO,
|
HVACMode.AUTO,
|
||||||
HVAC_MODE_COOL,
|
HVACMode.COOL,
|
||||||
HVAC_MODE_HEAT,
|
HVACMode.HEAT,
|
||||||
HVAC_MODE_HEAT_COOL,
|
HVACMode.HEAT_COOL,
|
||||||
HVAC_MODE_OFF,
|
HVACMode.OFF,
|
||||||
]
|
]
|
||||||
assert state.attributes[ATTR_FAN_MODE] == "auto"
|
assert state.attributes[ATTR_FAN_MODE] == "auto"
|
||||||
assert state.attributes[ATTR_FAN_MODES] == ["auto", "on"]
|
assert state.attributes[ATTR_FAN_MODES] == ["auto", "on"]
|
||||||
@ -229,17 +221,18 @@ async def test_basic_thermostat_entity_state(hass, basic_thermostat):
|
|||||||
"""Tests the state attributes properly match the thermostat type."""
|
"""Tests the state attributes properly match the thermostat type."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[basic_thermostat])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[basic_thermostat])
|
||||||
state = hass.states.get("climate.basic_thermostat")
|
state = hass.states.get("climate.basic_thermostat")
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_TARGET_TEMPERATURE_RANGE | SUPPORT_TARGET_TEMPERATURE
|
== ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
|
| ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
assert ATTR_HVAC_ACTION not in state.attributes
|
assert ATTR_HVAC_ACTION not in state.attributes
|
||||||
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
||||||
HVAC_MODE_COOL,
|
HVACMode.COOL,
|
||||||
HVAC_MODE_HEAT,
|
HVACMode.HEAT,
|
||||||
HVAC_MODE_HEAT_COOL,
|
HVACMode.HEAT_COOL,
|
||||||
HVAC_MODE_OFF,
|
HVACMode.OFF,
|
||||||
]
|
]
|
||||||
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 21.1 # celsius
|
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 21.1 # celsius
|
||||||
|
|
||||||
@ -248,20 +241,20 @@ async def test_thermostat_entity_state(hass, thermostat):
|
|||||||
"""Tests the state attributes properly match the thermostat type."""
|
"""Tests the state attributes properly match the thermostat type."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||||
state = hass.states.get("climate.thermostat")
|
state = hass.states.get("climate.thermostat")
|
||||||
assert state.state == HVAC_MODE_HEAT
|
assert state.state == HVACMode.HEAT
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_FAN_MODE
|
== ClimateEntityFeature.FAN_MODE
|
||||||
| SUPPORT_TARGET_TEMPERATURE_RANGE
|
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
| SUPPORT_TARGET_TEMPERATURE
|
| ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE
|
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.IDLE
|
||||||
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
||||||
HVAC_MODE_AUTO,
|
HVACMode.AUTO,
|
||||||
HVAC_MODE_COOL,
|
HVACMode.COOL,
|
||||||
HVAC_MODE_HEAT,
|
HVACMode.HEAT,
|
||||||
HVAC_MODE_HEAT_COOL,
|
HVACMode.HEAT_COOL,
|
||||||
HVAC_MODE_OFF,
|
HVACMode.OFF,
|
||||||
]
|
]
|
||||||
assert state.attributes[ATTR_FAN_MODE] == "on"
|
assert state.attributes[ATTR_FAN_MODE] == "on"
|
||||||
assert state.attributes[ATTR_FAN_MODES] == ["auto", "on"]
|
assert state.attributes[ATTR_FAN_MODES] == ["auto", "on"]
|
||||||
@ -277,7 +270,8 @@ async def test_buggy_thermostat_entity_state(hass, buggy_thermostat):
|
|||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_TARGET_TEMPERATURE_RANGE | SUPPORT_TARGET_TEMPERATURE
|
== ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
|
||||||
|
| ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
assert state.state is STATE_UNKNOWN
|
assert state.state is STATE_UNKNOWN
|
||||||
assert state.attributes[ATTR_TEMPERATURE] is None
|
assert state.attributes[ATTR_TEMPERATURE] is None
|
||||||
@ -292,25 +286,25 @@ async def test_buggy_thermostat_invalid_mode(hass, buggy_thermostat):
|
|||||||
)
|
)
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[buggy_thermostat])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[buggy_thermostat])
|
||||||
state = hass.states.get("climate.buggy_thermostat")
|
state = hass.states.get("climate.buggy_thermostat")
|
||||||
assert state.attributes[ATTR_HVAC_MODES] == [HVAC_MODE_HEAT]
|
assert state.attributes[ATTR_HVAC_MODES] == [HVACMode.HEAT]
|
||||||
|
|
||||||
|
|
||||||
async def test_air_conditioner_entity_state(hass, air_conditioner):
|
async def test_air_conditioner_entity_state(hass, air_conditioner):
|
||||||
"""Tests when an invalid operation mode is included."""
|
"""Tests when an invalid operation mode is included."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
assert (
|
assert (
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
state.attributes[ATTR_SUPPORTED_FEATURES]
|
||||||
== SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE
|
== ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
||||||
HVAC_MODE_COOL,
|
HVACMode.COOL,
|
||||||
HVAC_MODE_DRY,
|
HVACMode.DRY,
|
||||||
HVAC_MODE_FAN_ONLY,
|
HVACMode.FAN_ONLY,
|
||||||
HVAC_MODE_HEAT,
|
HVACMode.HEAT,
|
||||||
HVAC_MODE_HEAT_COOL,
|
HVACMode.HEAT_COOL,
|
||||||
HVAC_MODE_OFF,
|
HVACMode.OFF,
|
||||||
]
|
]
|
||||||
assert state.attributes[ATTR_FAN_MODE] == "medium"
|
assert state.attributes[ATTR_FAN_MODE] == "medium"
|
||||||
assert sorted(state.attributes[ATTR_FAN_MODES]) == [
|
assert sorted(state.attributes[ATTR_FAN_MODES]) == [
|
||||||
@ -354,13 +348,13 @@ async def test_set_hvac_mode(hass, thermostat, air_conditioner):
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
{ATTR_ENTITY_ID: entity_ids, ATTR_HVAC_MODE: HVAC_MODE_COOL},
|
{ATTR_ENTITY_ID: entity_ids, ATTR_HVAC_MODE: HVACMode.COOL},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
for entity_id in entity_ids:
|
for entity_id in entity_ids:
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == HVAC_MODE_COOL, entity_id
|
assert state.state == HVACMode.COOL, entity_id
|
||||||
|
|
||||||
|
|
||||||
async def test_ac_set_hvac_mode_from_off(hass, air_conditioner):
|
async def test_ac_set_hvac_mode_from_off(hass, air_conditioner):
|
||||||
@ -371,33 +365,33 @@ async def test_ac_set_hvac_mode_from_off(hass, air_conditioner):
|
|||||||
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: "climate.air_conditioner",
|
ATTR_ENTITY_ID: "climate.air_conditioner",
|
||||||
ATTR_HVAC_MODE: HVAC_MODE_HEAT_COOL,
|
ATTR_HVAC_MODE: HVACMode.HEAT_COOL,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
|
|
||||||
|
|
||||||
async def test_ac_set_hvac_mode_off(hass, air_conditioner):
|
async def test_ac_set_hvac_mode_off(hass, air_conditioner):
|
||||||
"""Test the AC HVAC mode can be turned off set successfully."""
|
"""Test the AC HVAC mode can be turned off set successfully."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state != HVAC_MODE_OFF
|
assert state.state != HVACMode.OFF
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
{ATTR_ENTITY_ID: "climate.air_conditioner", ATTR_HVAC_MODE: HVAC_MODE_OFF},
|
{ATTR_ENTITY_ID: "climate.air_conditioner", ATTR_HVAC_MODE: HVACMode.OFF},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
|
|
||||||
|
|
||||||
async def test_set_temperature_heat_mode(hass, thermostat):
|
async def test_set_temperature_heat_mode(hass, thermostat):
|
||||||
@ -411,7 +405,7 @@ async def test_set_temperature_heat_mode(hass, thermostat):
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.thermostat")
|
state = hass.states.get("climate.thermostat")
|
||||||
assert state.state == HVAC_MODE_HEAT
|
assert state.state == HVACMode.HEAT
|
||||||
assert state.attributes[ATTR_TEMPERATURE] == 21
|
assert state.attributes[ATTR_TEMPERATURE] == 21
|
||||||
assert thermostat.status.heating_setpoint == 69.8
|
assert thermostat.status.heating_setpoint == 69.8
|
||||||
|
|
||||||
@ -471,13 +465,13 @@ async def test_set_temperature_ac_with_mode(hass, air_conditioner):
|
|||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: "climate.air_conditioner",
|
ATTR_ENTITY_ID: "climate.air_conditioner",
|
||||||
ATTR_TEMPERATURE: 27,
|
ATTR_TEMPERATURE: 27,
|
||||||
ATTR_HVAC_MODE: HVAC_MODE_COOL,
|
ATTR_HVAC_MODE: HVACMode.COOL,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||||
assert state.state == HVAC_MODE_COOL
|
assert state.state == HVACMode.COOL
|
||||||
|
|
||||||
|
|
||||||
async def test_set_temperature_ac_with_mode_from_off(hass, air_conditioner):
|
async def test_set_temperature_ac_with_mode_from_off(hass, air_conditioner):
|
||||||
@ -487,39 +481,39 @@ async def test_set_temperature_ac_with_mode_from_off(hass, air_conditioner):
|
|||||||
)
|
)
|
||||||
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
assert hass.states.get("climate.air_conditioner").state == HVAC_MODE_OFF
|
assert hass.states.get("climate.air_conditioner").state == HVACMode.OFF
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: "climate.air_conditioner",
|
ATTR_ENTITY_ID: "climate.air_conditioner",
|
||||||
ATTR_TEMPERATURE: 27,
|
ATTR_TEMPERATURE: 27,
|
||||||
ATTR_HVAC_MODE: HVAC_MODE_COOL,
|
ATTR_HVAC_MODE: HVACMode.COOL,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||||
assert state.state == HVAC_MODE_COOL
|
assert state.state == HVACMode.COOL
|
||||||
|
|
||||||
|
|
||||||
async def test_set_temperature_ac_with_mode_to_off(hass, air_conditioner):
|
async def test_set_temperature_ac_with_mode_to_off(hass, air_conditioner):
|
||||||
"""Test the temp and mode is set successfully to turn off the unit."""
|
"""Test the temp and mode is set successfully to turn off the unit."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
assert hass.states.get("climate.air_conditioner").state != HVAC_MODE_OFF
|
assert hass.states.get("climate.air_conditioner").state != HVACMode.OFF
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: "climate.air_conditioner",
|
ATTR_ENTITY_ID: "climate.air_conditioner",
|
||||||
ATTR_TEMPERATURE: 27,
|
ATTR_TEMPERATURE: 27,
|
||||||
ATTR_HVAC_MODE: HVAC_MODE_OFF,
|
ATTR_HVAC_MODE: HVACMode.OFF,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
|
|
||||||
|
|
||||||
async def test_set_temperature_with_mode(hass, thermostat):
|
async def test_set_temperature_with_mode(hass, thermostat):
|
||||||
@ -532,26 +526,26 @@ async def test_set_temperature_with_mode(hass, thermostat):
|
|||||||
ATTR_ENTITY_ID: "climate.thermostat",
|
ATTR_ENTITY_ID: "climate.thermostat",
|
||||||
ATTR_TARGET_TEMP_HIGH: 25.5,
|
ATTR_TARGET_TEMP_HIGH: 25.5,
|
||||||
ATTR_TARGET_TEMP_LOW: 22.2,
|
ATTR_TARGET_TEMP_LOW: 22.2,
|
||||||
ATTR_HVAC_MODE: HVAC_MODE_HEAT_COOL,
|
ATTR_HVAC_MODE: HVACMode.HEAT_COOL,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.thermostat")
|
state = hass.states.get("climate.thermostat")
|
||||||
assert state.attributes[ATTR_TARGET_TEMP_HIGH] == 25.5
|
assert state.attributes[ATTR_TARGET_TEMP_HIGH] == 25.5
|
||||||
assert state.attributes[ATTR_TARGET_TEMP_LOW] == 22.2
|
assert state.attributes[ATTR_TARGET_TEMP_LOW] == 22.2
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
|
|
||||||
|
|
||||||
async def test_set_turn_off(hass, air_conditioner):
|
async def test_set_turn_off(hass, air_conditioner):
|
||||||
"""Test the a/c is turned off successfully."""
|
"""Test the a/c is turned off successfully."""
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN, SERVICE_TURN_OFF, {"entity_id": "all"}, blocking=True
|
CLIMATE_DOMAIN, SERVICE_TURN_OFF, {"entity_id": "all"}, blocking=True
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
|
|
||||||
|
|
||||||
async def test_set_turn_on(hass, air_conditioner):
|
async def test_set_turn_on(hass, air_conditioner):
|
||||||
@ -559,12 +553,12 @@ async def test_set_turn_on(hass, air_conditioner):
|
|||||||
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
air_conditioner.status.update_attribute_value(Attribute.switch, "off")
|
||||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_OFF
|
assert state.state == HVACMode.OFF
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN, SERVICE_TURN_ON, {"entity_id": "all"}, blocking=True
|
CLIMATE_DOMAIN, SERVICE_TURN_ON, {"entity_id": "all"}, blocking=True
|
||||||
)
|
)
|
||||||
state = hass.states.get("climate.air_conditioner")
|
state = hass.states.get("climate.air_conditioner")
|
||||||
assert state.state == HVAC_MODE_HEAT_COOL
|
assert state.state == HVACMode.HEAT_COOL
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_and_device_attributes(hass, thermostat):
|
async def test_entity_and_device_attributes(hass, thermostat):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user