diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 8fe35a20bc4..1ee60b71dad 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1,9 +1,10 @@ """Test the bootstrapping.""" - import asyncio +from collections.abc import Generator import glob import os -from unittest.mock import Mock, patch +from typing import Any +from unittest.mock import AsyncMock, Mock, patch import pytest @@ -27,7 +28,7 @@ VERSION_PATH = os.path.join(get_test_config_dir(), config_util.VERSION_FILE) @pytest.fixture(autouse=True) -def apply_mock_storage(hass_storage): +def apply_mock_storage(hass_storage: dict[str, Any]) -> None: """Apply the storage mock.""" @@ -37,7 +38,7 @@ async def apply_stop_hass(stop_hass: None) -> None: @pytest.fixture(autouse=True) -def mock_http_start_stop(): +def mock_http_start_stop() -> Generator[None, None, None]: """Mock HTTP start and stop.""" with patch( "homeassistant.components.http.start_http_server_and_save_config" @@ -416,8 +417,8 @@ async def test_setup_after_deps_not_present(hass: HomeAssistant) -> None: @pytest.fixture -def mock_is_virtual_env(): - """Mock enable logging.""" +def mock_is_virtual_env() -> Generator[Mock, None, None]: + """Mock is_virtual_env.""" with patch( "homeassistant.bootstrap.is_virtual_env", return_value=False ) as is_virtual_env: @@ -425,14 +426,14 @@ def mock_is_virtual_env(): @pytest.fixture -def mock_enable_logging(): +def mock_enable_logging() -> Generator[Mock, None, None]: """Mock enable logging.""" with patch("homeassistant.bootstrap.async_enable_logging") as enable_logging: yield enable_logging @pytest.fixture -def mock_mount_local_lib_path(): +def mock_mount_local_lib_path() -> Generator[AsyncMock, None, None]: """Mock enable logging.""" with patch( "homeassistant.bootstrap.async_mount_local_lib_path" @@ -441,7 +442,7 @@ def mock_mount_local_lib_path(): @pytest.fixture -def mock_process_ha_config_upgrade(): +def mock_process_ha_config_upgrade() -> Generator[Mock, None, None]: """Mock enable logging.""" with patch( "homeassistant.config.process_ha_config_upgrade" @@ -450,7 +451,7 @@ def mock_process_ha_config_upgrade(): @pytest.fixture -def mock_ensure_config_exists(): +def mock_ensure_config_exists() -> Generator[AsyncMock, None, None]: """Mock enable logging.""" with patch( "homeassistant.config.async_ensure_config_exists", return_value=True @@ -461,13 +462,13 @@ def mock_ensure_config_exists(): @pytest.mark.parametrize("hass_config", [{"browser": {}, "frontend": {}}]) async def test_setup_hass( mock_hass_config: None, - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" verbose = Mock() @@ -511,13 +512,13 @@ async def test_setup_hass( @pytest.mark.parametrize("hass_config", [{"browser": {}, "frontend": {}}]) async def test_setup_hass_takes_longer_than_log_slow_startup( mock_hass_config: None, - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" verbose = Mock() @@ -551,12 +552,12 @@ async def test_setup_hass_takes_longer_than_log_slow_startup( async def test_setup_hass_invalid_yaml( - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, - event_loop, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch( @@ -579,12 +580,12 @@ async def test_setup_hass_invalid_yaml( async def test_setup_hass_config_dir_nonexistent( - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, - event_loop, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" mock_ensure_config_exists.return_value = False @@ -606,12 +607,12 @@ async def test_setup_hass_config_dir_nonexistent( async def test_setup_hass_safe_mode( - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, - event_loop, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch("homeassistant.components.browser.setup") as browser_setup, patch( @@ -641,12 +642,12 @@ async def test_setup_hass_safe_mode( @pytest.mark.parametrize("hass_config", [{"homeassistant": {"non-existing": 1}}]) async def test_setup_hass_invalid_core_config( mock_hass_config: None, - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, - event_loop, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" hass = await bootstrap.async_setup_hass( @@ -679,12 +680,12 @@ async def test_setup_hass_invalid_core_config( ) async def test_setup_safe_mode_if_no_frontend( mock_hass_config: None, - mock_enable_logging, - mock_is_virtual_env, - mock_mount_local_lib_path, - mock_ensure_config_exists, - mock_process_ha_config_upgrade, - event_loop, + mock_enable_logging: Mock, + mock_is_virtual_env: Mock, + mock_mount_local_lib_path: AsyncMock, + mock_ensure_config_exists: AsyncMock, + mock_process_ha_config_upgrade: Mock, + event_loop: asyncio.AbstractEventLoop, ) -> None: """Test we setup safe mode if frontend didn't load.""" verbose = Mock() diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 36fbaff150c..29041730da2 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio +from collections.abc import Generator from datetime import timedelta import logging from typing import Any @@ -26,6 +27,8 @@ from homeassistant.exceptions import ( HomeAssistantError, ) from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.setup import async_set_domains_to_be_loaded, async_setup_component from homeassistant.util import dt @@ -44,7 +47,7 @@ from .common import ( @pytest.fixture(autouse=True) -def mock_handlers(): +def mock_handlers() -> Generator[None, None, None]: """Mock config flows.""" class MockFlowHandler(config_entries.ConfigFlow): @@ -63,7 +66,7 @@ def mock_handlers(): @pytest.fixture -def manager(hass): +def manager(hass: HomeAssistant) -> config_entries.ConfigEntries: """Fixture of a loaded config manager.""" manager = config_entries.ConfigEntries(hass, {}) hass.config_entries = manager @@ -263,15 +266,21 @@ async def test_call_async_migrate_entry_failure_not_supported( assert not entry.supports_unload -async def test_remove_entry(hass: HomeAssistant, manager) -> None: +async def test_remove_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can remove an entry.""" - async def mock_setup_entry(hass, entry): + async def mock_setup_entry( + hass: HomeAssistant, entry: config_entries.ConfigEntry + ) -> bool: """Mock setting up entry.""" hass.config_entries.async_setup_platforms(entry, ["light"]) return True - async def mock_unload_entry(hass, entry): + async def mock_unload_entry( + hass: HomeAssistant, entry: config_entries.ConfigEntry + ) -> bool: """Mock unloading an entry.""" result = await hass.config_entries.async_unload_platforms(entry, ["light"]) assert result @@ -281,7 +290,11 @@ async def test_remove_entry(hass: HomeAssistant, manager) -> None: entity = MockEntity(unique_id="1234", name="Test Entity") - async def mock_setup_entry_platform(hass, entry, async_add_entities): + async def mock_setup_entry_platform( + hass: HomeAssistant, + entry: config_entries.ConfigEntry, + async_add_entities: AddEntitiesCallback, + ) -> None: """Mock setting up platform.""" async_add_entities([entity]) @@ -347,7 +360,9 @@ async def test_remove_entry(hass: HomeAssistant, manager) -> None: assert not entity_entry_list -async def test_remove_entry_cancels_reauth(hass: HomeAssistant, manager) -> None: +async def test_remove_entry_cancels_reauth( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Tests that removing a config entry, also aborts existing reauth flows.""" entry = MockConfigEntry(title="test_title", domain="test") @@ -372,7 +387,7 @@ async def test_remove_entry_cancels_reauth(hass: HomeAssistant, manager) -> None async def test_remove_entry_handles_callback_error( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that exceptions in the remove callback are handled.""" mock_setup_entry = AsyncMock(return_value=True) @@ -406,7 +421,9 @@ async def test_remove_entry_handles_callback_error( assert [item.entry_id for item in manager.async_entries()] == [] -async def test_remove_entry_raises(hass: HomeAssistant, manager) -> None: +async def test_remove_entry_raises( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test if a component raises while removing entry.""" async def mock_unload_entry(hass, entry): @@ -433,7 +450,9 @@ async def test_remove_entry_raises(hass: HomeAssistant, manager) -> None: assert [item.entry_id for item in manager.async_entries()] == ["test1", "test3"] -async def test_remove_entry_if_not_loaded(hass: HomeAssistant, manager) -> None: +async def test_remove_entry_if_not_loaded( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can remove an entry that is not loaded.""" mock_unload_entry = AsyncMock(return_value=True) @@ -458,7 +477,7 @@ async def test_remove_entry_if_not_loaded(hass: HomeAssistant, manager) -> None: async def test_remove_entry_if_integration_deleted( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can remove an entry when the integration is deleted.""" mock_unload_entry = AsyncMock(return_value=True) @@ -481,7 +500,9 @@ async def test_remove_entry_if_integration_deleted( assert len(mock_unload_entry.mock_calls) == 0 -async def test_add_entry_calls_setup_entry(hass: HomeAssistant, manager) -> None: +async def test_add_entry_calls_setup_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test we call setup_config_entry.""" mock_setup_entry = AsyncMock(return_value=True) @@ -510,7 +531,7 @@ async def test_add_entry_calls_setup_entry(hass: HomeAssistant, manager) -> None assert p_entry.data == {"token": "supersecret"} -async def test_entries_gets_entries(manager) -> None: +async def test_entries_gets_entries(manager: config_entries.ConfigEntries) -> None: """Test entries are filtered by domain.""" MockConfigEntry(domain="test").add_to_manager(manager) entry1 = MockConfigEntry(domain="test2") @@ -521,7 +542,9 @@ async def test_entries_gets_entries(manager) -> None: assert manager.async_entries("test2") == [entry1, entry2] -async def test_domains_gets_domains_uniques(manager) -> None: +async def test_domains_gets_domains_uniques( + manager: config_entries.ConfigEntries, +) -> None: """Test we only return each domain once.""" MockConfigEntry(domain="test").add_to_manager(manager) MockConfigEntry(domain="test2").add_to_manager(manager) @@ -532,7 +555,9 @@ async def test_domains_gets_domains_uniques(manager) -> None: assert manager.async_domains() == ["test", "test2", "test3"] -async def test_domains_gets_domains_excludes_ignore_and_disabled(manager) -> None: +async def test_domains_gets_domains_excludes_ignore_and_disabled( + manager: config_entries.ConfigEntries, +) -> None: """Test we only return each domain once.""" MockConfigEntry(domain="test").add_to_manager(manager) MockConfigEntry(domain="test2").add_to_manager(manager) @@ -838,7 +863,7 @@ async def test_loading_default_config(hass: HomeAssistant) -> None: assert len(manager.async_entries()) == 0 -async def test_updating_entry_data(manager) -> None: +async def test_updating_entry_data(manager: config_entries.ConfigEntries) -> None: """Test that we can update an entry data.""" entry = MockConfigEntry( domain="test", @@ -854,7 +879,9 @@ async def test_updating_entry_data(manager) -> None: assert entry.data == {"second": True} -async def test_updating_entry_system_options(manager) -> None: +async def test_updating_entry_system_options( + manager: config_entries.ConfigEntries, +) -> None: """Test that we can update an entry data.""" entry = MockConfigEntry( domain="test", @@ -876,7 +903,7 @@ async def test_updating_entry_system_options(manager) -> None: async def test_update_entry_options_and_trigger_listener( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can update entry options and trigger listener.""" entry = MockConfigEntry(domain="test", options={"first": True}) @@ -1070,7 +1097,9 @@ async def test_create_entry_options(hass: HomeAssistant) -> None: assert entries[0].options == {"example": "option"} -async def test_entry_options(hass: HomeAssistant, manager) -> None: +async def test_entry_options( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can set options on an entry.""" entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager) @@ -1104,7 +1133,9 @@ async def test_entry_options(hass: HomeAssistant, manager) -> None: assert entry.options == {"second": True} -async def test_entry_options_abort(hass: HomeAssistant, manager) -> None: +async def test_entry_options_abort( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can abort options flow.""" entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager) @@ -1134,7 +1165,9 @@ async def test_entry_options_abort(hass: HomeAssistant, manager) -> None: ) -async def test_entry_setup_succeed(hass: HomeAssistant, manager) -> None: +async def test_entry_setup_succeed( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can setup an entry.""" entry = MockConfigEntry( domain="comp", state=config_entries.ConfigEntryState.NOT_LOADED @@ -1166,7 +1199,11 @@ async def test_entry_setup_succeed(hass: HomeAssistant, manager) -> None: config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) -async def test_entry_setup_invalid_state(hass: HomeAssistant, manager, state) -> None: +async def test_entry_setup_invalid_state( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + state: config_entries.ConfigEntryState, +) -> None: """Test that we cannot setup an entry with invalid state.""" entry = MockConfigEntry(domain="comp", state=state) entry.add_to_hass(hass) @@ -1187,7 +1224,9 @@ async def test_entry_setup_invalid_state(hass: HomeAssistant, manager, state) -> assert entry.state is state -async def test_entry_unload_succeed(hass: HomeAssistant, manager) -> None: +async def test_entry_unload_succeed( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can unload an entry.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) @@ -1209,7 +1248,11 @@ async def test_entry_unload_succeed(hass: HomeAssistant, manager) -> None: config_entries.ConfigEntryState.SETUP_RETRY, ), ) -async def test_entry_unload_failed_to_load(hass: HomeAssistant, manager, state) -> None: +async def test_entry_unload_failed_to_load( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + state: config_entries.ConfigEntryState, +) -> None: """Test that we can unload an entry.""" entry = MockConfigEntry(domain="comp", state=state) entry.add_to_hass(hass) @@ -1230,7 +1273,11 @@ async def test_entry_unload_failed_to_load(hass: HomeAssistant, manager, state) config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) -async def test_entry_unload_invalid_state(hass: HomeAssistant, manager, state) -> None: +async def test_entry_unload_invalid_state( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + state: config_entries.ConfigEntryState, +) -> None: """Test that we cannot unload an entry with invalid state.""" entry = MockConfigEntry(domain="comp", state=state) entry.add_to_hass(hass) @@ -1246,7 +1293,9 @@ async def test_entry_unload_invalid_state(hass: HomeAssistant, manager, state) - assert entry.state is state -async def test_entry_reload_succeed(hass: HomeAssistant, manager) -> None: +async def test_entry_reload_succeed( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can reload an entry.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) @@ -1281,7 +1330,11 @@ async def test_entry_reload_succeed(hass: HomeAssistant, manager) -> None: config_entries.ConfigEntryState.SETUP_RETRY, ), ) -async def test_entry_reload_not_loaded(hass: HomeAssistant, manager, state) -> None: +async def test_entry_reload_not_loaded( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + state: config_entries.ConfigEntryState, +) -> None: """Test that we can reload an entry.""" entry = MockConfigEntry(domain="comp", state=state) entry.add_to_hass(hass) @@ -1315,7 +1368,11 @@ async def test_entry_reload_not_loaded(hass: HomeAssistant, manager, state) -> N config_entries.ConfigEntryState.FAILED_UNLOAD, ), ) -async def test_entry_reload_error(hass: HomeAssistant, manager, state) -> None: +async def test_entry_reload_error( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + state: config_entries.ConfigEntryState, +) -> None: """Test that we can reload an entry.""" entry = MockConfigEntry(domain="comp", state=state) entry.add_to_hass(hass) @@ -1344,7 +1401,9 @@ async def test_entry_reload_error(hass: HomeAssistant, manager, state) -> None: assert entry.state == state -async def test_entry_disable_succeed(hass: HomeAssistant, manager) -> None: +async def test_entry_disable_succeed( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can disable an entry.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) @@ -1382,7 +1441,7 @@ async def test_entry_disable_succeed(hass: HomeAssistant, manager) -> None: async def test_entry_disable_without_reload_support( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can disable an entry without reload support.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) @@ -1421,7 +1480,7 @@ async def test_entry_disable_without_reload_support( async def test_entry_enable_without_reload_support( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can disable an entry without reload support.""" entry = MockConfigEntry( @@ -1550,7 +1609,9 @@ async def test_reload_entry_entity_registry_works( assert len(mock_unload_entry.mock_calls) == 2 -async def test_unique_id_persisted(hass: HomeAssistant, manager) -> None: +async def test_unique_id_persisted( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that a unique ID is stored in the config entry.""" mock_setup_entry = AsyncMock(return_value=True) @@ -1579,7 +1640,9 @@ async def test_unique_id_persisted(hass: HomeAssistant, manager) -> None: assert p_entry.unique_id == "mock-unique-id" -async def test_unique_id_existing_entry(hass: HomeAssistant, manager) -> None: +async def test_unique_id_existing_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we remove an entry if there already is an entry with unique ID.""" hass.config.components.add("comp") MockConfigEntry( @@ -1632,7 +1695,9 @@ async def test_unique_id_existing_entry(hass: HomeAssistant, manager) -> None: assert len(async_remove_entry.mock_calls) == 1 -async def test_entry_id_existing_entry(hass: HomeAssistant, manager) -> None: +async def test_entry_id_existing_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we throw when the entry id collides.""" collide_entry_id = "collide" hass.config.components.add("comp") @@ -1670,7 +1735,7 @@ async def test_entry_id_existing_entry(hass: HomeAssistant, manager) -> None: async def test_unique_id_update_existing_entry_without_reload( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we update an entry if there already is an entry with unique ID.""" hass.config.components.add("comp") @@ -1716,7 +1781,7 @@ async def test_unique_id_update_existing_entry_without_reload( async def test_unique_id_update_existing_entry_with_reload( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we update an entry if there already is an entry with unique ID and we reload on changes.""" hass.config.components.add("comp") @@ -1780,7 +1845,7 @@ async def test_unique_id_update_existing_entry_with_reload( async def test_unique_id_from_discovery_in_setup_retry( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we reload when in a setup retry state from discovery.""" hass.config.components.add("comp") @@ -1851,7 +1916,7 @@ async def test_unique_id_from_discovery_in_setup_retry( async def test_unique_id_not_update_existing_entry( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we do not update an entry if existing entry has the data.""" hass.config.components.add("comp") @@ -1895,7 +1960,9 @@ async def test_unique_id_not_update_existing_entry( assert len(async_reload.mock_calls) == 0 -async def test_unique_id_in_progress(hass: HomeAssistant, manager) -> None: +async def test_unique_id_in_progress( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> 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) @@ -1926,7 +1993,9 @@ async def test_unique_id_in_progress(hass: HomeAssistant, manager) -> None: assert result2["reason"] == "already_in_progress" -async def test_finish_flow_aborts_progress(hass: HomeAssistant, manager) -> None: +async def test_finish_flow_aborts_progress( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that when finishing a flow, we abort other flows in progress with unique ID.""" mock_integration( hass, @@ -1965,7 +2034,9 @@ async def test_finish_flow_aborts_progress(hass: HomeAssistant, manager) -> None assert len(hass.config_entries.flow.async_progress()) == 0 -async def test_unique_id_ignore(hass: HomeAssistant, manager) -> None: +async def test_unique_id_ignore( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """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)) @@ -2008,7 +2079,9 @@ async def test_unique_id_ignore(hass: HomeAssistant, manager) -> None: assert entry.title == "Ignored Title" -async def test_manual_add_overrides_ignored_entry(hass: HomeAssistant, manager) -> None: +async def test_manual_add_overrides_ignored_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test that we can ignore manually add entry, overriding ignored entry.""" hass.config.components.add("comp") entry = MockConfigEntry( @@ -2054,7 +2127,7 @@ async def test_manual_add_overrides_ignored_entry(hass: HomeAssistant, manager) async def test_manual_add_overrides_ignored_entry_singleton( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can ignore manually add entry, overriding ignored entry.""" hass.config.components.add("comp") @@ -2095,7 +2168,7 @@ async def test_manual_add_overrides_ignored_entry_singleton( async def test__async_current_entries_does_not_skip_ignore_non_user( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that _async_current_entries does not skip ignore by default for non user step.""" hass.config.components.add("comp") @@ -2132,7 +2205,7 @@ async def test__async_current_entries_does_not_skip_ignore_non_user( async def test__async_current_entries_explicit_skip_ignore( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that _async_current_entries can explicitly include ignore.""" hass.config.components.add("comp") @@ -2173,7 +2246,7 @@ async def test__async_current_entries_explicit_skip_ignore( async def test__async_current_entries_explicit_include_ignore( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that _async_current_entries can explicitly include ignore.""" hass.config.components.add("comp") @@ -2209,7 +2282,9 @@ async def test__async_current_entries_explicit_include_ignore( assert len(mock_setup_entry.mock_calls) == 0 -async def test_unignore_step_form(hass: HomeAssistant, manager) -> None: +async def test_unignore_step_form( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """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)) @@ -2254,7 +2329,9 @@ async def test_unignore_step_form(hass: HomeAssistant, manager) -> None: assert len(hass.config_entries.async_entries("comp")) == 0 -async def test_unignore_create_entry(hass: HomeAssistant, manager) -> None: +async def test_unignore_create_entry( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """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)) @@ -2302,7 +2379,9 @@ async def test_unignore_create_entry(hass: HomeAssistant, manager) -> None: assert len(hass.config_entries.flow.async_progress_by_handler("comp")) == 0 -async def test_unignore_default_impl(hass: HomeAssistant, manager) -> None: +async def test_unignore_default_impl( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """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)) @@ -2334,7 +2413,9 @@ async def test_unignore_default_impl(hass: HomeAssistant, manager) -> None: assert len(hass.config_entries.flow.async_progress()) == 0 -async def test_partial_flows_hidden(hass: HomeAssistant, manager) -> None: +async def test_partial_flows_hidden( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """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)) @@ -2395,7 +2476,7 @@ async def test_partial_flows_hidden(hass: HomeAssistant, manager) -> None: async def test_async_setup_init_entry(hass: HomeAssistant) -> None: """Test a config entry being initialized during integration setup.""" - async def mock_async_setup(hass, config): + async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Mock setup.""" hass.async_create_task( hass.config_entries.flow.async_init( @@ -2576,7 +2657,9 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None: ), ) async def test_flow_with_default_discovery( - hass: HomeAssistant, manager, discovery_source + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + discovery_source: tuple[str, dict | BaseServiceInfo], ) -> None: """Test that finishing a default discovery flow removes the unique ID in the entry.""" mock_integration( @@ -2626,7 +2709,7 @@ async def test_flow_with_default_discovery( async def test_flow_with_default_discovery_with_unique_id( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test discovery flow using the default discovery is ignored when unique ID is set.""" mock_integration(hass, MockModule("comp")) @@ -2656,7 +2739,7 @@ async def test_flow_with_default_discovery_with_unique_id( async def test_default_discovery_abort_existing_entries( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that a flow without discovery implementation aborts when a config entry exists.""" hass.config.components.add("comp") @@ -2679,7 +2762,9 @@ async def test_default_discovery_abort_existing_entries( assert result["reason"] == "already_configured" -async def test_default_discovery_in_progress(hass: HomeAssistant, manager) -> None: +async def test_default_discovery_in_progress( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> 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) @@ -2715,7 +2800,7 @@ async def test_default_discovery_in_progress(hass: HomeAssistant, manager) -> No async def test_default_discovery_abort_on_new_unique_flow( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that a flow using default discovery is aborted when a second flow with unique ID is created.""" mock_integration(hass, MockModule("comp")) @@ -2754,7 +2839,7 @@ async def test_default_discovery_abort_on_new_unique_flow( async def test_default_discovery_abort_on_user_flow_complete( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that a flow using default discovery is aborted when a second flow completes.""" mock_integration(hass, MockModule("comp")) @@ -2804,7 +2889,9 @@ async def test_default_discovery_abort_on_user_flow_complete( assert len(flows) == 0 -async def test_flow_same_device_multiple_sources(hass: HomeAssistant, manager) -> None: +async def test_flow_same_device_multiple_sources( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test discovery of the same devices from multiple discovery sources.""" mock_integration( hass, @@ -2872,7 +2959,9 @@ async def test_flow_same_device_multiple_sources(hass: HomeAssistant, manager) - assert entry.unique_id == "thisid" -async def test_updating_entry_with_and_without_changes(manager) -> None: +async def test_updating_entry_with_and_without_changes( + manager: config_entries.ConfigEntries, +) -> None: """Test that we can update an entry data.""" entry = MockConfigEntry( domain="test", @@ -2900,7 +2989,7 @@ async def test_updating_entry_with_and_without_changes(manager) -> None: async def test_entry_reload_calls_on_unload_listeners( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test reload calls the on unload listeners.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) @@ -3239,7 +3328,10 @@ async def test_setup_retrying_during_shutdown(hass: HomeAssistant) -> None: ], ) async def test__async_abort_entries_match( - hass: HomeAssistant, manager, matchers, reason + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + matchers: dict[str, str], + reason: str, ) -> None: """Test aborting if matching config entries exist.""" MockConfigEntry( @@ -3336,7 +3428,9 @@ async def test_deprecated_disabled_by_str_ctor( async def test_deprecated_disabled_by_str_set( - hass: HomeAssistant, manager, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + caplog: pytest.LogCaptureFixture, ) -> None: """Test deprecated str set disabled_by enumizes and logs a warning.""" entry = MockConfigEntry() @@ -3348,7 +3442,9 @@ async def test_deprecated_disabled_by_str_set( assert " str for config entry disabled_by. This is deprecated " in caplog.text -async def test_entry_reload_concurrency(hass: HomeAssistant, manager) -> None: +async def test_entry_reload_concurrency( + hass: HomeAssistant, manager: config_entries.ConfigEntries +) -> None: """Test multiple reload calls do not cause a reload race.""" entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) entry.add_to_hass(hass) @@ -3457,7 +3553,7 @@ async def test_unique_id_update_while_setup_in_progress( async def test_disallow_entry_reload_with_setup_in_progresss( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test we do not allow reload while the config entry is still setting up.""" entry = MockConfigEntry( @@ -3638,7 +3734,7 @@ async def test_options_flow_options_not_mutated() -> None: async def test_initializing_flows_canceled_on_shutdown( - hass: HomeAssistant, manager + hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that initializing flows are canceled on shutdown."""