22
33from __future__ import annotations
44
5+ from typing import Any
56from unittest .mock import patch
67
78import pytest
@@ -46,74 +47,76 @@ async def test_platform_setup_and_discovery(
4647 "mock_device_code" ,
4748 ["kt_5wnlzekkstwcdsvm" ],
4849)
49- async def test_set_temperature (
50- hass : HomeAssistant ,
51- mock_manager : Manager ,
52- mock_config_entry : MockConfigEntry ,
53- mock_device : CustomerDevice ,
54- ) -> None :
55- """Test set temperature service."""
56- entity_id = "climate.air_conditioner"
57- await initialize_entry (hass , mock_manager , mock_config_entry , mock_device )
58-
59- state = hass .states .get (entity_id )
60- assert state is not None , f"{ entity_id } does not exist"
61- await hass .services .async_call (
62- CLIMATE_DOMAIN ,
63- SERVICE_SET_TEMPERATURE ,
64- {
65- ATTR_ENTITY_ID : entity_id ,
66- ATTR_TEMPERATURE : 22.7 ,
67- },
68- blocking = True ,
69- )
70- mock_manager .send_commands .assert_called_once_with (
71- mock_device .id , [{"code" : "temp_set" , "value" : 23 }]
72- )
73-
74-
7550@pytest .mark .parametrize (
76- "mock_device_code" ,
77- ["kt_5wnlzekkstwcdsvm" ],
51+ ("service" , "service_data" , "expected_command" ),
52+ [
53+ (
54+ SERVICE_SET_TEMPERATURE ,
55+ {ATTR_TEMPERATURE : 22.7 },
56+ {"code" : "temp_set" , "value" : 23 },
57+ ),
58+ (
59+ SERVICE_SET_FAN_MODE ,
60+ {ATTR_FAN_MODE : 2 },
61+ {"code" : "windspeed" , "value" : "2" },
62+ ),
63+ ],
7864)
79- async def test_fan_mode_windspeed (
65+ async def test_action (
8066 hass : HomeAssistant ,
8167 mock_manager : Manager ,
8268 mock_config_entry : MockConfigEntry ,
8369 mock_device : CustomerDevice ,
70+ service : str ,
71+ service_data : dict [str , Any ],
72+ expected_command : dict [str , Any ],
8473) -> None :
85- """Test fan mode with windspeed ."""
74+ """Test service action ."""
8675 entity_id = "climate.air_conditioner"
8776 await initialize_entry (hass , mock_manager , mock_config_entry , mock_device )
8877
8978 state = hass .states .get (entity_id )
9079 assert state is not None , f"{ entity_id } does not exist"
91- assert state .attributes [ATTR_FAN_MODE ] == 1
9280 await hass .services .async_call (
9381 CLIMATE_DOMAIN ,
94- SERVICE_SET_FAN_MODE ,
82+ service ,
9583 {
9684 ATTR_ENTITY_ID : entity_id ,
97- ATTR_FAN_MODE : 2 ,
85+ ** service_data ,
9886 },
9987 blocking = True ,
10088 )
10189 mock_manager .send_commands .assert_called_once_with (
102- mock_device .id , [{ "code" : "windspeed" , "value" : "2" } ]
90+ mock_device .id , [expected_command ]
10391 )
10492
10593
10694@pytest .mark .parametrize (
10795 "mock_device_code" ,
10896 ["kt_5wnlzekkstwcdsvm" ],
10997)
110- async def test_fan_mode_no_valid_code (
98+ @pytest .mark .parametrize (
99+ ("service" , "service_data" ),
100+ [
101+ (
102+ SERVICE_SET_FAN_MODE ,
103+ {ATTR_FAN_MODE : 2 },
104+ ),
105+ (
106+ SERVICE_SET_HUMIDITY ,
107+ {ATTR_HUMIDITY : 50 },
108+ ),
109+ ],
110+ )
111+ async def test_action_not_supported (
111112 hass : HomeAssistant ,
112113 mock_manager : Manager ,
113114 mock_config_entry : MockConfigEntry ,
114115 mock_device : CustomerDevice ,
116+ service : str ,
117+ service_data : dict [str , Any ],
115118) -> None :
116- """Test fan mode with no valid code ."""
119+ """Test service action not supported ."""
117120 # Remove windspeed DPCode to simulate a device with no valid fan mode
118121 mock_device .function .pop ("windspeed" , None )
119122 mock_device .status_range .pop ("windspeed" , None )
@@ -128,38 +131,10 @@ async def test_fan_mode_no_valid_code(
128131 with pytest .raises (ServiceNotSupported ):
129132 await hass .services .async_call (
130133 CLIMATE_DOMAIN ,
131- SERVICE_SET_FAN_MODE ,
132- {
133- ATTR_ENTITY_ID : entity_id ,
134- ATTR_FAN_MODE : 2 ,
135- },
136- blocking = True ,
137- )
138-
139-
140- @pytest .mark .parametrize (
141- "mock_device_code" ,
142- ["kt_5wnlzekkstwcdsvm" ],
143- )
144- async def test_set_humidity_not_supported (
145- hass : HomeAssistant ,
146- mock_manager : Manager ,
147- mock_config_entry : MockConfigEntry ,
148- mock_device : CustomerDevice ,
149- ) -> None :
150- """Test set humidity service (not available on this device)."""
151- entity_id = "climate.air_conditioner"
152- await initialize_entry (hass , mock_manager , mock_config_entry , mock_device )
153-
154- state = hass .states .get (entity_id )
155- assert state is not None , f"{ entity_id } does not exist"
156- with pytest .raises (ServiceNotSupported ):
157- await hass .services .async_call (
158- CLIMATE_DOMAIN ,
159- SERVICE_SET_HUMIDITY ,
134+ service ,
160135 {
161136 ATTR_ENTITY_ID : entity_id ,
162- ATTR_HUMIDITY : 50 ,
137+ ** service_data ,
163138 },
164139 blocking = True ,
165140 )
0 commit comments