mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Use pytest.parametrize in Tuya siren/switch/valve tests (#156920)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user