diff --git a/tests/common.py b/tests/common.py index 1737eae21e63a..bc770fae2fec5 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1339,18 +1339,6 @@ def mock_import_platform(platform_name: str) -> NoReturn: return integration -def mock_entity_platform( - hass: HomeAssistant, platform_path: str, module: MockPlatform | None -) -> None: - """Mock a entity platform. - - platform_path is in form light.hue. Will create platform - hue.light. - """ - domain, platform_name = platform_path.split(".") - mock_platform(hass, f"{platform_name}.{domain}", module) - - def mock_platform( hass: HomeAssistant, platform_path: str, module: Mock | MockPlatform | None = None ) -> None: diff --git a/tests/components/assist_pipeline/test_select.py b/tests/components/assist_pipeline/test_select.py index 9e70e65e0a813..c4e750e101926 100644 --- a/tests/components/assist_pipeline/test_select.py +++ b/tests/components/assist_pipeline/test_select.py @@ -20,7 +20,7 @@ from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from tests.common import MockConfigEntry, MockPlatform, mock_entity_platform +from tests.common import MockConfigEntry, MockPlatform, mock_platform class SelectPlatform(MockPlatform): @@ -47,7 +47,7 @@ async def async_setup_entry( @pytest.fixture async def init_select(hass: HomeAssistant, init_components) -> ConfigEntry: """Initialize select entity.""" - mock_entity_platform(hass, "select.assist_pipeline", SelectPlatform()) + mock_platform(hass, "assist_pipeline.select", SelectPlatform()) config_entry = MockConfigEntry(domain="assist_pipeline") config_entry.add_to_hass(hass) assert await hass.config_entries.async_forward_entry_setup(config_entry, "select") diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 3cc7ada49ba39..bfee7551cffe4 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -19,8 +19,8 @@ MockConfigEntry, MockModule, MockUser, - mock_entity_platform, mock_integration, + mock_platform, ) from tests.typing import WebSocketGenerator @@ -304,7 +304,7 @@ async def test_reload_entry_in_setup_retry( async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) entry = MockConfigEntry(domain="comp", state=core_ce.ConfigEntryState.SETUP_RETRY) entry.supports_unload = True entry.add_to_hass(hass) @@ -353,7 +353,7 @@ async def test_available_flows( async def test_initialize_flow(hass: HomeAssistant, client) -> None: """Test we can initialize a flow.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): @@ -402,7 +402,7 @@ async def async_step_user(self, user_input=None): async def test_initialize_flow_unmet_dependency(hass: HomeAssistant, client) -> None: """Test unmet dependencies are listed.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) config_schema = vol.Schema({"comp_conf": {"hello": str}}, required=True) mock_integration( @@ -458,7 +458,7 @@ async def async_step_user(self, user_input=None): async def test_abort(hass: HomeAssistant, client) -> None: """Test a flow that aborts.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): @@ -484,7 +484,7 @@ async def test_create_account( hass: HomeAssistant, client, enable_custom_integrations: None ) -> None: """Test a flow that creates an account.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) @@ -542,7 +542,7 @@ async def test_two_step_flow( mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): VERSION = 1 @@ -619,7 +619,7 @@ async def test_continue_flow_unauth( mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): VERSION = 1 @@ -666,7 +666,7 @@ async def test_get_progress_index( ) -> None: """Test querying for the flows that are in progress.""" assert await async_setup_component(hass, "config", {}) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) ws_client = await hass_ws_client(hass) class TestFlow(core_ce.ConfigFlow): @@ -714,7 +714,7 @@ async def test_get_progress_index_unauth( async def test_get_progress_flow(hass: HomeAssistant, client) -> None: """Test we can query the API for same result as we get from init a flow.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): @@ -750,7 +750,7 @@ async def test_get_progress_flow_unauth( hass: HomeAssistant, client, hass_admin_user: MockUser ) -> None: """Test we can can't query the API for result of flow.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): @@ -804,7 +804,7 @@ async def async_step_user(self, user_input=None): return OptionsFlowHandler() mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) MockConfigEntry( domain="test", entry_id="test1", @@ -862,7 +862,7 @@ async def async_step_init(self, user_input=None): return OptionsFlowHandler() mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) MockConfigEntry( domain="test", entry_id="test1", @@ -883,7 +883,7 @@ async def test_two_step_options_flow(hass: HomeAssistant, client) -> None: mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): @staticmethod @@ -950,7 +950,7 @@ async def test_options_flow_with_invalid_data(hass: HomeAssistant, client) -> No mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): @staticmethod @@ -1265,7 +1265,7 @@ async def test_ignore_flow( mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(core_ce.ConfigFlow): VERSION = 1 diff --git a/tests/components/hassio/test_discovery.py b/tests/components/hassio/test_discovery.py index 5c4717fd561c4..0923967a48003 100644 --- a/tests/components/hassio/test_discovery.py +++ b/tests/components/hassio/test_discovery.py @@ -12,12 +12,7 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from tests.common import ( - MockModule, - mock_config_flow, - mock_entity_platform, - mock_integration, -) +from tests.common import MockModule, mock_config_flow, mock_integration, mock_platform from tests.test_util.aiohttp import AiohttpClientMocker @@ -25,7 +20,7 @@ async def mock_mqtt_fixture(hass): """Mock the MQTT integration's config flow.""" mock_integration(hass, MockModule(MQTT_DOMAIN)) - mock_entity_platform(hass, f"config_flow.{MQTT_DOMAIN}", None) + mock_platform(hass, f"{MQTT_DOMAIN}.config_flow", None) class MqttFlow(config_entries.ConfigFlow): """Test flow.""" diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index ed01b70e660b4..50809a11fc1dc 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -34,7 +34,7 @@ MockConfigEntry, async_capture_events, async_fire_mqtt_message, - mock_entity_platform, + mock_platform, ) from tests.typing import ( MqttMockHAClientGenerator, @@ -1499,7 +1499,7 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe( ) -> None: """Check MQTT integration discovery subscribe and unsubscribe.""" mqtt_mock = await mqtt_mock_entry() - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) entry = hass.config_entries.async_entries("mqtt")[0] mqtt_mock().connected = True @@ -1552,7 +1552,7 @@ async def test_mqtt_discovery_unsubscribe_once( ) -> None: """Check MQTT integration discovery unsubscribe once.""" mqtt_mock = await mqtt_mock_entry() - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) entry = hass.config_entries.async_entries("mqtt")[0] mqtt_mock().connected = True diff --git a/tests/helpers/test_config_entry_flow.py b/tests/helpers/test_config_entry_flow.py index 90d8030be79a2..71c81b096cafa 100644 --- a/tests/helpers/test_config_entry_flow.py +++ b/tests/helpers/test_config_entry_flow.py @@ -9,12 +9,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import config_entry_flow -from tests.common import ( - MockConfigEntry, - MockModule, - mock_entity_platform, - mock_integration, -) +from tests.common import MockConfigEntry, MockModule, mock_integration, mock_platform @pytest.fixture @@ -77,7 +72,7 @@ async def test_user_has_confirmation( ) -> None: """Test user requires confirmation to setup.""" discovery_flow_conf["discovered"] = True - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.SOURCE_USER}, data={} @@ -184,7 +179,7 @@ async def test_multiple_discoveries( hass: HomeAssistant, discovery_flow_conf: dict[str, bool] ) -> None: """Test we only create one instance for multiple discoveries.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.SOURCE_DISCOVERY}, data={} @@ -202,7 +197,7 @@ async def test_only_one_in_progress( hass: HomeAssistant, discovery_flow_conf: dict[str, bool] ) -> None: """Test a user initialized one will finish and cancel discovered one.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) # Discovery starts flow result = await hass.config_entries.flow.async_init( @@ -230,7 +225,7 @@ async def test_import_abort_discovery( hass: HomeAssistant, discovery_flow_conf: dict[str, bool] ) -> None: """Test import will finish and cancel discovered one.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) # Discovery starts flow result = await hass.config_entries.flow.async_init( @@ -280,7 +275,7 @@ async def test_ignored_discoveries( hass: HomeAssistant, discovery_flow_conf: dict[str, bool] ) -> None: """Test we can ignore discovered entries.""" - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) result = await hass.config_entries.flow.async_init( "test", context={"source": config_entries.SOURCE_DISCOVERY}, data={} @@ -373,7 +368,7 @@ async def test_webhook_create_cloudhook( async_remove_entry=config_entry_flow.webhook_async_remove_entry, ), ) - mock_entity_platform(hass, "config_flow.test_single", None) + mock_platform(hass, "test_single.config_flow", None) result = await hass.config_entries.flow.async_init( "test_single", context={"source": config_entries.SOURCE_USER} @@ -428,7 +423,7 @@ async def test_webhook_create_cloudhook_aborts_not_connected( async_remove_entry=config_entry_flow.webhook_async_remove_entry, ), ) - mock_entity_platform(hass, "config_flow.test_single", None) + mock_platform(hass, "test_single.config_flow", None) result = await hass.config_entries.flow.async_init( "test_single", context={"source": config_entries.SOURCE_USER} diff --git a/tests/helpers/test_discovery.py b/tests/helpers/test_discovery.py index 2900cb2c09e17..d73bfe8460731 100644 --- a/tests/helpers/test_discovery.py +++ b/tests/helpers/test_discovery.py @@ -9,12 +9,7 @@ from homeassistant.helpers import discovery from homeassistant.helpers.dispatcher import async_dispatcher_send -from tests.common import ( - MockModule, - MockPlatform, - mock_entity_platform, - mock_integration, -) +from tests.common import MockModule, MockPlatform, mock_integration, mock_platform @pytest.fixture @@ -136,7 +131,7 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None): # dependencies are only set in component level # since we are using manifest to hold them mock_integration(hass, MockModule("test_circular", dependencies=["test_component"])) - mock_entity_platform(hass, "switch.test_circular", MockPlatform(setup_platform)) + mock_platform(hass, "test_circular.switch", MockPlatform(setup_platform)) await setup.async_setup_component( hass, diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index b5cda6770c50d..40e2563399248 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -35,8 +35,8 @@ MockModule, MockPlatform, async_fire_time_changed, - mock_entity_platform, mock_integration, + mock_platform, ) _LOGGER = logging.getLogger(__name__) @@ -51,7 +51,7 @@ async def test_setup_loads_platforms(hass: HomeAssistant) -> None: mock_integration(hass, MockModule("test_component", setup=component_setup)) # mock the dependencies mock_integration(hass, MockModule("mod2", dependencies=["test_component"])) - mock_entity_platform(hass, "test_domain.mod2", MockPlatform(platform_setup)) + mock_platform(hass, "mod2.test_domain", MockPlatform(platform_setup)) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -70,8 +70,8 @@ async def test_setup_recovers_when_setup_raises(hass: HomeAssistant) -> None: platform1_setup = Mock(side_effect=Exception("Broken")) platform2_setup = Mock(return_value=None) - mock_entity_platform(hass, "test_domain.mod1", MockPlatform(platform1_setup)) - mock_entity_platform(hass, "test_domain.mod2", MockPlatform(platform2_setup)) + mock_platform(hass, "mod1.test_domain", MockPlatform(platform1_setup)) + mock_platform(hass, "mod2.test_domain", MockPlatform(platform2_setup)) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -130,7 +130,7 @@ def platform_setup( """Test the platform setup.""" add_entities([MockEntity(should_poll=True)]) - mock_entity_platform(hass, "test_domain.platform", MockPlatform(platform_setup)) + mock_platform(hass, "platform.test_domain", MockPlatform(platform_setup)) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -157,7 +157,7 @@ def platform_setup( platform = MockPlatform(platform_setup) - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -205,7 +205,7 @@ async def test_platform_not_ready(hass: HomeAssistant) -> None: """Test that we retry when platform not ready.""" platform1_setup = Mock(side_effect=[PlatformNotReady, PlatformNotReady, None]) mock_integration(hass, MockModule("mod1")) - mock_entity_platform(hass, "test_domain.mod1", MockPlatform(platform1_setup)) + mock_platform(hass, "mod1.test_domain", MockPlatform(platform1_setup)) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -309,7 +309,7 @@ async def test_setup_dependencies_platform(hass: HomeAssistant) -> None: hass, MockModule("test_component", dependencies=["test_component2"]) ) mock_integration(hass, MockModule("test_component2")) - mock_entity_platform(hass, "test_domain.test_component", MockPlatform()) + mock_platform(hass, "test_component.test_domain", MockPlatform()) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -323,9 +323,9 @@ async def test_setup_dependencies_platform(hass: HomeAssistant) -> None: async def test_setup_entry(hass: HomeAssistant) -> None: """Test setup entry calls async_setup_entry on platform.""" mock_setup_entry = AsyncMock(return_value=True) - mock_entity_platform( + mock_platform( hass, - "test_domain.entry_domain", + "entry_domain.test_domain", MockPlatform( async_setup_entry=mock_setup_entry, scan_interval=timedelta(seconds=5) ), @@ -354,9 +354,9 @@ async def test_setup_entry_platform_not_exist(hass: HomeAssistant) -> None: async def test_setup_entry_fails_duplicate(hass: HomeAssistant) -> None: """Test we don't allow setting up a config entry twice.""" mock_setup_entry = AsyncMock(return_value=True) - mock_entity_platform( + mock_platform( hass, - "test_domain.entry_domain", + "entry_domain.test_domain", MockPlatform(async_setup_entry=mock_setup_entry), ) @@ -372,9 +372,9 @@ async def test_setup_entry_fails_duplicate(hass: HomeAssistant) -> None: async def test_unload_entry_resets_platform(hass: HomeAssistant) -> None: """Test unloading an entry removes all entities.""" mock_setup_entry = AsyncMock(return_value=True) - mock_entity_platform( + mock_platform( hass, - "test_domain.entry_domain", + "entry_domain.test_domain", MockPlatform(async_setup_entry=mock_setup_entry), ) @@ -673,7 +673,7 @@ async def test_platforms_shutdown_on_stop(hass: HomeAssistant) -> None: """Test that we shutdown platforms on stop.""" platform1_setup = Mock(side_effect=[PlatformNotReady, PlatformNotReady, None]) mock_integration(hass, MockModule("mod1")) - mock_entity_platform(hass, "test_domain.mod1", MockPlatform(platform1_setup)) + mock_platform(hass, "mod1.test_domain", MockPlatform(platform1_setup)) component = EntityComponent(_LOGGER, DOMAIN, hass) diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index 5702026832354..721114c1a7ba9 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -43,7 +43,7 @@ MockEntityPlatform, MockPlatform, async_fire_time_changed, - mock_entity_platform, + mock_platform, mock_registry, ) @@ -195,7 +195,7 @@ def platform_setup( platform = MockPlatform(platform_setup) platform.SCAN_INTERVAL = timedelta(seconds=30) - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -230,7 +230,7 @@ async def test_platform_warn_slow_setup(hass: HomeAssistant) -> None: """Warn we log when platform setup takes a long time.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -264,7 +264,7 @@ async def setup_platform(*args): platform = MockPlatform(async_setup_platform=setup_platform) component = EntityComponent(_LOGGER, DOMAIN, hass) - mock_entity_platform(hass, "test_domain.test_platform", platform) + mock_platform(hass, "test_platform.test_domain", platform) await component.async_setup({DOMAIN: {"platform": "test_platform"}}) await hass.async_block_till_done() assert len(called) == 1 @@ -298,7 +298,7 @@ async def test_parallel_updates_async_platform(hass: HomeAssistant) -> None: """Test async platform does not have parallel_updates limit by default.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -328,7 +328,7 @@ async def test_parallel_updates_async_platform_with_constant( platform = MockPlatform() platform.PARALLEL_UPDATES = 2 - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -355,7 +355,7 @@ async def test_parallel_updates_sync_platform(hass: HomeAssistant) -> None: """Test sync platform parallel_updates default set to 1.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -381,7 +381,7 @@ async def test_parallel_updates_no_update_method(hass: HomeAssistant) -> None: """Test platform parallel_updates default set to 0.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -403,7 +403,7 @@ async def test_parallel_updates_sync_platform_with_constant( platform = MockPlatform() platform.PARALLEL_UPDATES = 2 - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -431,7 +431,7 @@ async def test_parallel_updates_async_platform_updates_in_parallel( """Test an async platform is updated in parallel.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.async_platform", platform) + mock_platform(hass, "async_platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -479,7 +479,7 @@ async def test_parallel_updates_sync_platform_updates_in_sequence( """Test a sync platform is updated in sequence.""" platform = MockPlatform() - mock_entity_platform(hass, "test_domain.platform", platform) + mock_platform(hass, "platform.test_domain", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) component._platforms = {} @@ -1660,16 +1660,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): platform = MockPlatform(async_setup_entry=async_setup_entry) config_entry = MockConfigEntry(entry_id="super-mock-id") - mock_entity_platform = MockEntityPlatform( + platform = MockEntityPlatform( hass, platform_name=config_entry.domain, platform=platform ) with patch.object(entity_platform, "SLOW_ADD_ENTITY_MAX_WAIT", 0.01), patch.object( entity_platform, "SLOW_ADD_MIN_TIMEOUT", 0.01 ): - assert await mock_entity_platform.async_setup_entry(config_entry) + assert await platform.async_setup_entry(config_entry) await hass.async_block_till_done() - full_name = f"{mock_entity_platform.domain}.{config_entry.domain}" + full_name = f"{platform.domain}.{config_entry.domain}" assert full_name in hass.config.components assert len(hass.states.async_entity_ids()) == 0 assert len(entity_registry.entities) == 1 diff --git a/tests/helpers/test_reload.py b/tests/helpers/test_reload.py index ad3b7ccb243c8..9c3789a35538a 100644 --- a/tests/helpers/test_reload.py +++ b/tests/helpers/test_reload.py @@ -21,8 +21,8 @@ MockModule, MockPlatform, get_fixture_path, - mock_entity_platform, mock_integration, + mock_platform, ) _LOGGER = logging.getLogger(__name__) @@ -42,8 +42,8 @@ async def setup_platform(*args): mock_integration(hass, MockModule(DOMAIN, setup=component_setup)) mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN])) - mock_platform = MockPlatform(async_setup_platform=setup_platform) - mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform) + platform = MockPlatform(async_setup_platform=setup_platform) + mock_platform(hass, f"{PLATFORM}.{DOMAIN}", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -82,8 +82,8 @@ async def setup_platform(*args): mock_integration(hass, MockModule(DOMAIN, setup=component_setup)) mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN])) - mock_platform = MockPlatform(async_setup_platform=setup_platform) - mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform) + platform = MockPlatform(async_setup_platform=setup_platform) + mock_platform(hass, f"{PLATFORM}.{DOMAIN}", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -123,8 +123,8 @@ async def setup_platform(*args): mock_integration(hass, MockModule(DOMAIN, setup=component_setup)) mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN])) - mock_platform = MockPlatform(async_setup_platform=setup_platform) - mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform) + platform = MockPlatform(async_setup_platform=setup_platform) + mock_platform(hass, f"{PLATFORM}.{DOMAIN}", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) @@ -173,8 +173,8 @@ async def async_reset_platform(*args): mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN])) - mock_platform = MockPlatform(async_setup_platform=setup_platform) - mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform) + platform = MockPlatform(async_setup_platform=setup_platform) + mock_platform(hass, f"{PLATFORM}.{DOMAIN}", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) diff --git a/tests/helpers/test_restore_state.py b/tests/helpers/test_restore_state.py index fa0a14b8fbbdd..f01718d6af64c 100644 --- a/tests/helpers/test_restore_state.py +++ b/tests/helpers/test_restore_state.py @@ -31,8 +31,8 @@ MockModule, MockPlatform, async_fire_time_changed, - mock_entity_platform, mock_integration, + mock_platform, ) _LOGGER = logging.getLogger(__name__) @@ -499,8 +499,8 @@ async def async_setup_platform( mock_integration(hass, MockModule(DOMAIN, setup=component_setup)) mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN])) - mock_platform = MockPlatform(async_setup_platform=async_setup_platform) - mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform) + platform = MockPlatform(async_setup_platform=async_setup_platform) + mock_platform(hass, f"{PLATFORM}.{DOMAIN}", platform) component = EntityComponent(_LOGGER, DOMAIN, hass) diff --git a/tests/helpers/test_schema_config_entry_flow.py b/tests/helpers/test_schema_config_entry_flow.py index b069f0cb8f561..58f6a261aefd3 100644 --- a/tests/helpers/test_schema_config_entry_flow.py +++ b/tests/helpers/test_schema_config_entry_flow.py @@ -23,13 +23,7 @@ ) from homeassistant.util.decorator import Registry -from tests.common import ( - MockConfigEntry, - MockModule, - mock_entity_platform, - mock_integration, - mock_platform, -) +from tests.common import MockConfigEntry, MockModule, mock_integration, mock_platform TEST_DOMAIN = "test" @@ -232,7 +226,7 @@ class TestFlow(MockSchemaConfigFlowHandler, domain="test"): options_flow = OPTIONS_FLOW mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) config_entry = MockConfigEntry( data={}, domain="test", @@ -521,7 +515,7 @@ class TestFlow(MockSchemaConfigFlowHandler, domain="test"): options_flow = OPTIONS_FLOW mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) config_entry = MockConfigEntry( data={}, domain="test", @@ -634,7 +628,7 @@ class TestFlow(MockSchemaConfigFlowHandler, domain="test"): options_flow = OPTIONS_FLOW mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) config_entry = MockConfigEntry( data={}, domain="test", @@ -700,7 +694,7 @@ class TestFlow(MockSchemaConfigFlowHandler, domain="test"): options_flow = OPTIONS_FLOW mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) config_entry = MockConfigEntry( data={}, domain="test", diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 555bcbdf6b20f..f5e01e0c97b39 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -23,8 +23,8 @@ MockModule, MockPlatform, get_test_config_dir, - mock_entity_platform, mock_integration, + mock_platform, ) VERSION_PATH = os.path.join(get_test_config_dir(), config_util.VERSION_FILE) @@ -327,7 +327,7 @@ async def async_setup(hass, config): partial_manifest={"after_dependencies": ["after_dep_of_platform_int"]}, ), ) - mock_entity_platform(hass, "light.platform_int", MockPlatform()) + mock_platform(hass, "platform_int.light", MockPlatform()) @callback def continue_loading(_): diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index a3c052971e3d8..f63972c79e861 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -40,8 +40,8 @@ MockPlatform, async_fire_time_changed, mock_config_flow, - mock_entity_platform, mock_integration, + mock_platform, ) from tests.common import async_get_persistent_notifications @@ -92,7 +92,7 @@ async def test_call_setup_entry(hass: HomeAssistant) -> None: async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) with patch("homeassistant.config_entries.support_entry_unload", return_value=True): result = await async_setup_component(hass, "comp", {}) @@ -121,7 +121,7 @@ async def test_call_setup_entry_without_reload_support(hass: HomeAssistant) -> N async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) with patch("homeassistant.config_entries.support_entry_unload", return_value=False): result = await async_setup_component(hass, "comp", {}) @@ -151,7 +151,7 @@ async def test_call_async_migrate_entry(hass: HomeAssistant) -> None: async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) with patch("homeassistant.config_entries.support_entry_unload", return_value=True): result = await async_setup_component(hass, "comp", {}) @@ -181,7 +181,7 @@ async def test_call_async_migrate_entry_failure_false(hass: HomeAssistant) -> No async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) result = await async_setup_component(hass, "comp", {}) assert result @@ -209,7 +209,7 @@ async def test_call_async_migrate_entry_failure_exception(hass: HomeAssistant) - async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) result = await async_setup_component(hass, "comp", {}) assert result @@ -237,7 +237,7 @@ async def test_call_async_migrate_entry_failure_not_bool(hass: HomeAssistant) -> async_migrate_entry=mock_migrate_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) result = await async_setup_component(hass, "comp", {}) assert result @@ -259,7 +259,7 @@ async def test_call_async_migrate_entry_failure_not_supported( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) result = await async_setup_component(hass, "comp", {}) assert result @@ -311,10 +311,10 @@ async def mock_setup_entry_platform( async_remove_entry=mock_remove_entry, ), ) - mock_entity_platform( - hass, "light.test", MockPlatform(async_setup_entry=mock_setup_entry_platform) + mock_platform( + hass, "test.light", MockPlatform(async_setup_entry=mock_setup_entry_platform) ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) MockConfigEntry(domain="test_other", entry_id="test1").add_to_manager(manager) entry = MockConfigEntry(domain="test", entry_id="test2") @@ -371,7 +371,7 @@ async def test_remove_entry_cancels_reauth( mock_setup_entry = AsyncMock(side_effect=ConfigEntryAuthFailed()) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) entry.add_to_hass(hass) await entry.async_setup(hass) @@ -510,7 +510,7 @@ async def test_add_entry_calls_setup_entry( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -610,7 +610,7 @@ async def test_saving_and_loading(hass: HomeAssistant) -> None: "test", async_setup_entry=lambda *args: AsyncMock(return_value=True) ), ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -721,7 +721,7 @@ async def test_discovery_notification( ) -> None: """Test that we create/dismiss a notification when source is discovery.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch.dict(config_entries.HANDLERS): @@ -775,7 +775,7 @@ async def async_step_discovery_confirm(self, discovery_info): async def test_reauth_notification(hass: HomeAssistant) -> None: """Test that we create/dismiss a notification when source is reauth.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch.dict(config_entries.HANDLERS): @@ -842,7 +842,7 @@ async def async_step_reauth_confirm(self, user_input): async def test_discovery_notification_not_created(hass: HomeAssistant) -> None: """Test that we not create a notification when discovery is aborted.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -940,7 +940,7 @@ async def test_setup_raise_not_ready( side_effect=ConfigEntryNotReady("The internet connection is offline") ) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch("homeassistant.config_entries.async_call_later") as mock_call: await entry.async_setup(hass) @@ -978,7 +978,7 @@ async def test_setup_raise_not_ready_from_exception( mock_setup_entry = AsyncMock(side_effect=config_entry_exception) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch("homeassistant.config_entries.async_call_later") as mock_call: await entry.async_setup(hass) @@ -996,7 +996,7 @@ async def test_setup_retrying_during_unload(hass: HomeAssistant) -> None: mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch("homeassistant.config_entries.async_call_later") as mock_call: await entry.async_setup(hass) @@ -1018,7 +1018,7 @@ async def test_setup_retrying_during_unload_before_started(hass: HomeAssistant) mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -1043,7 +1043,7 @@ async def test_setup_does_not_retry_during_shutdown(hass: HomeAssistant) -> None mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) @@ -1081,7 +1081,7 @@ async def mock_async_setup(hass, config): "comp", async_setup=mock_async_setup, async_setup_entry=async_setup_entry ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1114,7 +1114,7 @@ async def test_entry_options( ) -> None: """Test that we can set options on an entry.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager) @@ -1152,7 +1152,7 @@ async def test_entry_options_abort( ) -> None: """Test that we can abort options flow.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager) @@ -1186,7 +1186,7 @@ async def test_entry_options_unknown_config_entry( ) -> None: """Test that we can abort options flow.""" mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) class TestFlow: """Test flow.""" @@ -1218,7 +1218,7 @@ async def test_entry_setup_succeed( hass, MockModule("comp", async_setup=mock_setup, async_setup_entry=mock_setup_entry), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) assert await manager.async_setup(entry.entry_id) assert len(mock_setup.mock_calls) == 1 @@ -1350,7 +1350,7 @@ async def test_entry_reload_succeed( async_unload_entry=async_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) assert await manager.async_reload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 1 @@ -1389,7 +1389,7 @@ async def test_entry_reload_not_loaded( async_unload_entry=async_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) assert await manager.async_reload(entry.entry_id) assert len(async_unload_entry.mock_calls) == 0 @@ -1458,7 +1458,7 @@ async def test_entry_disable_succeed( async_unload_entry=async_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) # Disable assert await manager.async_set_disabled_by( @@ -1495,7 +1495,7 @@ async def test_entry_disable_without_reload_support( async_setup_entry=async_setup_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) # Disable assert not await manager.async_set_disabled_by( @@ -1536,7 +1536,7 @@ async def test_entry_enable_without_reload_support( async_setup_entry=async_setup_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) # Enable assert await manager.async_set_disabled_by(entry.entry_id, None) @@ -1582,7 +1582,7 @@ async def test_init_custom_integration_with_missing_handler( hass, MockModule("hue"), ) - mock_entity_platform(hass, "config_flow.hue", None) + mock_platform(hass, "hue.config_flow", None) with pytest.raises(data_entry_flow.UnknownHandler), patch( "homeassistant.loader.async_get_integration", return_value=integration, @@ -1634,7 +1634,7 @@ async def test_reload_entry_entity_registry_works( async_unload_entry=mock_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) # Only changing disabled_by should update trigger entity_entry = entity_registry.async_get_or_create( @@ -1676,7 +1676,7 @@ async def test_unique_id_persisted( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1724,7 +1724,7 @@ async def test_unique_id_existing_entry( async_remove_entry=async_remove_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1772,7 +1772,7 @@ async def test_entry_id_existing_entry( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1811,7 +1811,7 @@ async def test_unique_id_update_existing_entry_without_reload( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1857,7 +1857,7 @@ async def test_unique_id_update_existing_entry_with_reload( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) updates = {"host": "1.1.1.1"} class TestFlow(config_entries.ConfigFlow): @@ -1923,7 +1923,7 @@ async def test_unique_id_from_discovery_in_setup_retry( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -1991,7 +1991,7 @@ async def test_unique_id_not_update_existing_entry( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2025,7 +2025,7 @@ async def test_unique_id_in_progress( ) -> None: """Test that we abort if there is already a flow in progress with same unique id.""" mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2061,7 +2061,7 @@ async def test_finish_flow_aborts_progress( hass, MockModule("comp", async_setup_entry=AsyncMock(return_value=True)), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2100,7 +2100,7 @@ async def test_unique_id_ignore( """Test that we can ignore flows that are in progress and have a unique ID.""" async_setup_entry = AsyncMock(return_value=False) mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2157,7 +2157,7 @@ async def test_manual_add_overrides_ignored_entry( hass, MockModule("comp"), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2204,7 +2204,7 @@ async def test_manual_add_overrides_ignored_entry_singleton( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2245,7 +2245,7 @@ async def test__async_current_entries_does_not_skip_ignore_non_user( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2282,7 +2282,7 @@ async def test__async_current_entries_explicit_skip_ignore( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2323,7 +2323,7 @@ async def test__async_current_entries_explicit_include_ignore( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2351,7 +2351,7 @@ async def test_unignore_step_form( """Test that we can ignore flows that are in progress and have a unique ID, then rediscover them.""" async_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2398,7 +2398,7 @@ async def test_unignore_create_entry( """Test that we can ignore flows that are in progress and have a unique ID, then rediscover them.""" async_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2448,7 +2448,7 @@ async def test_unignore_default_impl( """Test that resdicovery is a no-op by default.""" async_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2482,7 +2482,7 @@ async def test_partial_flows_hidden( """Test that flows that don't have a cur_step and haven't finished initing are hidden.""" async_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) # A flag to test our assertion that `async_step_discovery` was called and is in its blocked state # This simulates if the step was e.g. doing network i/o @@ -2562,7 +2562,7 @@ async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool: "comp", async_setup=mock_async_setup, async_setup_entry=async_setup_entry ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2616,7 +2616,7 @@ async def mock_async_setup(hass, config): "comp", async_setup=mock_async_setup, async_setup_entry=async_setup_entry ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2682,7 +2682,7 @@ async def mock_async_setup_entry(hass, entry): async_setup_entry=mock_async_setup_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2734,7 +2734,7 @@ async def test_flow_with_default_discovery( hass, MockModule("comp", async_setup_entry=AsyncMock(return_value=True)), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2781,7 +2781,7 @@ async def test_flow_with_default_discovery_with_unique_id( ) -> None: """Test discovery flow using the default discovery is ignored when unique ID is set.""" mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2818,7 +2818,7 @@ async def test_default_discovery_abort_existing_entries( entry.add_to_hass(hass) mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2838,7 +2838,7 @@ async def test_default_discovery_in_progress( ) -> None: """Test that a flow using default discovery can only be triggered once.""" mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2878,7 +2878,7 @@ async def test_default_discovery_abort_on_new_unique_flow( ) -> None: """Test that a flow using default discovery is aborted when a second flow with unique ID is created.""" mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2920,7 +2920,7 @@ async def test_default_discovery_abort_on_user_flow_complete( ) -> None: """Test that a flow using default discovery is aborted when a second flow completes.""" mock_integration(hass, MockModule("comp")) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -2977,7 +2977,7 @@ async def test_flow_same_device_multiple_sources( hass, MockModule("comp", async_setup_entry=AsyncMock(return_value=True)), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -3088,7 +3088,7 @@ async def test_entry_reload_calls_on_unload_listeners( async_unload_entry=async_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) mock_unload_callback = Mock() @@ -3119,7 +3119,7 @@ async def test_setup_raise_entry_error( side_effect=ConfigEntryError("Incompatible firmware version") ) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3156,7 +3156,7 @@ async def _async_update_data(): return True mock_integration(hass, MockModule("test", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3193,7 +3193,7 @@ async def _async_update_data(): return True mock_integration(hass, MockModule("test", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3215,7 +3215,7 @@ async def test_setup_raise_auth_failed( side_effect=ConfigEntryAuthFailed("The password is no longer valid") ) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3267,7 +3267,7 @@ async def _async_update_data(): return True mock_integration(hass, MockModule("test", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3316,7 +3316,7 @@ async def _async_update_data(): return True mock_integration(hass, MockModule("test", async_setup_entry=async_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3361,7 +3361,7 @@ async def test_setup_retrying_during_shutdown(hass: HomeAssistant) -> None: mock_setup_entry = AsyncMock(side_effect=ConfigEntryNotReady) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch("homeassistant.helpers.event.async_call_later") as mock_call: await entry.async_setup(hass) @@ -3444,7 +3444,7 @@ async def test__async_abort_entries_match( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -3530,7 +3530,7 @@ async def test__async_abort_entries_match_options_flow( mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("test_abort", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test_abort", None) + mock_platform(hass, "test_abort.config_flow", None) class TestFlow(config_entries.ConfigFlow): """Test flow.""" @@ -3649,7 +3649,7 @@ async def _async_unload_entry(*args, **kwargs): async_unload_entry=_async_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) tasks = [] for _ in range(15): tasks.append(asyncio.create_task(manager.async_reload(entry.entry_id))) @@ -3689,7 +3689,7 @@ async def mock_unload_entry(hass, entry): async_unload_entry=mock_unload_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) updates = {"host": "1.1.1.1"} hass.async_create_task(hass.config_entries.async_reload(entry.entry_id)) @@ -3752,7 +3752,7 @@ async def test_reauth(hass: HomeAssistant) -> None: mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3812,7 +3812,7 @@ async def test_get_active_flows(hass: HomeAssistant) -> None: entry = MockConfigEntry(title="test_title", domain="test") mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) await entry.async_setup(hass) await hass.async_block_till_done() @@ -3845,7 +3845,7 @@ async def test_async_wait_component_dynamic(hass: HomeAssistant) -> None: mock_setup_entry = AsyncMock(return_value=True) mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry)) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) entry.add_to_hass(hass) @@ -3876,7 +3876,7 @@ async def mock_setup(hass: HomeAssistant, _) -> bool: hass, MockModule("test", async_setup=mock_setup, async_setup_entry=mock_setup_entry), ) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) entry.add_to_hass(hass) @@ -3938,7 +3938,7 @@ async def async_step_reauth(self, data): await asyncio.sleep(1) mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch.dict( config_entries.HANDLERS, {"comp": MockFlowHandler, "test": MockFlowHandler} @@ -4010,7 +4010,7 @@ async def async_setup_preview(hass: HomeAssistant) -> None: preview_calls.append(None) mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) assert len(preview_calls) == 0 @@ -4046,7 +4046,7 @@ async def async_step_user_confirm(self, user_input=None): raise NotImplementedError mock_integration(hass, MockModule("test")) - mock_entity_platform(hass, "config_flow.test", None) + mock_platform(hass, "test.config_flow", None) with patch.dict( config_entries.HANDLERS, {"comp": MockFlowHandler, "test": MockFlowHandler} diff --git a/tests/test_setup.py b/tests/test_setup.py index eb4c645ecb122..8b3b79ac48ce1 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -23,8 +23,8 @@ MockModule, MockPlatform, assert_setup_component, - mock_entity_platform, mock_integration, + mock_platform, ) @@ -90,9 +90,9 @@ async def test_validate_platform_config( hass, MockModule("platform_conf", platform_schema_base=platform_schema_base), ) - mock_entity_platform( + mock_platform( hass, - "platform_conf.whatever", + "whatever.platform_conf", MockPlatform(platform_schema=platform_schema), ) @@ -156,9 +156,9 @@ async def test_validate_platform_config_2( ), ) - mock_entity_platform( + mock_platform( hass, - "platform_conf.whatever", + "whatever.platform_conf", MockPlatform("whatever", platform_schema=platform_schema), ) @@ -185,9 +185,9 @@ async def test_validate_platform_config_3( hass, MockModule("platform_conf", platform_schema=component_schema) ) - mock_entity_platform( + mock_platform( hass, - "platform_conf.whatever", + "whatever.platform_conf", MockPlatform("whatever", platform_schema=platform_schema), ) @@ -213,9 +213,9 @@ async def test_validate_platform_config_4(hass: HomeAssistant) -> None: MockModule("platform_conf", platform_schema_base=component_schema), ) - mock_entity_platform( + mock_platform( hass, - "platform_conf.whatever", + "whatever.platform_conf", MockPlatform(platform_schema=platform_schema), ) @@ -350,7 +350,7 @@ def config_check_setup(hass, config): MockModule("platform_a", setup=config_check_setup, dependencies=["comp_a"]), ) - mock_entity_platform(hass, "switch.platform_a", platform) + mock_platform(hass, "platform_a.switch", platform) await setup.async_setup_component( hass, @@ -367,9 +367,9 @@ async def test_platform_specific_config_validation(hass: HomeAssistant) -> None: mock_setup = Mock(spec_set=True) - mock_entity_platform( + mock_platform( hass, - "switch.platform_a", + "platform_a.switch", MockPlatform(platform_schema=platform_schema, setup_platform=mock_setup), ) @@ -618,7 +618,7 @@ async def mock_async_setup_entry(hass, entry): async_setup_entry=mock_async_setup_entry, ), ) - mock_entity_platform(hass, "config_flow.comp", None) + mock_platform(hass, "comp.config_flow", None) await setup.async_setup_component(hass, "comp", {}) assert calls == [1, 2, 1, 2]