Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion homeassistant/components/coolmaster/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@

HA_STATE_TO_CM = {value: key for key, value in CM_TO_HA_STATE.items()}

HVAC_MODES = list(CM_TO_HA_STATE.values())

# these are modes supported by Coolmaster that have no direct HA equivalent.
COOLMASTER_ONLY_MODES = ["vlow", "top"]

CM_TO_HA_FAN = {
"low": FAN_LOW,
"med": FAN_MEDIUM,
"high": FAN_HIGH,
"auto": FAN_AUTO,
}
} | {mode: mode for mode in COOLMASTER_ONLY_MODES}

HA_FAN_TO_CM = {value: key for key, value in CM_TO_HA_FAN.items()}

Expand Down
55 changes: 52 additions & 3 deletions tests/components/coolmaster/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,37 @@
"clean_filter": True,
"swing": "horizontal",
},
"L1.102": {
"is_on": True,
"thermostat": 20,
"temperature": 25,
"temperature_unit": "celsius",
"fan_speed": "vlow",
"mode": "cool",
"error_code": None,
"clean_filter": False,
"swing": None,
},
"L1.103": {
"is_on": True,
"thermostat": 25,
"temperature": 25,
"temperature_unit": "celsius",
"fan_speed": "med",
"mode": "dry",
"error_code": None,
"clean_filter": False,
"swing": None,
},
}


@pytest.fixture
def unit_count():
"""Fixture to expose the number of pre-defined units."""
return len(TEST_UNITS)


class CoolMasterNetUnitMock:
"""Mock for CoolMasterNetUnit."""

Expand Down Expand Up @@ -166,7 +194,14 @@ async def load_int(hass: HomeAssistant) -> MockConfigEntry:
data={
"host": "1.2.3.4",
"port": 1234,
"supported_modes": [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT],
"supported_modes": [
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.HEAT_COOL,
HVACMode.FAN_ONLY,
],
},
)

Expand All @@ -190,7 +225,14 @@ async def config_entry_with_errors(hass: HomeAssistant) -> MockConfigEntry:
data={
"host": "1.2.3.4",
"port": 1234,
"supported_modes": [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT],
"supported_modes": [
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.HEAT_COOL,
HVACMode.FAN_ONLY,
],
},
)

Expand All @@ -214,7 +256,14 @@ async def config_entry_with_empty_status(hass: HomeAssistant) -> MockConfigEntry
data={
"host": "1.2.3.4",
"port": 1234,
"supported_modes": [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT],
"supported_modes": [
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.HEAT_COOL,
HVACMode.FAN_ONLY,
],
},
)

Expand Down
42 changes: 29 additions & 13 deletions tests/components/coolmaster/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
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.components.coolmaster.climate import FAN_MODES, HVAC_MODES
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
Expand All @@ -44,6 +45,8 @@ async def test_climate_state(
"""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.DRY


async def test_climate_friendly_name(
Expand All @@ -53,6 +56,8 @@ async def test_climate_friendly_name(
"""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"


async def test_climate_supported_features(
Expand Down Expand Up @@ -82,6 +87,8 @@ async def test_climate_temperature(
"""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


async def test_climate_thermostat(
Expand All @@ -91,6 +98,8 @@ async def test_climate_thermostat(
"""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


async def test_climate_hvac_modes(
Expand All @@ -102,11 +111,15 @@ async def test_climate_hvac_modes(
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.DRY,
HVACMode.HEAT_COOL,
HVACMode.FAN_ONLY,
]
assert (
hass.states.get("climate.l1_101").attributes[ATTR_HVAC_MODES]
== hass.states.get("climate.l1_100").attributes[ATTR_HVAC_MODES]
)
for unit in ("climate.l1_101", "climate.l1_102", "climate.l1_103"):
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(
Expand All @@ -116,6 +129,8 @@ async def test_climate_fan_mode(
"""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


async def test_climate_fan_modes(
Expand All @@ -124,10 +139,11 @@ async def test_climate_fan_modes(
) -> None:
"""Test the Coolmaster climate fan modes."""
assert hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES] == FAN_MODES
assert (
hass.states.get("climate.l1_101").attributes[ATTR_FAN_MODES]
== hass.states.get("climate.l1_100").attributes[ATTR_FAN_MODES]
)
for unit in ("climate.l1_101", "climate.l1_102", "climate.l1_103"):
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(
Expand Down Expand Up @@ -227,9 +243,9 @@ async def test_set_swing_mode_error(
)


@pytest.mark.parametrize("target_hvac_mode", HVAC_MODES)
async def test_set_hvac_mode(
hass: HomeAssistant,
load_int: ConfigEntry,
hass: HomeAssistant, load_int: ConfigEntry, target_hvac_mode: str
) -> None:
"""Test the Coolmaster climate set hvac mode."""
assert hass.states.get("climate.l1_100").state == HVACMode.OFF
Expand All @@ -238,12 +254,12 @@ async def test_set_hvac_mode(
SERVICE_SET_HVAC_MODE,
{
ATTR_ENTITY_ID: "climate.l1_100",
ATTR_HVAC_MODE: HVACMode.HEAT,
ATTR_HVAC_MODE: target_hvac_mode,
},
blocking=True,
)
await hass.async_block_till_done()
assert hass.states.get("climate.l1_100").state == HVACMode.HEAT
assert hass.states.get("climate.l1_100").state == target_hvac_mode


async def test_set_hvac_mode_off(
Expand Down
26 changes: 18 additions & 8 deletions tests/components/coolmaster/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@


async def test_load_entry(
hass: HomeAssistant,
load_int: ConfigEntry,
hass: HomeAssistant, load_int: ConfigEntry, unit_count: int
) -> None:
"""Test Coolmaster initial load."""
# 2 units times 4 entities (climate, binary_sensor, sensor, button).
assert hass.states.async_entity_ids_count() == 8
# 4 units times 4 entities (climate, binary_sensor, sensor, button).
assert hass.states.async_entity_ids_count() == unit_count * 4
assert load_int.state is ConfigEntryState.LOADED


Expand All @@ -33,14 +32,17 @@ async def test_registry_cleanup(
hass: HomeAssistant,
load_int: ConfigEntry,
hass_ws_client: WebSocketGenerator,
unit_count: int,
) -> None:
"""Test being able to remove a disconnected device."""
entry_id = load_int.entry_id
device_registry = dr.async_get(hass)
live_id = "L1.100"
dead_id = "L2.200"

assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 2
assert (
len(dr.async_entries_for_config_entry(device_registry, entry_id)) == unit_count
)
device_registry.async_get_or_create(
config_entry_id=entry_id,
identifiers={(DOMAIN, dead_id)},
Expand All @@ -50,7 +52,10 @@ async def test_registry_cleanup(
sw_version="1.0",
)

assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 3
assert (
len(dr.async_entries_for_config_entry(device_registry, entry_id))
== unit_count + 1
)

assert await async_setup_component(hass, "config", {})
client = await hass_ws_client(hass)
Expand All @@ -59,13 +64,18 @@ async def test_registry_cleanup(
assert device is not None
response = await client.remove_device(device.id, entry_id)
assert not response["success"]
assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 3
assert (
len(dr.async_entries_for_config_entry(device_registry, entry_id))
== unit_count + 1
)
assert device_registry.async_get_device(identifiers={(DOMAIN, live_id)}) is not None

# Try to remove "L2.200" - succeeds since it is dead
device = device_registry.async_get_device(identifiers={(DOMAIN, dead_id)})
assert device is not None
response = await client.remove_device(device.id, entry_id)
assert response["success"]
assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 2
assert (
len(dr.async_entries_for_config_entry(device_registry, entry_id)) == unit_count
)
assert device_registry.async_get_device(identifiers={(DOMAIN, dead_id)}) is None
Loading