Skip to content

Commit d5fd27d

Browse files
authored
Add tests for Tuya climate actions (home-assistant#156935)
1 parent 0a034b9 commit d5fd27d

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

tests/components/tuya/test_climate.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
from homeassistant.components.climate import (
1313
ATTR_FAN_MODE,
1414
ATTR_HUMIDITY,
15+
ATTR_HVAC_MODE,
16+
ATTR_PRESET_MODE,
1517
ATTR_TEMPERATURE,
1618
DOMAIN as CLIMATE_DOMAIN,
1719
SERVICE_SET_FAN_MODE,
1820
SERVICE_SET_HUMIDITY,
21+
SERVICE_SET_HVAC_MODE,
22+
SERVICE_SET_PRESET_MODE,
1923
SERVICE_SET_TEMPERATURE,
24+
SERVICE_TURN_OFF,
25+
SERVICE_TURN_ON,
26+
HVACMode,
2027
)
2128
from homeassistant.const import ATTR_ENTITY_ID, Platform
2229
from homeassistant.core import HomeAssistant
@@ -44,21 +51,49 @@ async def test_platform_setup_and_discovery(
4451

4552

4653
@pytest.mark.parametrize(
47-
"mock_device_code",
48-
["kt_5wnlzekkstwcdsvm"],
49-
)
50-
@pytest.mark.parametrize(
51-
("service", "service_data", "expected_command"),
54+
("mock_device_code", "entity_id", "service", "service_data", "expected_commands"),
5255
[
5356
(
57+
"kt_5wnlzekkstwcdsvm",
58+
"climate.air_conditioner",
5459
SERVICE_SET_TEMPERATURE,
5560
{ATTR_TEMPERATURE: 22.7},
56-
{"code": "temp_set", "value": 23},
61+
[{"code": "temp_set", "value": 23}],
5762
),
5863
(
64+
"kt_5wnlzekkstwcdsvm",
65+
"climate.air_conditioner",
5966
SERVICE_SET_FAN_MODE,
6067
{ATTR_FAN_MODE: 2},
61-
{"code": "windspeed", "value": "2"},
68+
[{"code": "windspeed", "value": "2"}],
69+
),
70+
(
71+
"kt_5wnlzekkstwcdsvm",
72+
"climate.air_conditioner",
73+
SERVICE_TURN_ON,
74+
{},
75+
[{"code": "switch", "value": True}],
76+
),
77+
(
78+
"kt_5wnlzekkstwcdsvm",
79+
"climate.air_conditioner",
80+
SERVICE_TURN_OFF,
81+
{},
82+
[{"code": "switch", "value": False}],
83+
),
84+
(
85+
"kt_ibmmirhhq62mmf1g",
86+
"climate.master_bedroom_ac",
87+
SERVICE_SET_HVAC_MODE,
88+
{ATTR_HVAC_MODE: HVACMode.COOL},
89+
[{"code": "switch", "value": True}, {"code": "mode", "value": "cold"}],
90+
),
91+
(
92+
"wk_gc1bxoq2hafxpa35",
93+
"climate.polotentsosushitel",
94+
SERVICE_SET_PRESET_MODE,
95+
{ATTR_PRESET_MODE: "holiday"},
96+
[{"code": "mode", "value": "holiday"}],
6297
),
6398
],
6499
)
@@ -67,12 +102,12 @@ async def test_action(
67102
mock_manager: Manager,
68103
mock_config_entry: MockConfigEntry,
69104
mock_device: CustomerDevice,
105+
entity_id: str,
70106
service: str,
71107
service_data: dict[str, Any],
72-
expected_command: dict[str, Any],
108+
expected_commands: list[dict[str, Any]],
73109
) -> None:
74110
"""Test climate action."""
75-
entity_id = "climate.air_conditioner"
76111
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
77112

78113
state = hass.states.get(entity_id)
@@ -87,7 +122,7 @@ async def test_action(
87122
blocking=True,
88123
)
89124
mock_manager.send_commands.assert_called_once_with(
90-
mock_device.id, [expected_command]
125+
mock_device.id, expected_commands
91126
)
92127

93128

0 commit comments

Comments
 (0)