mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 00:20:30 +01:00
Simplify PLATFORMS patching in Tuya test (#167054)
This commit is contained in:
@@ -26,7 +26,15 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch(
|
||||
"homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -41,7 +49,6 @@ async def test_platform_setup_and_discovery(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
@pytest.mark.parametrize(
|
||||
("mock_device_code", "entity_id"),
|
||||
[
|
||||
@@ -83,7 +90,6 @@ async def test_service(
|
||||
mock_manager.send_commands.assert_called_once_with(mock_device.id, [command])
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
@pytest.mark.parametrize(
|
||||
("mock_device_code", "entity_id"),
|
||||
[
|
||||
|
||||
@@ -19,7 +19,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
@@ -55,7 +61,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
@@ -98,7 +103,6 @@ async def test_selective_state_update(
|
||||
(0x83, "on", "on", "on"),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_bitmap(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -18,7 +18,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
@@ -34,7 +40,6 @@ async def test_platform_setup_and_discovery(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["sd_lr33znaodtyarrrz"],
|
||||
|
||||
@@ -23,6 +23,20 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with (
|
||||
patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA]),
|
||||
# Mock camera access token which normally is randomized.
|
||||
patch(
|
||||
"homeassistant.components.camera.SystemRandom.getrandbits",
|
||||
return_value=1,
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_getrandbits():
|
||||
"""Mock camera access token which normally is randomized."""
|
||||
@@ -33,7 +47,6 @@ def mock_getrandbits():
|
||||
yield
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA])
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -54,7 +67,6 @@ async def test_platform_setup_and_discovery(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["sp_rudejjigkywujjvs"],
|
||||
|
||||
@@ -43,7 +43,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -58,7 +64,6 @@ async def test_platform_setup_and_discovery(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE])
|
||||
async def test_us_customary_system(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -36,7 +36,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -112,7 +118,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_action(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -154,7 +159,6 @@ async def test_action(
|
||||
(50, 25),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_percent_state_on_cover(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -218,7 +222,6 @@ async def test_set_tilt_position_not_supported(
|
||||
(100, "open", 100),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_clkg_wltqkykhni0papzj_state(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -275,7 +278,6 @@ async def test_clkg_wltqkykhni0papzj_state(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_clkg_wltqkykhni0papzj_action(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -321,7 +323,6 @@ async def test_clkg_wltqkykhni0papzj_action(
|
||||
("close", STATE_CLOSED),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||
async def test_cl_n3xgr5pdmpinictg_state(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -19,8 +19,14 @@ from . import MockDeviceListener, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2023-11-01 13:14:15+01:00")
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
|
||||
async def test_alarm_message_event(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -88,7 +93,6 @@ async def test_alarm_message_event(
|
||||
"mock_device_code",
|
||||
["wxkg_l8yaz4um5b3pwyvf"],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -26,7 +26,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -41,7 +47,6 @@ async def test_platform_setup_and_discovery(
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN])
|
||||
@pytest.mark.parametrize(
|
||||
("mock_device_code", "entity_id", "service", "service_data", "expected_commands"),
|
||||
[
|
||||
|
||||
@@ -26,7 +26,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.HUMIDIFIER])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.HUMIDIFIER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -27,7 +27,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.LIGHT])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.LIGHT]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -25,7 +25,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -60,7 +66,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -20,7 +20,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
@@ -56,7 +62,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
@@ -85,7 +90,6 @@ async def test_selective_state_update(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR])
|
||||
@pytest.mark.parametrize("mock_device_code", ["cz_guitoc9iylae4axs"])
|
||||
async def test_delta_report_sensor(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
@@ -88,7 +93,6 @@ async def test_selective_state_update(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["sp_sdd5f5f2dl5wydjf"],
|
||||
|
||||
@@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
@@ -88,7 +93,6 @@ async def test_selective_state_update(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cz_PGEkBctAbtzKOZng"],
|
||||
@@ -133,7 +137,6 @@ async def test_action(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["cz_PGEkBctAbtzKOZng"],
|
||||
|
||||
@@ -28,7 +28,13 @@ from . import initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VACUUM])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.VACUUM]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
|
||||
@@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE])
|
||||
@pytest.fixture(autouse=True)
|
||||
def platform_autouse():
|
||||
"""Platform fixture."""
|
||||
with patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_platform_setup_and_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
@@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery(
|
||||
),
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE])
|
||||
@pytest.mark.freeze_time("2024-01-01")
|
||||
async def test_selective_state_update(
|
||||
hass: HomeAssistant,
|
||||
@@ -88,7 +93,6 @@ async def test_selective_state_update(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["sfkzq_ed7frwissyqrejic"],
|
||||
@@ -133,7 +137,6 @@ async def test_action(
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE])
|
||||
@pytest.mark.parametrize(
|
||||
"mock_device_code",
|
||||
["sfkzq_ed7frwissyqrejic"],
|
||||
|
||||
Reference in New Issue
Block a user