diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 5256544c5e6f8d..51e4526104bf0d 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1024,18 +1024,6 @@ class MyCoordinator(DataUpdateCoordinator[MyData]): ) ``` -### Entity Performance Optimization -```python -# Use __slots__ for memory efficiency -class MySensor(SensorEntity): - __slots__ = ("_attr_native_value", "_attr_available") - - @property - def should_poll(self) -> bool: - """Disable polling when using coordinator.""" - return False # ✅ Let coordinator handle updates -``` - ## Testing Patterns ### Testing Best Practices @@ -1181,4 +1169,4 @@ python -m script.hassfest --integration-path homeassistant/components/my_integra pytest ./tests/components/my_integration \ --cov=homeassistant.components.my_integration \ --cov-report term-missing -``` \ No newline at end of file +``` diff --git a/homeassistant/components/mobile_app/manifest.json b/homeassistant/components/mobile_app/manifest.json index 6e4651ab0db074..e1e394be3635d3 100644 --- a/homeassistant/components/mobile_app/manifest.json +++ b/homeassistant/components/mobile_app/manifest.json @@ -16,5 +16,5 @@ "iot_class": "local_push", "loggers": ["nacl"], "quality_scale": "internal", - "requirements": ["PyNaCl==1.6.0"] + "requirements": ["PyNaCl==1.6.2"] } diff --git a/homeassistant/components/owntracks/manifest.json b/homeassistant/components/owntracks/manifest.json index 81da21b2a54a2f..ade83e87473017 100644 --- a/homeassistant/components/owntracks/manifest.json +++ b/homeassistant/components/owntracks/manifest.json @@ -9,6 +9,6 @@ "integration_type": "service", "iot_class": "local_push", "loggers": ["nacl"], - "requirements": ["PyNaCl==1.6.0"], + "requirements": ["PyNaCl==1.6.2"], "single_config_entry": true } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index bc32bc514d7116..c177ff6647f889 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -54,7 +54,7 @@ propcache==0.4.1 psutil-home-assistant==0.0.1 PyJWT==2.10.1 pymicro-vad==1.0.1 -PyNaCl==1.6.0 +PyNaCl==1.6.2 pyOpenSSL==25.3.0 pyserial==3.5 pyspeex-noise==1.0.2 diff --git a/requirements_all.txt b/requirements_all.txt index ee657fe63cd714..e20c175519b065 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -70,7 +70,7 @@ PyMicroBot==0.0.23 # homeassistant.components.mobile_app # homeassistant.components.owntracks -PyNaCl==1.6.0 +PyNaCl==1.6.2 # homeassistant.auth.mfa_modules.totp # homeassistant.components.homekit diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 13b8021a83ddb5..1fd04b403c00b1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -70,7 +70,7 @@ PyMicroBot==0.0.23 # homeassistant.components.mobile_app # homeassistant.components.owntracks -PyNaCl==1.6.0 +PyNaCl==1.6.2 # homeassistant.auth.mfa_modules.totp # homeassistant.components.homekit diff --git a/tests/components/__init__.py b/tests/components/__init__.py index 12e4b163cd8225..c1181074250549 100644 --- a/tests/components/__init__.py +++ b/tests/components/__init__.py @@ -5,6 +5,8 @@ import itertools from typing import Any, TypedDict +import pytest + from homeassistant.const import ( ATTR_AREA_ID, ATTR_DEVICE_ID, @@ -634,3 +636,37 @@ def other_states(state: StrEnum | Iterable[StrEnum]) -> list[str]: enum_class = list(state)[0].__class__ return sorted({s.value for s in enum_class} - excluded_values) + + +async def assert_condition_gated_by_labs_flag( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture, condition: str +) -> None: + """Helper to check that a condition is gated by the labs flag.""" + + # Local include to avoid importing the automation component unnecessarily + from homeassistant.components import automation # noqa: PLC0415 + + await async_setup_component( + hass, + automation.DOMAIN, + { + automation.DOMAIN: { + "trigger": {"platform": "event", "event_type": "test_event"}, + "condition": { + CONF_CONDITION: condition, + CONF_TARGET: {ATTR_LABEL_ID: "test_label"}, + CONF_OPTIONS: {"behavior": "any"}, + }, + "action": { + "service": "test.automation", + }, + } + }, + ) + + assert ( + "Unnamed automation failed to setup conditions and has been disabled: " + f"Condition '{condition}' requires the experimental 'New triggers and " + "conditions' feature to be enabled in Home Assistant Labs settings " + "(feature flag: 'new_triggers_conditions')" + ) in caplog.text diff --git a/tests/components/alarm_control_panel/test_trigger.py b/tests/components/alarm_control_panel/test_trigger.py index 6304cb6e052245..48a924046a338b 100644 --- a/tests/components/alarm_control_panel/test_trigger.py +++ b/tests/components/alarm_control_panel/test_trigger.py @@ -1,8 +1,6 @@ """Test alarm control panel triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -29,16 +27,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_alarm_control_panels(hass: HomeAssistant) -> list[str]: """Create multiple alarm control panel entities associated with different targets.""" @@ -70,7 +58,7 @@ async def test_alarm_control_panel_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("alarm_control_panel"), @@ -181,7 +169,7 @@ async def test_alarm_control_panel_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("alarm_control_panel"), @@ -291,7 +279,7 @@ async def test_alarm_control_panel_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("alarm_control_panel"), diff --git a/tests/components/assist_satellite/test_trigger.py b/tests/components/assist_satellite/test_trigger.py index 2692326434598f..51d19667390183 100644 --- a/tests/components/assist_satellite/test_trigger.py +++ b/tests/components/assist_satellite/test_trigger.py @@ -1,8 +1,6 @@ """Test assist satellite triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -26,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_assist_satellites(hass: HomeAssistant) -> list[str]: """Create multiple assist satellite entities associated with different targets.""" @@ -64,7 +52,7 @@ async def test_assist_satellite_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("assist_satellite"), @@ -132,7 +120,7 @@ async def test_assist_satellite_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("assist_satellite"), @@ -199,7 +187,7 @@ async def test_assist_satellite_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("assist_satellite"), diff --git a/tests/components/binary_sensor/test_trigger.py b/tests/components/binary_sensor/test_trigger.py index be31b77ba229f6..d78aed03b1b2fe 100644 --- a/tests/components/binary_sensor/test_trigger.py +++ b/tests/components/binary_sensor/test_trigger.py @@ -1,8 +1,6 @@ """Test binary sensor trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -30,16 +28,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_binary_sensors(hass: HomeAssistant) -> tuple[list[str], list[str]]: """Create multiple binary sensor entities associated with different targets.""" @@ -66,7 +54,7 @@ async def test_binary_sensor_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("binary_sensor"), @@ -136,7 +124,7 @@ async def test_binary_sensor_state_attribute_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("binary_sensor"), @@ -205,7 +193,7 @@ async def test_binary_sensor_state_attribute_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("binary_sensor"), diff --git a/tests/components/button/test_trigger.py b/tests/components/button/test_trigger.py index 98b52bf8434400..5943bea44ffd1c 100644 --- a/tests/components/button/test_trigger.py +++ b/tests/components/button/test_trigger.py @@ -1,8 +1,5 @@ """Test button trigger.""" -from collections.abc import Generator -from unittest.mock import patch - import pytest from homeassistant.const import ( @@ -27,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_buttons(hass: HomeAssistant) -> list[str]: """Create multiple button entities associated with different targets.""" @@ -57,7 +44,7 @@ async def test_button_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("button"), diff --git a/tests/components/climate/test_trigger.py b/tests/components/climate/test_trigger.py index 3c35a97096a0bc..46716ef16f8cc1 100644 --- a/tests/components/climate/test_trigger.py +++ b/tests/components/climate/test_trigger.py @@ -1,9 +1,7 @@ """Test climate trigger.""" -from collections.abc import Generator from contextlib import AbstractContextManager, nullcontext as does_not_raise from typing import Any -from unittest.mock import patch import pytest import voluptuous as vol @@ -45,16 +43,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_climates(hass: HomeAssistant) -> list[str]: """Create multiple climate entities associated with different targets.""" @@ -91,7 +79,7 @@ async def test_climate_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger", "trigger_options", "expected_result"), [ @@ -147,7 +135,7 @@ async def test_climate_trigger_validation( ) -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), @@ -220,7 +208,7 @@ async def test_climate_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), @@ -315,7 +303,7 @@ async def test_climate_state_attribute_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), @@ -389,7 +377,7 @@ async def test_climate_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), @@ -471,7 +459,7 @@ async def test_climate_state_attribute_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), @@ -544,7 +532,7 @@ async def test_climate_state_trigger_behavior_last( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("climate"), diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 38eeb3706c9fc9..19f8d605c347f7 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -1131,3 +1131,13 @@ def _service_registry_async_register( for description in translation_errors.values(): if description != "used": pytest.fail(description) + + +@pytest.fixture(name="enable_labs_preview_features") +def enable_labs_preview_features() -> Generator[None]: + """Enable labs preview features.""" + with patch( + "homeassistant.components.labs.async_is_preview_feature_enabled", + return_value=True, + ): + yield diff --git a/tests/components/device_tracker/test_trigger.py b/tests/components/device_tracker/test_trigger.py index 7ecd05272b2fdb..0327f46a511171 100644 --- a/tests/components/device_tracker/test_trigger.py +++ b/tests/components/device_tracker/test_trigger.py @@ -1,8 +1,6 @@ """Test device_tracker trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -31,16 +29,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_device_trackers(hass: HomeAssistant) -> list[str]: """Create multiple device_trackers entities associated with different targets.""" @@ -64,7 +52,7 @@ async def test_device_tracker_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("device_tracker"), @@ -122,7 +110,7 @@ async def test_device_tracker_home_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("device_tracker"), @@ -179,7 +167,7 @@ async def test_device_tracker_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("device_tracker"), diff --git a/tests/components/fan/test_condition.py b/tests/components/fan/test_condition.py index e318f51cec4ba4..ccb98d22e55a7c 100644 --- a/tests/components/fan/test_condition.py +++ b/tests/components/fan/test_condition.py @@ -1,25 +1,15 @@ """Test fan conditions.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest -from homeassistant.components import automation -from homeassistant.const import ( - ATTR_LABEL_ID, - CONF_CONDITION, - CONF_OPTIONS, - CONF_TARGET, - STATE_OFF, - STATE_ON, -) +from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component from tests.components import ( ConditionStateDescription, + assert_condition_gated_by_labs_flag, create_target_condition, parametrize_condition_states, parametrize_target_entities, @@ -45,43 +35,6 @@ async def target_switches(hass: HomeAssistant) -> list[str]: return (await target_entities(hass, "switch"))["included"] -async def setup_automation_with_fan_condition( - hass: HomeAssistant, - *, - condition: str, - target: dict, - behavior: str, -) -> None: - """Set up automation with fan state condition.""" - await async_setup_component( - hass, - automation.DOMAIN, - { - automation.DOMAIN: { - "trigger": {"platform": "event", "event_type": "test_event"}, - "condition": { - CONF_CONDITION: condition, - CONF_TARGET: target, - CONF_OPTIONS: {"behavior": behavior}, - }, - "action": { - "service": "test.automation", - }, - } - }, - ) - - -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.mark.parametrize( "condition", [ @@ -93,18 +46,10 @@ async def test_fan_conditions_gated_by_labs_flag( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, condition: str ) -> None: """Test the fan conditions are gated by the labs flag.""" - await setup_automation_with_fan_condition( - hass, condition=condition, target={ATTR_LABEL_ID: "test_label"}, behavior="any" - ) - assert ( - "Unnamed automation failed to setup conditions and has been disabled: " - f"Condition '{condition}' requires the experimental 'New triggers and " - "conditions' feature to be enabled in Home Assistant Labs settings " - "(feature flag: 'new_triggers_conditions')" - ) in caplog.text + await assert_condition_gated_by_labs_flag(hass, caplog, condition) -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("condition_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("fan"), @@ -170,7 +115,7 @@ async def test_fan_state_condition_behavior_any( assert condition(hass) == state["condition_true"] -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("condition_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("fan"), diff --git a/tests/components/fan/test_trigger.py b/tests/components/fan/test_trigger.py index 3a127f97c4b1d3..33e5b8f2ea723f 100644 --- a/tests/components/fan/test_trigger.py +++ b/tests/components/fan/test_trigger.py @@ -1,8 +1,6 @@ """Test fan trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -24,16 +22,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_fans(hass: HomeAssistant) -> list[str]: """Create multiple fan entities associated with different targets.""" @@ -60,7 +48,7 @@ async def test_fan_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("fan"), @@ -118,7 +106,7 @@ async def test_fan_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("fan"), @@ -175,7 +163,7 @@ async def test_fan_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("fan"), diff --git a/tests/components/firefly_iii/test_sensor.py b/tests/components/firefly_iii/test_sensor.py index 6042337fa37a09..1408c61c1fcd8f 100644 --- a/tests/components/firefly_iii/test_sensor.py +++ b/tests/components/firefly_iii/test_sensor.py @@ -2,6 +2,7 @@ from unittest.mock import AsyncMock, patch +from freezegun.api import FrozenDateTimeFactory from pyfirefly.exceptions import ( FireflyAuthenticationError, FireflyConnectionError, @@ -10,14 +11,16 @@ import pytest from syrupy.assertion import SnapshotAssertion +from homeassistant.components.firefly_iii.coordinator import DEFAULT_SCAN_INTERVAL from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er +from homeassistant.util import dt as dt_util from . import setup_integration -from tests.common import MockConfigEntry, snapshot_platform +from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform async def test_all_entities( @@ -51,6 +54,7 @@ async def test_refresh_exceptions( mock_firefly_client: AsyncMock, mock_config_entry: MockConfigEntry, exception: Exception, + freezer: FrozenDateTimeFactory, ) -> None: """Test entities go unavailable after coordinator refresh failures.""" await setup_integration(hass, mock_config_entry) @@ -58,7 +62,9 @@ async def test_refresh_exceptions( mock_firefly_client.get_accounts.side_effect = exception - await mock_config_entry.runtime_data.async_refresh() + freezer.tick(DEFAULT_SCAN_INTERVAL) + async_fire_time_changed(hass, dt_util.utcnow()) + await hass.async_block_till_done(wait_background_tasks=True) state = hass.states.get("sensor.credit_card_account_balance") assert state is not None diff --git a/tests/components/humidifier/test_trigger.py b/tests/components/humidifier/test_trigger.py index 2c7374f5978f38..2b85ab26cc0a6b 100644 --- a/tests/components/humidifier/test_trigger.py +++ b/tests/components/humidifier/test_trigger.py @@ -1,8 +1,6 @@ """Test humidifier trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -31,16 +29,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_humidifiers(hass: HomeAssistant) -> list[str]: """Create multiple humidifier entities associated with different targets.""" @@ -71,7 +59,7 @@ async def test_humidifier_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), @@ -129,7 +117,7 @@ async def test_humidifier_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), @@ -195,7 +183,7 @@ async def test_humidifier_state_attribute_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), @@ -252,7 +240,7 @@ async def test_humidifier_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), @@ -316,7 +304,7 @@ async def test_humidifier_state_attribute_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), @@ -372,7 +360,7 @@ async def test_humidifier_state_trigger_behavior_last( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("humidifier"), diff --git a/tests/components/lawn_mower/test_trigger.py b/tests/components/lawn_mower/test_trigger.py index 5c4a6aca1913f9..bd76bd429d687b 100644 --- a/tests/components/lawn_mower/test_trigger.py +++ b/tests/components/lawn_mower/test_trigger.py @@ -1,8 +1,6 @@ """Test lawn mower triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -26,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_lawn_mowers(hass: HomeAssistant) -> list[str]: """Create multiple lawn mower entities associated with different targets.""" @@ -64,7 +52,7 @@ async def test_lawn_mower_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("lawn_mower"), @@ -132,7 +120,7 @@ async def test_lawn_mower_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("lawn_mower"), @@ -199,7 +187,7 @@ async def test_lawn_mower_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("lawn_mower"), diff --git a/tests/components/light/test_condition.py b/tests/components/light/test_condition.py index d2912e5938ac6e..42863f771790e9 100644 --- a/tests/components/light/test_condition.py +++ b/tests/components/light/test_condition.py @@ -1,25 +1,15 @@ """Test light conditions.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest -from homeassistant.components import automation -from homeassistant.const import ( - ATTR_LABEL_ID, - CONF_CONDITION, - CONF_OPTIONS, - CONF_TARGET, - STATE_OFF, - STATE_ON, -) +from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, ServiceCall -from homeassistant.setup import async_setup_component from tests.components import ( ConditionStateDescription, + assert_condition_gated_by_labs_flag, create_target_condition, parametrize_condition_states, parametrize_target_entities, @@ -45,43 +35,6 @@ async def target_switches(hass: HomeAssistant) -> list[str]: return (await target_entities(hass, "switch"))["included"] -async def setup_automation_with_light_condition( - hass: HomeAssistant, - *, - condition: str, - target: dict, - behavior: str, -) -> None: - """Set up automation with light state condition.""" - await async_setup_component( - hass, - automation.DOMAIN, - { - automation.DOMAIN: { - "trigger": {"platform": "event", "event_type": "test_event"}, - "condition": { - CONF_CONDITION: condition, - CONF_TARGET: target, - CONF_OPTIONS: {"behavior": behavior}, - }, - "action": { - "service": "test.automation", - }, - } - }, - ) - - -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.mark.parametrize( "condition", [ @@ -93,18 +46,10 @@ async def test_light_conditions_gated_by_labs_flag( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, condition: str ) -> None: """Test the light conditions are gated by the labs flag.""" - await setup_automation_with_light_condition( - hass, condition=condition, target={ATTR_LABEL_ID: "test_label"}, behavior="any" - ) - assert ( - "Unnamed automation failed to setup conditions and has been disabled: " - f"Condition '{condition}' requires the experimental 'New triggers and " - "conditions' feature to be enabled in Home Assistant Labs settings " - "(feature flag: 'new_triggers_conditions')" - ) in caplog.text + await assert_condition_gated_by_labs_flag(hass, caplog, condition) -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("condition_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -170,7 +115,7 @@ async def test_light_state_condition_behavior_any( assert condition(hass) == state["condition_true"] -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("condition_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), diff --git a/tests/components/light/test_trigger.py b/tests/components/light/test_trigger.py index 56e05135d67bf5..d265fade22b028 100644 --- a/tests/components/light/test_trigger.py +++ b/tests/components/light/test_trigger.py @@ -1,8 +1,6 @@ """Test light trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -27,16 +25,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_lights(hass: HomeAssistant) -> list[str]: """Create multiple light entities associated with different targets.""" @@ -65,7 +53,7 @@ async def test_light_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -123,7 +111,7 @@ async def test_light_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -177,7 +165,7 @@ async def test_light_state_attribute_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -234,7 +222,7 @@ async def test_light_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -286,7 +274,7 @@ async def test_light_state_attribute_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), @@ -342,7 +330,7 @@ async def test_light_state_trigger_behavior_last( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("light"), diff --git a/tests/components/lock/test_trigger.py b/tests/components/lock/test_trigger.py index b14c0190043770..bab31788460e38 100644 --- a/tests/components/lock/test_trigger.py +++ b/tests/components/lock/test_trigger.py @@ -1,8 +1,6 @@ """Test lock triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -26,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_locks(hass: HomeAssistant) -> list[str]: """Create multiple lock entities associated with different targets.""" @@ -64,7 +52,7 @@ async def test_lock_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -132,7 +120,7 @@ async def test_lock_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -199,7 +187,7 @@ async def test_lock_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), diff --git a/tests/components/media_player/test_trigger.py b/tests/components/media_player/test_trigger.py index 20d34e2668e8b6..46cbb9181c8b9f 100644 --- a/tests/components/media_player/test_trigger.py +++ b/tests/components/media_player/test_trigger.py @@ -1,8 +1,6 @@ """Test media player trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -25,16 +23,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_media_players(hass: HomeAssistant) -> list[str]: """Create multiple media player entities associated with different targets.""" @@ -60,7 +48,7 @@ async def test_media_player_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("media_player"), @@ -121,7 +109,7 @@ async def test_media_player_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("media_player"), @@ -181,7 +169,7 @@ async def test_media_player_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("media_player"), diff --git a/tests/components/person/test_trigger.py b/tests/components/person/test_trigger.py index 9de0ab4c88cd12..2808f05c97c176 100644 --- a/tests/components/person/test_trigger.py +++ b/tests/components/person/test_trigger.py @@ -1,8 +1,6 @@ """Test person trigger.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -32,16 +30,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_persons(hass: HomeAssistant) -> list[str]: """Create multiple persons entities associated with different targets.""" @@ -65,7 +53,7 @@ async def test_person_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -123,7 +111,7 @@ async def test_person_home_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -180,7 +168,7 @@ async def test_person_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), diff --git a/tests/components/scene/test_trigger.py b/tests/components/scene/test_trigger.py index 76f3fa30ccc648..ea9c5f6c63ad31 100644 --- a/tests/components/scene/test_trigger.py +++ b/tests/components/scene/test_trigger.py @@ -1,8 +1,5 @@ """Test scene trigger.""" -from collections.abc import Generator -from unittest.mock import patch - import pytest from homeassistant.const import ( @@ -27,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_scenes(hass: HomeAssistant) -> list[str]: """Create multiple scene entities associated with different targets.""" @@ -57,7 +44,7 @@ async def test_scene_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("scene"), diff --git a/tests/components/siren/test_trigger.py b/tests/components/siren/test_trigger.py index 0977d8bff50198..25f60350ce7b60 100644 --- a/tests/components/siren/test_trigger.py +++ b/tests/components/siren/test_trigger.py @@ -1,8 +1,6 @@ """Test siren triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -25,16 +23,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_sirens(hass: HomeAssistant) -> list[str]: """Create multiple siren entities associated with different targets.""" @@ -61,7 +49,7 @@ async def test_siren_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -119,7 +107,7 @@ async def test_siren_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -176,7 +164,7 @@ async def test_siren_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), diff --git a/tests/components/switch/test_trigger.py b/tests/components/switch/test_trigger.py index c29703aec30455..fe39f058430274 100644 --- a/tests/components/switch/test_trigger.py +++ b/tests/components/switch/test_trigger.py @@ -1,8 +1,6 @@ """Test switch triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -25,16 +23,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_switches(hass: HomeAssistant) -> list[str]: """Create multiple switch entities associated with different targets.""" @@ -61,7 +49,7 @@ async def test_switch_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -119,7 +107,7 @@ async def test_switch_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -176,7 +164,7 @@ async def test_switch_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), diff --git a/tests/components/text/test_trigger.py b/tests/components/text/test_trigger.py index 9902731d7e0ea0..37df0fc33fb7f6 100644 --- a/tests/components/text/test_trigger.py +++ b/tests/components/text/test_trigger.py @@ -1,8 +1,5 @@ """Test text trigger.""" -from collections.abc import Generator -from unittest.mock import patch - import pytest from homeassistant.const import ( @@ -27,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_texts(hass: HomeAssistant) -> list[str]: """Create multiple text entities associated with different targets.""" @@ -57,7 +44,7 @@ async def test_text_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("text"), diff --git a/tests/components/update/test_trigger.py b/tests/components/update/test_trigger.py index 675bd338ff0bfa..b087a6ea400427 100644 --- a/tests/components/update/test_trigger.py +++ b/tests/components/update/test_trigger.py @@ -1,8 +1,6 @@ """Test update triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -25,16 +23,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_updates(hass: HomeAssistant) -> list[str]: """Create multiple update entities associated with different targets.""" @@ -60,7 +48,7 @@ async def test_update_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -113,7 +101,7 @@ async def test_update_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), @@ -165,7 +153,7 @@ async def test_update_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities(DOMAIN), diff --git a/tests/components/vacuum/test_trigger.py b/tests/components/vacuum/test_trigger.py index 3eef5d23f8403f..564505fa361327 100644 --- a/tests/components/vacuum/test_trigger.py +++ b/tests/components/vacuum/test_trigger.py @@ -1,8 +1,6 @@ """Test vacuum triggers.""" -from collections.abc import Generator from typing import Any -from unittest.mock import patch import pytest @@ -26,16 +24,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None: """Stub copying the blueprints to the config folder.""" -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture async def target_vacuums(hass: HomeAssistant) -> list[str]: """Create multiple vacuum entities associated with different targets.""" @@ -64,7 +52,7 @@ async def test_vacuum_triggers_gated_by_labs_flag( ) in caplog.text -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("vacuum"), @@ -132,7 +120,7 @@ async def test_vacuum_state_trigger_behavior_any( service_calls.clear() -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("vacuum"), @@ -199,7 +187,7 @@ async def test_vacuum_state_trigger_behavior_first( assert len(service_calls) == 0 -@pytest.mark.usefixtures("enable_experimental_triggers_conditions") +@pytest.mark.usefixtures("enable_labs_preview_features") @pytest.mark.parametrize( ("trigger_target_config", "entity_id", "entities_in_target"), parametrize_target_entities("vacuum"), diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 81b37a77ef47d9..66c528a127196e 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -1,7 +1,6 @@ """Tests for WebSocket API commands.""" import asyncio -from collections.abc import Generator from copy import deepcopy import io import logging @@ -79,16 +78,6 @@ STATE_KEY_LONG_NAMES = {v: k for k, v in STATE_KEY_SHORT_NAMES.items()} -@pytest.fixture(name="enable_experimental_triggers_conditions") -def enable_experimental_triggers_conditions() -> Generator[None]: - """Enable experimental triggers and conditions.""" - with patch( - "homeassistant.components.labs.async_is_preview_feature_enabled", - return_value=True, - ): - yield - - @pytest.fixture def fake_integration(hass: HomeAssistant): """Set up a mock integration with device automation support.""" @@ -3661,7 +3650,7 @@ async def test_extract_from_target_validation_error( assert "error" in msg -@pytest.mark.usefixtures("enable_experimental_triggers_conditions", "target_entities") +@pytest.mark.usefixtures("enable_labs_preview_features", "target_entities") @patch("annotatedyaml.loader.load_yaml") @pytest.mark.parametrize("automation_component", ["trigger", "condition"]) async def test_get_triggers_conditions_for_target(