diff --git a/tests/components/tuya/test_button.py b/tests/components/tuya/test_button.py index 2413f774fc1..391691ff931 100644 --- a/tests/components/tuya/test_button.py +++ b/tests/components/tuya/test_button.py @@ -39,13 +39,13 @@ async def test_platform_setup_and_discovery( "mock_device_code", ["sd_lr33znaodtyarrrz"], ) -async def test_button_press( +async def test_action( hass: HomeAssistant, mock_manager: Manager, mock_config_entry: MockConfigEntry, mock_device: CustomerDevice, ) -> None: - """Test pressing a button.""" + """Test button action.""" entity_id = "button.v20_reset_duster_cloth" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) diff --git a/tests/components/tuya/test_camera.py b/tests/components/tuya/test_camera.py index 35c0cd12a4a..186c411e0ce 100644 --- a/tests/components/tuya/test_camera.py +++ b/tests/components/tuya/test_camera.py @@ -72,7 +72,7 @@ async def test_platform_setup_and_discovery( ), ], ) -async def test_motion_detection( +async def test_action( hass: HomeAssistant, mock_manager: Manager, mock_config_entry: MockConfigEntry, @@ -80,7 +80,7 @@ async def test_motion_detection( service: str, expected_command: dict[str, Any], ) -> None: - """Test turning off a switch.""" + """Test camera action.""" entity_id = "camera.burocam" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) diff --git a/tests/components/tuya/test_climate.py b/tests/components/tuya/test_climate.py index 847a0b29941..1b01508f61a 100644 --- a/tests/components/tuya/test_climate.py +++ b/tests/components/tuya/test_climate.py @@ -71,7 +71,7 @@ async def test_action( service_data: dict[str, Any], expected_command: dict[str, Any], ) -> None: - """Test service action.""" + """Test climate action.""" entity_id = "climate.air_conditioner" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) diff --git a/tests/components/tuya/test_humidifier.py b/tests/components/tuya/test_humidifier.py index 8baa9b5d185..8a4d193a56b 100644 --- a/tests/components/tuya/test_humidifier.py +++ b/tests/components/tuya/test_humidifier.py @@ -66,7 +66,7 @@ async def test_action( service_data: dict[str, Any], expected_command: dict[str, Any], ) -> None: - """Test service action.""" + """Test humidifier action.""" entity_id = "humidifier.dehumidifier" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) diff --git a/tests/components/tuya/test_light.py b/tests/components/tuya/test_light.py index 45f1fe387f1..37d70150d11 100644 --- a/tests/components/tuya/test_light.py +++ b/tests/components/tuya/test_light.py @@ -107,7 +107,7 @@ async def test_action( service_data: dict[str, Any], expected_commands: list[dict[str, Any]], ) -> None: - """Test service action.""" + """Test light action.""" entity_id = "light.garage_light" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) diff --git a/tests/components/tuya/test_siren.py b/tests/components/tuya/test_siren.py index c3de4979a45..1cd91656e01 100644 --- a/tests/components/tuya/test_siren.py +++ b/tests/components/tuya/test_siren.py @@ -2,6 +2,7 @@ from __future__ import annotations +from typing import Any from unittest.mock import patch import pytest @@ -42,43 +43,28 @@ async def test_platform_setup_and_discovery( "mock_device_code", ["sp_sdd5f5f2dl5wydjf"], ) -async def test_turn_on( - hass: HomeAssistant, - mock_manager: Manager, - mock_config_entry: MockConfigEntry, - mock_device: CustomerDevice, -) -> None: - """Test turning on.""" - entity_id = "siren.c9" - await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) - - state = hass.states.get(entity_id) - assert state is not None, f"{entity_id} does not exist" - await hass.services.async_call( - SIREN_DOMAIN, - SERVICE_TURN_ON, - { - ATTR_ENTITY_ID: entity_id, - }, - blocking=True, - ) - mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "siren_switch", "value": True}] - ) - - -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]) @pytest.mark.parametrize( - "mock_device_code", - ["sp_sdd5f5f2dl5wydjf"], + ("service", "expected_commands"), + [ + ( + SERVICE_TURN_ON, + [{"code": "siren_switch", "value": True}], + ), + ( + SERVICE_TURN_OFF, + [{"code": "siren_switch", "value": False}], + ), + ], ) -async def test_turn_off( +async def test_action( hass: HomeAssistant, mock_manager: Manager, mock_config_entry: MockConfigEntry, mock_device: CustomerDevice, + service: str, + expected_commands: list[dict[str, Any]], ) -> None: - """Test turning off.""" + """Test siren action.""" entity_id = "siren.c9" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) @@ -86,12 +72,12 @@ async def test_turn_off( assert state is not None, f"{entity_id} does not exist" await hass.services.async_call( SIREN_DOMAIN, - SERVICE_TURN_OFF, + service, { ATTR_ENTITY_ID: entity_id, }, blocking=True, ) mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "siren_switch", "value": False}] + mock_device.id, expected_commands ) diff --git a/tests/components/tuya/test_switch.py b/tests/components/tuya/test_switch.py index 97eb4eabf7e..072efdb6ee1 100644 --- a/tests/components/tuya/test_switch.py +++ b/tests/components/tuya/test_switch.py @@ -95,43 +95,28 @@ async def test_sfkzq_deprecated_switch( "mock_device_code", ["cz_PGEkBctAbtzKOZng"], ) -async def test_turn_on( - hass: HomeAssistant, - mock_manager: Manager, - mock_config_entry: MockConfigEntry, - mock_device: CustomerDevice, -) -> None: - """Test turning on a switch.""" - entity_id = "switch.din_socket" - await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) - - state = hass.states.get(entity_id) - assert state is not None, f"{entity_id} does not exist" - await hass.services.async_call( - SWITCH_DOMAIN, - SERVICE_TURN_ON, - { - ATTR_ENTITY_ID: entity_id, - }, - blocking=True, - ) - mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "switch", "value": True}] - ) - - -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]) @pytest.mark.parametrize( - "mock_device_code", - ["cz_PGEkBctAbtzKOZng"], + ("service", "expected_commands"), + [ + ( + SERVICE_TURN_ON, + [{"code": "switch", "value": True}], + ), + ( + SERVICE_TURN_OFF, + [{"code": "switch", "value": False}], + ), + ], ) -async def test_turn_off( +async def test_action( hass: HomeAssistant, mock_manager: Manager, mock_config_entry: MockConfigEntry, mock_device: CustomerDevice, + service: str, + expected_commands: list[dict[str, Any]], ) -> None: - """Test turning off a switch.""" + """Test switch action.""" entity_id = "switch.din_socket" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) @@ -139,14 +124,14 @@ async def test_turn_off( assert state is not None, f"{entity_id} does not exist" await hass.services.async_call( SWITCH_DOMAIN, - SERVICE_TURN_OFF, + service, { ATTR_ENTITY_ID: entity_id, }, blocking=True, ) mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "switch", "value": False}] + mock_device.id, expected_commands ) diff --git a/tests/components/tuya/test_vacuum.py b/tests/components/tuya/test_vacuum.py index b51eb405b2f..c8d495c4339 100644 --- a/tests/components/tuya/test_vacuum.py +++ b/tests/components/tuya/test_vacuum.py @@ -100,7 +100,7 @@ async def test_action( service_data: dict[str, Any], expected_command: dict[str, Any], ) -> None: - """Test service action.""" + """Test vacuum action.""" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) state = hass.states.get(entity_id) diff --git a/tests/components/tuya/test_valve.py b/tests/components/tuya/test_valve.py index dd840633da8..a315227a6f8 100644 --- a/tests/components/tuya/test_valve.py +++ b/tests/components/tuya/test_valve.py @@ -43,43 +43,28 @@ async def test_platform_setup_and_discovery( "mock_device_code", ["sfkzq_ed7frwissyqrejic"], ) -async def test_open_valve( - hass: HomeAssistant, - mock_manager: Manager, - mock_config_entry: MockConfigEntry, - mock_device: CustomerDevice, -) -> None: - """Test opening a valve.""" - entity_id = "valve.jie_hashui_fa_valve_1" - await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) - - state = hass.states.get(entity_id) - assert state is not None, f"{entity_id} does not exist" - await hass.services.async_call( - VALVE_DOMAIN, - SERVICE_OPEN_VALVE, - { - ATTR_ENTITY_ID: entity_id, - }, - blocking=True, - ) - mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "switch_1", "value": True}] - ) - - -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]) @pytest.mark.parametrize( - "mock_device_code", - ["sfkzq_ed7frwissyqrejic"], + ("service", "expected_commands"), + [ + ( + SERVICE_OPEN_VALVE, + [{"code": "switch_1", "value": True}], + ), + ( + SERVICE_CLOSE_VALVE, + [{"code": "switch_1", "value": False}], + ), + ], ) -async def test_close_valve( +async def test_action( hass: HomeAssistant, mock_manager: Manager, mock_config_entry: MockConfigEntry, mock_device: CustomerDevice, + service: str, + expected_commands: list[dict[str, Any]], ) -> None: - """Test closing a valve.""" + """Test valve action.""" entity_id = "valve.jie_hashui_fa_valve_1" await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) @@ -87,14 +72,14 @@ async def test_close_valve( assert state is not None, f"{entity_id} does not exist" await hass.services.async_call( VALVE_DOMAIN, - SERVICE_CLOSE_VALVE, + service, { ATTR_ENTITY_ID: entity_id, }, blocking=True, ) mock_manager.send_commands.assert_called_once_with( - mock_device.id, [{"code": "switch_1", "value": False}] + mock_device.id, expected_commands )