@@ -43,58 +43,43 @@ async def test_platform_setup_and_discovery(
4343 "mock_device_code" ,
4444 ["sfkzq_ed7frwissyqrejic" ],
4545)
46- async def test_open_valve (
47- hass : HomeAssistant ,
48- mock_manager : Manager ,
49- mock_config_entry : MockConfigEntry ,
50- mock_device : CustomerDevice ,
51- ) -> None :
52- """Test opening a valve."""
53- entity_id = "valve.jie_hashui_fa_valve_1"
54- await initialize_entry (hass , mock_manager , mock_config_entry , mock_device )
55-
56- state = hass .states .get (entity_id )
57- assert state is not None , f"{ entity_id } does not exist"
58- await hass .services .async_call (
59- VALVE_DOMAIN ,
60- SERVICE_OPEN_VALVE ,
61- {
62- ATTR_ENTITY_ID : entity_id ,
63- },
64- blocking = True ,
65- )
66- mock_manager .send_commands .assert_called_once_with (
67- mock_device .id , [{"code" : "switch_1" , "value" : True }]
68- )
69-
70-
71- @patch ("homeassistant.components.tuya.PLATFORMS" , [Platform .VALVE ])
7246@pytest .mark .parametrize (
73- "mock_device_code" ,
74- ["sfkzq_ed7frwissyqrejic" ],
47+ ("service" , "expected_commands" ),
48+ [
49+ (
50+ SERVICE_OPEN_VALVE ,
51+ [{"code" : "switch_1" , "value" : True }],
52+ ),
53+ (
54+ SERVICE_CLOSE_VALVE ,
55+ [{"code" : "switch_1" , "value" : False }],
56+ ),
57+ ],
7558)
76- async def test_close_valve (
59+ async def test_action (
7760 hass : HomeAssistant ,
7861 mock_manager : Manager ,
7962 mock_config_entry : MockConfigEntry ,
8063 mock_device : CustomerDevice ,
64+ service : str ,
65+ expected_commands : list [dict [str , Any ]],
8166) -> None :
82- """Test closing a valve."""
67+ """Test valve action ."""
8368 entity_id = "valve.jie_hashui_fa_valve_1"
8469 await initialize_entry (hass , mock_manager , mock_config_entry , mock_device )
8570
8671 state = hass .states .get (entity_id )
8772 assert state is not None , f"{ entity_id } does not exist"
8873 await hass .services .async_call (
8974 VALVE_DOMAIN ,
90- SERVICE_CLOSE_VALVE ,
75+ service ,
9176 {
9277 ATTR_ENTITY_ID : entity_id ,
9378 },
9479 blocking = True ,
9580 )
9681 mock_manager .send_commands .assert_called_once_with (
97- mock_device .id , [{ "code" : "switch_1" , "value" : False }]
82+ mock_device .id , expected_commands
9883 )
9984
10085
0 commit comments