mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
373 lines
12 KiB
Python
373 lines
12 KiB
Python
"""The test for the Coolmaster climate platform."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pycoolmasternet_async import SWING_MODES
|
|
import pytest
|
|
|
|
from homeassistant.components.climate import (
|
|
ATTR_CURRENT_TEMPERATURE,
|
|
ATTR_FAN_MODE,
|
|
ATTR_FAN_MODES,
|
|
ATTR_HVAC_MODE,
|
|
ATTR_HVAC_MODES,
|
|
ATTR_SWING_MODE,
|
|
ATTR_SWING_MODES,
|
|
DOMAIN as CLIMATE_DOMAIN,
|
|
FAN_HIGH,
|
|
FAN_LOW,
|
|
FAN_MEDIUM,
|
|
SERVICE_SET_FAN_MODE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
SERVICE_SET_SWING_MODE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
ClimateEntityFeature,
|
|
HVACMode,
|
|
)
|
|
from homeassistant.components.coolmaster.climate import FAN_MODES
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import (
|
|
ATTR_ENTITY_ID,
|
|
ATTR_FRIENDLY_NAME,
|
|
ATTR_SUPPORTED_FEATURES,
|
|
ATTR_TEMPERATURE,
|
|
SERVICE_TURN_OFF,
|
|
SERVICE_TURN_ON,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
|
|
|
|
async def test_climate_state(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate state."""
|
|
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
|
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
|
assert hass.states.get("climate.l1_102").state == HVACMode.COOL
|
|
assert hass.states.get("climate.l1_103").state == HVACMode.COOL
|
|
assert hass.states.get("climate.l1_104").state == HVACMode.COOL
|
|
|
|
|
|
async def test_climate_friendly_name(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate friendly name."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_FRIENDLY_NAME] == "L1.100"
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_FRIENDLY_NAME] == "L1.101"
|
|
assert hass.states.get("climate.l1_102").attributes[ATTR_FRIENDLY_NAME] == "L1.102"
|
|
assert hass.states.get("climate.l1_103").attributes[ATTR_FRIENDLY_NAME] == "L1.103"
|
|
assert hass.states.get("climate.l1_104").attributes[ATTR_FRIENDLY_NAME] == "L1.104"
|
|
|
|
|
|
async def test_climate_supported_features(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate supported features."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_SUPPORTED_FEATURES] == (
|
|
ClimateEntityFeature.TARGET_TEMPERATURE
|
|
| ClimateEntityFeature.FAN_MODE
|
|
| ClimateEntityFeature.TURN_OFF
|
|
| ClimateEntityFeature.TURN_ON
|
|
)
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_SUPPORTED_FEATURES] == (
|
|
ClimateEntityFeature.TARGET_TEMPERATURE
|
|
| ClimateEntityFeature.FAN_MODE
|
|
| ClimateEntityFeature.SWING_MODE
|
|
| ClimateEntityFeature.TURN_OFF
|
|
| ClimateEntityFeature.TURN_ON
|
|
)
|
|
|
|
|
|
async def test_climate_temperature(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate current temperature."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_CURRENT_TEMPERATURE] == 25
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_CURRENT_TEMPERATURE] == 10
|
|
assert hass.states.get("climate.l1_102").attributes[ATTR_CURRENT_TEMPERATURE] == 25
|
|
assert hass.states.get("climate.l1_103").attributes[ATTR_CURRENT_TEMPERATURE] == 25
|
|
assert hass.states.get("climate.l1_104").attributes[ATTR_CURRENT_TEMPERATURE] == 25
|
|
|
|
|
|
async def test_climate_thermostat(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate thermostat."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 20
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_TEMPERATURE] == 20
|
|
assert hass.states.get("climate.l1_102").attributes[ATTR_TEMPERATURE] == 20
|
|
assert hass.states.get("climate.l1_103").attributes[ATTR_TEMPERATURE] == 25
|
|
assert hass.states.get("climate.l1_104").attributes[ATTR_TEMPERATURE] == 25
|
|
|
|
|
|
async def test_climate_hvac_modes(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate hvac modes."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_HVAC_MODES] == [
|
|
HVACMode.OFF,
|
|
HVACMode.COOL,
|
|
HVACMode.HEAT,
|
|
]
|
|
for unit in (
|
|
"climate.l1_101",
|
|
"climate.l1_102",
|
|
"climate.l1_103",
|
|
"climate.l1_104",
|
|
):
|
|
assert (
|
|
hass.states.get(unit).attributes[ATTR_HVAC_MODES]
|
|
== hass.states.get("climate.l1_100").attributes[ATTR_HVAC_MODES]
|
|
)
|
|
|
|
|
|
async def test_climate_fan_mode(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate fan mode."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == FAN_LOW
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_FAN_MODE] == FAN_HIGH
|
|
assert hass.states.get("climate.l1_102").attributes[ATTR_FAN_MODE] == "vlow"
|
|
assert hass.states.get("climate.l1_103").attributes[ATTR_FAN_MODE] == FAN_MEDIUM
|
|
assert hass.states.get("climate.l1_104").attributes[ATTR_FAN_MODE] == "ultra"
|
|
|
|
|
|
async def test_climate_unknown_fan_mode_warning(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
caplog: pytest.LogCaptureFixture,
|
|
) -> None:
|
|
"""Test the Coolmaster climate unknown fan mode warning."""
|
|
# TODO(2026.7.0): When support for unknown fan speeds is removed, delete this test.
|
|
setup_logs = caplog.get_records(when="setup")
|
|
|
|
# Assert that both unknown fan speeds logged a warning.
|
|
assert any(
|
|
"Detected unknown fan speed value from HVAC unit: ultra. "
|
|
"Support for unknown fan speeds will be removed in 2026.7.0"
|
|
in rec.getMessage()
|
|
and rec.levelname == "WARNING"
|
|
for rec in setup_logs
|
|
)
|
|
assert any(
|
|
"Detected unknown fan speed value from HVAC unit: vlow. "
|
|
"Support for unknown fan speeds will be removed in 2026.7.0"
|
|
in rec.getMessage()
|
|
and rec.levelname == "WARNING"
|
|
for rec in setup_logs
|
|
)
|
|
|
|
start_record_count = len(caplog.records)
|
|
# Get the entity from the climate component
|
|
climate_component = hass.data[CLIMATE_DOMAIN]
|
|
entity = climate_component.get_entity("climate.l1_104")
|
|
|
|
# Access the fan_mode property again to ensure no duplicate warnings are logged
|
|
assert entity.fan_mode == "ultra"
|
|
end_record_count = len(caplog.records)
|
|
|
|
for record in caplog.records[start_record_count:end_record_count]:
|
|
assert not (
|
|
"Detected unknown fan speed value from HVAC unit: ultra. "
|
|
"Support for unknown fan speeds will be removed in 2026.7.0"
|
|
in record.getMessage()
|
|
and record.levelname == "WARNING"
|
|
)
|
|
|
|
|
|
async def test_climate_fan_modes(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate fan modes."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES] == FAN_MODES
|
|
for unit in (
|
|
"climate.l1_101",
|
|
"climate.l1_102",
|
|
"climate.l1_103",
|
|
"climate.l1_104",
|
|
):
|
|
assert (
|
|
hass.states.get(unit).attributes[ATTR_FAN_MODES]
|
|
== hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES]
|
|
)
|
|
|
|
|
|
async def test_climate_swing_mode(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate swing mode."""
|
|
assert ATTR_SWING_MODE not in hass.states.get("climate.l1_100").attributes
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "horizontal"
|
|
|
|
|
|
async def test_climate_swing_modes(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate swing modes."""
|
|
assert ATTR_SWING_MODES not in hass.states.get("climate.l1_100").attributes
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODES] == SWING_MODES
|
|
|
|
|
|
async def test_set_temperature(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set temperature."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 20
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_100",
|
|
ATTR_TEMPERATURE: 30,
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_TEMPERATURE] == 30
|
|
|
|
|
|
@pytest.mark.parametrize("target_fan_mode", FAN_MODES)
|
|
async def test_set_fan_mode(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
target_fan_mode: str,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set fan mode."""
|
|
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == FAN_LOW
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_FAN_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_100",
|
|
ATTR_FAN_MODE: target_fan_mode,
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert (
|
|
hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODE] == target_fan_mode
|
|
)
|
|
|
|
|
|
async def test_set_swing_mode(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set swing mode."""
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "horizontal"
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_SWING_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_101",
|
|
ATTR_SWING_MODE: "vertical",
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_101").attributes[ATTR_SWING_MODE] == "vertical"
|
|
|
|
|
|
async def test_set_swing_mode_error(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set swing mode with error."""
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_SWING_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_101",
|
|
ATTR_SWING_MODE: "",
|
|
},
|
|
blocking=True,
|
|
)
|
|
|
|
|
|
async def test_set_hvac_mode(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set hvac mode."""
|
|
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_100",
|
|
ATTR_HVAC_MODE: HVACMode.HEAT,
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_100").state == HVACMode.HEAT
|
|
|
|
|
|
async def test_set_hvac_mode_off(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate set hvac mode to off."""
|
|
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_101",
|
|
ATTR_HVAC_MODE: HVACMode.OFF,
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_101").state == HVACMode.OFF
|
|
|
|
|
|
async def test_turn_on(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate turn on."""
|
|
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_TURN_ON,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_100",
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_100").state == HVACMode.COOL
|
|
|
|
|
|
async def test_turn_off(
|
|
hass: HomeAssistant,
|
|
load_int: ConfigEntry,
|
|
) -> None:
|
|
"""Test the Coolmaster climate turn off."""
|
|
assert hass.states.get("climate.l1_101").state == HVACMode.HEAT
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_TURN_OFF,
|
|
{
|
|
ATTR_ENTITY_ID: "climate.l1_101",
|
|
},
|
|
blocking=True,
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get("climate.l1_101").state == HVACMode.OFF
|