Skip to content

Commit 6bd1787

Browse files
authored
Improve parametrize in tuya light tests (home-assistant#156581)
1 parent 37040f5 commit 6bd1787

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

tests/components/tuya/test_light.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ async def test_platform_setup_and_discovery(
4545
["dj_mki13ie507rlry4r"],
4646
)
4747
@pytest.mark.parametrize(
48-
("turn_on_input", "expected_commands"),
48+
("service", "service_data", "expected_commands"),
4949
[
5050
(
51+
SERVICE_TURN_ON,
5152
{
5253
ATTR_WHITE: True,
5354
},
@@ -58,6 +59,7 @@ async def test_platform_setup_and_discovery(
5859
],
5960
),
6061
(
62+
SERVICE_TURN_ON,
6163
{
6264
ATTR_BRIGHTNESS: 150,
6365
},
@@ -67,6 +69,7 @@ async def test_platform_setup_and_discovery(
6769
],
6870
),
6971
(
72+
SERVICE_TURN_ON,
7073
{
7174
ATTR_WHITE: True,
7275
ATTR_BRIGHTNESS: 150,
@@ -78,6 +81,7 @@ async def test_platform_setup_and_discovery(
7881
],
7982
),
8083
(
84+
SERVICE_TURN_ON,
8185
{
8286
ATTR_WHITE: 150,
8387
},
@@ -87,61 +91,38 @@ async def test_platform_setup_and_discovery(
8791
{"code": "bright_value_v2", "value": 592},
8892
],
8993
),
94+
(
95+
SERVICE_TURN_OFF,
96+
{},
97+
[{"code": "switch_led", "value": False}],
98+
),
9099
],
91100
)
92-
async def test_turn_on_white(
101+
async def test_action(
93102
hass: HomeAssistant,
94103
mock_manager: Manager,
95104
mock_config_entry: MockConfigEntry,
96105
mock_device: CustomerDevice,
97-
turn_on_input: dict[str, Any],
106+
service: str,
107+
service_data: dict[str, Any],
98108
expected_commands: list[dict[str, Any]],
99109
) -> None:
100-
"""Test turn_on service."""
110+
"""Test service action."""
101111
entity_id = "light.garage_light"
102112
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
103113

104114
state = hass.states.get(entity_id)
105115
assert state is not None, f"{entity_id} does not exist"
106116
await hass.services.async_call(
107117
LIGHT_DOMAIN,
108-
SERVICE_TURN_ON,
118+
service,
109119
{
110120
ATTR_ENTITY_ID: entity_id,
111-
**turn_on_input,
121+
**service_data,
112122
},
113123
blocking=True,
114124
)
115125
mock_manager.send_commands.assert_called_once_with(
116126
mock_device.id,
117127
expected_commands,
118128
)
119-
120-
121-
@pytest.mark.parametrize(
122-
"mock_device_code",
123-
["dj_mki13ie507rlry4r"],
124-
)
125-
async def test_turn_off(
126-
hass: HomeAssistant,
127-
mock_manager: Manager,
128-
mock_config_entry: MockConfigEntry,
129-
mock_device: CustomerDevice,
130-
) -> None:
131-
"""Test turn_off service."""
132-
entity_id = "light.garage_light"
133-
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
134-
135-
state = hass.states.get(entity_id)
136-
assert state is not None, f"{entity_id} does not exist"
137-
await hass.services.async_call(
138-
LIGHT_DOMAIN,
139-
SERVICE_TURN_OFF,
140-
{
141-
ATTR_ENTITY_ID: entity_id,
142-
},
143-
blocking=True,
144-
)
145-
mock_manager.send_commands.assert_called_once_with(
146-
mock_device.id, [{"code": "switch_led", "value": False}]
147-
)

0 commit comments

Comments
 (0)