diff --git a/tests/components/zha/test_alarm_control_panel.py b/tests/components/zha/test_alarm_control_panel.py index e3742a3132f..0d3b8ffa9f1 100644 --- a/tests/components/zha/test_alarm_control_panel.py +++ b/tests/components/zha/test_alarm_control_panel.py @@ -22,6 +22,21 @@ from .common import async_enable_traffic, find_entity_id from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE +@pytest.fixture(autouse=True) +def alarm_control_panel_platform_only(): + """Only setup the alarm_control_panel and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.ALARM_CONTROL_PANEL, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + @pytest.fixture def zigpy_device(zigpy_device_mock): """Device tracker zigpy device.""" diff --git a/tests/components/zha/test_api.py b/tests/components/zha/test_api.py index dac9855148a..08766bc74ac 100644 --- a/tests/components/zha/test_api.py +++ b/tests/components/zha/test_api.py @@ -37,7 +37,7 @@ from homeassistant.components.zha.core.const import ( GROUP_IDS, GROUP_NAME, ) -from homeassistant.const import ATTR_NAME +from homeassistant.const import ATTR_NAME, Platform from homeassistant.core import Context from .conftest import ( @@ -53,6 +53,20 @@ IEEE_SWITCH_DEVICE = "01:2d:6f:00:0a:90:69:e7" IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8" +@pytest.fixture(autouse=True) +def required_platform_only(): + """Only setup the required and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + ), + ): + yield + + @pytest.fixture async def device_switch(hass, zigpy_device_mock, zha_device_joined): """Test zha switch platform.""" diff --git a/tests/components/zha/test_binary_sensor.py b/tests/components/zha/test_binary_sensor.py index bfe2a3ce4f5..c27c8be16d8 100644 --- a/tests/components/zha/test_binary_sensor.py +++ b/tests/components/zha/test_binary_sensor.py @@ -1,4 +1,6 @@ """Test zha binary sensor.""" +from unittest.mock import patch + import pytest import zigpy.profiles.zha import zigpy.zcl.clusters.measurement as measurement @@ -34,6 +36,21 @@ DEVICE_OCCUPANCY = { } +@pytest.fixture(autouse=True) +def binary_sensor_platform_only(): + """Only setup the binary_sensor and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BINARY_SENSOR, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + async def async_test_binary_sensor_on_off(hass, cluster, entity_id): """Test getting on and off messages for binary sensors.""" # binary sensor on diff --git a/tests/components/zha/test_button.py b/tests/components/zha/test_button.py index f692528203f..2fdc263d732 100644 --- a/tests/components/zha/test_button.py +++ b/tests/components/zha/test_button.py @@ -28,6 +28,7 @@ from homeassistant.const import ( ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_DIAGNOSTIC, STATE_UNKNOWN, + Platform, ) from homeassistant.helpers import entity_registry as er @@ -37,6 +38,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from tests.common import mock_coro +@pytest.fixture(autouse=True) +def button_platform_only(): + """Only setup the button and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BINARY_SENSOR, + Platform.BUTTON, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture async def contact_sensor(hass, zigpy_device_mock, zha_device_joined_restored): """Contact sensor fixture.""" diff --git a/tests/components/zha/test_channels.py b/tests/components/zha/test_channels.py index e55e10bd7ae..7701992cab4 100644 --- a/tests/components/zha/test_channels.py +++ b/tests/components/zha/test_channels.py @@ -20,6 +20,13 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from tests.common import async_capture_events +@pytest.fixture(autouse=True) +def disable_platform_only(): + """Disable platforms to speed up tests.""" + with patch("homeassistant.components.zha.PLATFORMS", []): + yield + + @pytest.fixture def ieee(): """IEEE fixture.""" diff --git a/tests/components/zha/test_climate.py b/tests/components/zha/test_climate.py index 7866bba076c..a04b2c116e3 100644 --- a/tests/components/zha/test_climate.py +++ b/tests/components/zha/test_climate.py @@ -171,6 +171,24 @@ ZCL_ATTR_PLUG = { } +@pytest.fixture(autouse=True) +def climate_platform_only(): + """Only setup the climate and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BUTTON, + Platform.CLIMATE, + Platform.BINARY_SENSOR, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + ), + ): + yield + + @pytest.fixture def device_climate_mock(hass, zigpy_device_mock, zha_device_joined): """Test regular thermostat device.""" diff --git a/tests/components/zha/test_config_flow.py b/tests/components/zha/test_config_flow.py index df68c21b6c0..285c08d8a3e 100644 --- a/tests/components/zha/test_config_flow.py +++ b/tests/components/zha/test_config_flow.py @@ -34,6 +34,13 @@ from homeassistant.data_entry_flow import ( from tests.common import MockConfigEntry +@pytest.fixture(autouse=True) +def disable_platform_only(): + """Disable platforms to speed up tests.""" + with patch("homeassistant.components.zha.PLATFORMS", []): + yield + + def com_port(): """Mock of a serial port.""" port = serial.tools.list_ports_common.ListPortInfo("/dev/ttyUSB1234") diff --git a/tests/components/zha/test_cover.py b/tests/components/zha/test_cover.py index d5b07e16685..3dab405151d 100644 --- a/tests/components/zha/test_cover.py +++ b/tests/components/zha/test_cover.py @@ -39,6 +39,21 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE from tests.common import async_capture_events, mock_coro, mock_restore_cache +@pytest.fixture(autouse=True) +def cover_platform_only(): + """Only setup the cover and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.COVER, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + @pytest.fixture def zigpy_cover_device(zigpy_device_mock): """Zigpy cover device.""" diff --git a/tests/components/zha/test_device.py b/tests/components/zha/test_device.py index 0f2caceada5..8b718635b6a 100644 --- a/tests/components/zha/test_device.py +++ b/tests/components/zha/test_device.py @@ -12,7 +12,7 @@ from homeassistant.components.zha.core.const import ( CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY, CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS, ) -from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE +from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE, Platform import homeassistant.helpers.device_registry as dr import homeassistant.util.dt as dt_util @@ -22,6 +22,22 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from tests.common import async_fire_time_changed +@pytest.fixture(autouse=True) +def required_platforms_only(): + """Only setup the required platform and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.SENSOR, + Platform.SELECT, + Platform.SWITCH, + Platform.BINARY_SENSOR, + ), + ): + yield + + @pytest.fixture def zigpy_device(zigpy_device_mock): """Device tracker zigpy device.""" diff --git a/tests/components/zha/test_device_action.py b/tests/components/zha/test_device_action.py index 54cc7e9171d..fffb79fe0f2 100644 --- a/tests/components/zha/test_device_action.py +++ b/tests/components/zha/test_device_action.py @@ -24,6 +24,23 @@ COMMAND = "command" COMMAND_SINGLE = "single" +@pytest.fixture(autouse=True) +def required_platforms_only(): + """Only setup the required platforms and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BINARY_SENSOR, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, + Platform.SIREN, + ), + ): + yield + + @pytest.fixture async def device_ias(hass, zigpy_device_mock, zha_device_joined_restored): """IAS device fixture.""" diff --git a/tests/components/zha/test_device_tracker.py b/tests/components/zha/test_device_tracker.py index 06caac91cb2..59c36143a6e 100644 --- a/tests/components/zha/test_device_tracker.py +++ b/tests/components/zha/test_device_tracker.py @@ -1,6 +1,7 @@ """Test ZHA Device Tracker.""" from datetime import timedelta import time +from unittest.mock import patch import pytest import zigpy.profiles.zha @@ -24,6 +25,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE from tests.common import async_fire_time_changed +@pytest.fixture(autouse=True) +def device_tracker_platforms_only(): + """Only setup the device_tracker platforms and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.BUTTON, + Platform.SELECT, + Platform.NUMBER, + Platform.BINARY_SENSOR, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture def zigpy_device_dt(zigpy_device_mock): """Device tracker zigpy device.""" diff --git a/tests/components/zha/test_device_trigger.py b/tests/components/zha/test_device_trigger.py index ac93cbe0c7f..1f5fa467a93 100644 --- a/tests/components/zha/test_device_trigger.py +++ b/tests/components/zha/test_device_trigger.py @@ -1,6 +1,7 @@ """ZHA device automation trigger tests.""" from datetime import timedelta import time +from unittest.mock import patch import pytest import zigpy.profiles.zha @@ -8,6 +9,7 @@ import zigpy.zcl.clusters.general as general import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType +from homeassistant.const import Platform from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -36,6 +38,13 @@ LONG_PRESS = "remote_button_long_press" LONG_RELEASE = "remote_button_long_release" +@pytest.fixture(autouse=True) +def sensor_platforms_only(): + """Only setup the sensor platform and required base platforms to speed up tests.""" + with patch("homeassistant.components.zha.PLATFORMS", (Platform.SENSOR,)): + yield + + def _same_lists(list_a, list_b): if len(list_a) != len(list_b): return False diff --git a/tests/components/zha/test_diagnostics.py b/tests/components/zha/test_diagnostics.py index 804b6d73316..d88996c78f1 100644 --- a/tests/components/zha/test_diagnostics.py +++ b/tests/components/zha/test_diagnostics.py @@ -1,6 +1,8 @@ """Tests for the diagnostics data provided by the ESPHome integration.""" +from unittest.mock import patch + import pytest import zigpy.profiles.zha as zha import zigpy.zcl.clusters.security as security @@ -8,6 +10,7 @@ import zigpy.zcl.clusters.security as security from homeassistant.components.diagnostics.const import REDACTED from homeassistant.components.zha.core.device import ZHADevice from homeassistant.components.zha.diagnostics import KEYS_TO_REDACT +from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import async_get @@ -26,6 +29,15 @@ CONFIG_ENTRY_DIAGNOSTICS_KEYS = [ ] +@pytest.fixture(autouse=True) +def required_platforms_only(): + """Only setup the required platform and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", (Platform.ALARM_CONTROL_PANEL,) + ): + yield + + @pytest.fixture def zigpy_device(zigpy_device_mock): """Device tracker zigpy device.""" diff --git a/tests/components/zha/test_fan.py b/tests/components/zha/test_fan.py index 19f5f39a22f..423634db035 100644 --- a/tests/components/zha/test_fan.py +++ b/tests/components/zha/test_fan.py @@ -51,6 +51,22 @@ IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8" IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8" +@pytest.fixture(autouse=True) +def fan_platform_only(): + """Only setup the fan and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.FAN, + Platform.LIGHT, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + @pytest.fixture def zigpy_device(zigpy_device_mock): """Device tracker zigpy device.""" diff --git a/tests/components/zha/test_gateway.py b/tests/components/zha/test_gateway.py index 67ce6481542..b19c98548ce 100644 --- a/tests/components/zha/test_gateway.py +++ b/tests/components/zha/test_gateway.py @@ -35,6 +35,22 @@ def zigpy_dev_basic(zigpy_device_mock): ) +@pytest.fixture(autouse=True) +def required_platform_only(): + """Only setup the required and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.SENSOR, + Platform.LIGHT, + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + @pytest.fixture async def zha_dev_basic(hass, zha_device_restored, zigpy_dev_basic): """ZHA device with just a basic cluster.""" diff --git a/tests/components/zha/test_init.py b/tests/components/zha/test_init.py index 0615eeef623..262a743559f 100644 --- a/tests/components/zha/test_init.py +++ b/tests/components/zha/test_init.py @@ -20,6 +20,13 @@ DATA_RADIO_TYPE = "deconz" DATA_PORT_PATH = "/dev/serial/by-id/FTDI_USB__-__Serial_Cable_12345678-if00-port0" +@pytest.fixture(autouse=True) +def disable_platform_only(): + """Disable platforms to speed up tests.""" + with patch("homeassistant.components.zha.PLATFORMS", []): + yield + + @pytest.fixture def config_entry_v1(hass): """Config entry version 1 fixture.""" diff --git a/tests/components/zha/test_light.py b/tests/components/zha/test_light.py index 8cf0e668503..dd6df0dff19 100644 --- a/tests/components/zha/test_light.py +++ b/tests/components/zha/test_light.py @@ -80,6 +80,24 @@ LIGHT_COLOR = { } +@pytest.fixture(autouse=True) +def light_platform_only(): + """Only setup the light and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BINARY_SENSOR, + Platform.DEVICE_TRACKER, + Platform.BUTTON, + Platform.LIGHT, + Platform.SENSOR, + Platform.NUMBER, + Platform.SELECT, + ), + ): + yield + + @pytest.fixture async def coordinator(hass, zigpy_device_mock, zha_device_joined): """Test zha light platform.""" diff --git a/tests/components/zha/test_lock.py b/tests/components/zha/test_lock.py index 0669cebf128..08b720b2ad7 100644 --- a/tests/components/zha/test_lock.py +++ b/tests/components/zha/test_lock.py @@ -27,6 +27,20 @@ CLEAR_PIN_CODE = 7 SET_USER_STATUS = 9 +@pytest.fixture(autouse=True) +def lock_platform_only(): + """Only setup the lock and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.LOCK, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture async def lock(hass, zigpy_device_mock, zha_device_joined_restored): """Lock cluster fixture.""" diff --git a/tests/components/zha/test_logbook.py b/tests/components/zha/test_logbook.py index 00e1cc28ea6..33b758fd0a7 100644 --- a/tests/components/zha/test_logbook.py +++ b/tests/components/zha/test_logbook.py @@ -1,11 +1,13 @@ """ZHA logbook describe events tests.""" +from unittest.mock import patch + import pytest import zigpy.profiles.zha import zigpy.zcl.clusters.general as general from homeassistant.components.zha.core.const import ZHA_EVENT -from homeassistant.const import CONF_DEVICE_ID, CONF_UNIQUE_ID +from homeassistant.const import CONF_DEVICE_ID, CONF_UNIQUE_ID, Platform from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component @@ -29,6 +31,13 @@ UP = "up" DOWN = "down" +@pytest.fixture(autouse=True) +def sensor_platform_only(): + """Only setup the sensor and required base platforms to speed up tests.""" + with patch("homeassistant.components.zha.PLATFORMS", (Platform.SENSOR,)): + yield + + @pytest.fixture async def mock_devices(hass, zigpy_device_mock, zha_device_joined): """IAS device fixture.""" diff --git a/tests/components/zha/test_number.py b/tests/components/zha/test_number.py index 01946c05f1a..f6b606ccbbf 100644 --- a/tests/components/zha/test_number.py +++ b/tests/components/zha/test_number.py @@ -24,6 +24,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE from tests.common import mock_coro +@pytest.fixture(autouse=True) +def number_platform_only(): + """Only setup the number and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BUTTON, + Platform.DEVICE_TRACKER, + Platform.LIGHT, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture def zigpy_analog_output_device(zigpy_device_mock): """Zigpy analog_output device.""" diff --git a/tests/components/zha/test_select.py b/tests/components/zha/test_select.py index 70b943d5ea2..c883d648e8e 100644 --- a/tests/components/zha/test_select.py +++ b/tests/components/zha/test_select.py @@ -1,6 +1,6 @@ """Test ZHA select entities.""" -from unittest.mock import call +from unittest.mock import call, patch import pytest from zigpy.const import SIG_EP_PROFILE @@ -16,6 +16,24 @@ from .common import find_entity_id from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE +@pytest.fixture(autouse=True) +def select_select_only(): + """Only setup the select and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.BUTTON, + Platform.DEVICE_TRACKER, + Platform.SIREN, + Platform.LIGHT, + Platform.NUMBER, + Platform.SELECT, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture async def siren(hass, zigpy_device_mock, zha_device_joined_restored): """Siren fixture.""" diff --git a/tests/components/zha/test_sensor.py b/tests/components/zha/test_sensor.py index 0d476fb8bda..c638bdd8c48 100644 --- a/tests/components/zha/test_sensor.py +++ b/tests/components/zha/test_sensor.py @@ -1,5 +1,6 @@ """Test zha sensor.""" import math +from unittest.mock import patch import pytest import zigpy.profiles.zha @@ -50,6 +51,19 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE ENTITY_ID_PREFIX = "sensor.fakemanufacturer_fakemodel_e769900a_{}" +@pytest.fixture(autouse=True) +def sensor_platform_only(): + """Only setup the sensor and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.SENSOR, + ), + ): + yield + + @pytest.fixture async def elec_measurement_zigpy_dev(hass, zigpy_device_mock): """Electric Measurement zigpy device.""" diff --git a/tests/components/zha/test_siren.py b/tests/components/zha/test_siren.py index 285bc1cd585..72a40a8323e 100644 --- a/tests/components/zha/test_siren.py +++ b/tests/components/zha/test_siren.py @@ -28,6 +28,22 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from tests.common import async_fire_time_changed, mock_coro +@pytest.fixture(autouse=True) +def siren_platform_only(): + """Only setup the siren and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.NUMBER, + Platform.SENSOR, + Platform.SELECT, + Platform.SIREN, + ), + ): + yield + + @pytest.fixture async def siren(hass, zigpy_device_mock, zha_device_joined_restored): """Siren fixture.""" diff --git a/tests/components/zha/test_switch.py b/tests/components/zha/test_switch.py index 99e8a681348..0b8fe658c28 100644 --- a/tests/components/zha/test_switch.py +++ b/tests/components/zha/test_switch.py @@ -41,6 +41,21 @@ IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8" IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8" +@pytest.fixture(autouse=True) +def switch_platform_only(): + """Only setup the switch and required base platforms to speed up tests.""" + with patch( + "homeassistant.components.zha.PLATFORMS", + ( + Platform.DEVICE_TRACKER, + Platform.SENSOR, + Platform.SELECT, + Platform.SWITCH, + ), + ): + yield + + @pytest.fixture def zigpy_device(zigpy_device_mock): """Device tracker zigpy device."""