Add missing hass type in tests/*.py (#124048)
This commit is contained in:
parent
69843e9ac4
commit
ba3872ff87
6 changed files with 74 additions and 50 deletions
|
@ -52,7 +52,7 @@ from homeassistant.components import device_automation, persistent_notification
|
||||||
from homeassistant.components.device_automation import ( # noqa: F401
|
from homeassistant.components.device_automation import ( # noqa: F401
|
||||||
_async_get_device_automation_capabilities as async_get_device_automation_capabilities,
|
_async_get_device_automation_capabilities as async_get_device_automation_capabilities,
|
||||||
)
|
)
|
||||||
from homeassistant.config import async_process_component_config
|
from homeassistant.config import IntegrationConfigInfo, async_process_component_config
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow
|
from homeassistant.config_entries import ConfigEntry, ConfigFlow
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_DEFAULT_NAME,
|
DEVICE_DEFAULT_NAME,
|
||||||
|
@ -439,14 +439,16 @@ mock_service = threadsafe_callback_factory(async_mock_service)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_mock_intent(hass, intent_typ):
|
def async_mock_intent(hass: HomeAssistant, intent_typ: str) -> list[intent.Intent]:
|
||||||
"""Set up a fake intent handler."""
|
"""Set up a fake intent handler."""
|
||||||
intents = []
|
intents: list[intent.Intent] = []
|
||||||
|
|
||||||
class MockIntentHandler(intent.IntentHandler):
|
class MockIntentHandler(intent.IntentHandler):
|
||||||
intent_type = intent_typ
|
intent_type = intent_typ
|
||||||
|
|
||||||
async def async_handle(self, intent_obj):
|
async def async_handle(
|
||||||
|
self, intent_obj: intent.Intent
|
||||||
|
) -> intent.IntentResponse:
|
||||||
"""Handle the intent."""
|
"""Handle the intent."""
|
||||||
intents.append(intent_obj)
|
intents.append(intent_obj)
|
||||||
return intent_obj.create_response()
|
return intent_obj.create_response()
|
||||||
|
@ -1159,7 +1161,12 @@ def assert_setup_component(count, domain=None):
|
||||||
"""
|
"""
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
async def mock_psc(hass, config_input, integration, component=None):
|
async def mock_psc(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_input: ConfigType,
|
||||||
|
integration: loader.Integration,
|
||||||
|
component: loader.ComponentProtocol | None = None,
|
||||||
|
) -> IntegrationConfigInfo:
|
||||||
"""Mock the prepare_setup_component to capture config."""
|
"""Mock the prepare_setup_component to capture config."""
|
||||||
domain_input = integration.domain
|
domain_input = integration.domain
|
||||||
integration_config_info = await async_process_component_config(
|
integration_config_info = await async_process_component_config(
|
||||||
|
|
|
@ -213,7 +213,7 @@ async def test_setup_after_deps_all_present(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ async def test_setup_after_deps_in_stage_1_ignored(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ async def test_setup_after_deps_manifests_are_loaded_even_if_not_setup(
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ async def test_setup_frontend_before_recorder(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ async def test_setup_after_deps_via_platform(hass: HomeAssistant) -> None:
|
||||||
after_dep_event = asyncio.Event()
|
after_dep_event = asyncio.Event()
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
if domain == "after_dep_of_platform_int":
|
if domain == "after_dep_of_platform_int":
|
||||||
await after_dep_event.wait()
|
await after_dep_event.wait()
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ async def test_setup_after_deps_not_trigger_load(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -559,7 +559,7 @@ async def test_setup_after_deps_not_present(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -969,7 +969,7 @@ async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
await asyncio.sleep(0.05)
|
await asyncio.sleep(0.05)
|
||||||
|
|
||||||
|
@ -1029,7 +1029,7 @@ async def test_warning_logged_on_wrap_up_timeout(
|
||||||
task: asyncio.Task | None = None
|
task: asyncio.Task | None = None
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
nonlocal task
|
nonlocal task
|
||||||
|
|
||||||
async def _not_marked_background_task():
|
async def _not_marked_background_task():
|
||||||
|
@ -1067,7 +1067,7 @@ async def test_tasks_logged_that_block_stage_1(
|
||||||
"""Test we log tasks that delay stage 1 startup."""
|
"""Test we log tasks that delay stage 1 startup."""
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
async def _not_marked_background_task():
|
async def _not_marked_background_task():
|
||||||
await asyncio.sleep(0.2)
|
await asyncio.sleep(0.2)
|
||||||
|
|
||||||
|
@ -1110,7 +1110,7 @@ async def test_tasks_logged_that_block_stage_2(
|
||||||
done_future = hass.loop.create_future()
|
done_future = hass.loop.create_future()
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
async def _not_marked_background_task():
|
async def _not_marked_background_task():
|
||||||
await done_future
|
await done_future
|
||||||
|
|
||||||
|
@ -1452,7 +1452,7 @@ async def test_setup_does_base_platforms_first(hass: HomeAssistant) -> None:
|
||||||
order = []
|
order = []
|
||||||
|
|
||||||
def gen_domain_setup(domain):
|
def gen_domain_setup(domain):
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
order.append(domain)
|
order.append(domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ from homeassistant.core import (
|
||||||
DOMAIN as HOMEASSISTANT_DOMAIN,
|
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||||
ConfigSource,
|
ConfigSource,
|
||||||
HomeAssistant,
|
HomeAssistant,
|
||||||
|
State,
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import ConfigValidationError, HomeAssistantError
|
from homeassistant.exceptions import ConfigValidationError, HomeAssistantError
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
|
@ -579,7 +580,7 @@ def test_customize_glob_is_ordered() -> None:
|
||||||
assert isinstance(conf["customize_glob"], OrderedDict)
|
assert isinstance(conf["customize_glob"], OrderedDict)
|
||||||
|
|
||||||
|
|
||||||
async def _compute_state(hass, config):
|
async def _compute_state(hass: HomeAssistant, config: dict[str, Any]) -> State | None:
|
||||||
await config_util.async_process_ha_core_config(hass, config)
|
await config_util.async_process_ha_core_config(hass, config)
|
||||||
|
|
||||||
entity = Entity()
|
entity = Entity()
|
||||||
|
|
|
@ -18,6 +18,7 @@ from syrupy.assertion import SnapshotAssertion
|
||||||
from homeassistant import config_entries, data_entry_flow, loader
|
from homeassistant import config_entries, data_entry_flow, loader
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.components.hassio import HassioServiceInfo
|
from homeassistant.components.hassio import HassioServiceInfo
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_COMPONENT_LOADED,
|
EVENT_COMPONENT_LOADED,
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
|
@ -104,12 +105,12 @@ async def test_setup_race_only_setup_once(hass: HomeAssistant) -> None:
|
||||||
fast_config_entry_setup_future = hass.loop.create_future()
|
fast_config_entry_setup_future = hass.loop.create_future()
|
||||||
slow_setup_future = hass.loop.create_future()
|
slow_setup_future = hass.loop.create_future()
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Mock setup."""
|
"""Mock setup."""
|
||||||
await slow_setup_future
|
await slow_setup_future
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry."""
|
"""Mock setup entry."""
|
||||||
slow = entry.data["slow"]
|
slow = entry.data["slow"]
|
||||||
if slow:
|
if slow:
|
||||||
|
@ -122,7 +123,7 @@ async def test_setup_race_only_setup_once(hass: HomeAssistant) -> None:
|
||||||
await fast_config_entry_setup_future
|
await fast_config_entry_setup_future
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock unload entry."""
|
"""Mock unload entry."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -582,7 +583,7 @@ async def test_remove_entry_raises(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if a component raises while removing entry."""
|
"""Test if a component raises while removing entry."""
|
||||||
|
|
||||||
async def mock_unload_entry(hass, entry):
|
async def mock_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock unload entry function."""
|
"""Mock unload entry function."""
|
||||||
raise Exception("BROKEN") # noqa: TRY002
|
raise Exception("BROKEN") # noqa: TRY002
|
||||||
|
|
||||||
|
@ -1326,7 +1327,7 @@ async def test_update_entry_options_and_trigger_listener(
|
||||||
entry.add_to_manager(manager)
|
entry.add_to_manager(manager)
|
||||||
update_listener_calls = []
|
update_listener_calls = []
|
||||||
|
|
||||||
async def update_listener(hass, entry):
|
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Test function."""
|
"""Test function."""
|
||||||
assert entry.options == {"second": True}
|
assert entry.options == {"second": True}
|
||||||
update_listener_calls.append(None)
|
update_listener_calls.append(None)
|
||||||
|
@ -1491,7 +1492,7 @@ async def test_reload_during_setup_retrying_waits(hass: HomeAssistant) -> None:
|
||||||
load_attempts = []
|
load_attempts = []
|
||||||
sleep_duration = 0
|
sleep_duration = 0
|
||||||
|
|
||||||
async def _mock_setup_entry(hass, entry):
|
async def _mock_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry."""
|
"""Mock setup entry."""
|
||||||
nonlocal sleep_duration
|
nonlocal sleep_duration
|
||||||
await asyncio.sleep(sleep_duration)
|
await asyncio.sleep(sleep_duration)
|
||||||
|
@ -1536,7 +1537,7 @@ async def test_create_entry_options(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test a config entry being created with options."""
|
"""Test a config entry being created with options."""
|
||||||
|
|
||||||
async def mock_async_setup(hass, config):
|
async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Mock setup."""
|
"""Mock setup."""
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
|
@ -3234,7 +3235,7 @@ async def test_async_setup_init_entry_completes_before_loaded_event_fires(
|
||||||
"""Test a config entry being initialized during integration setup before the loaded event fires."""
|
"""Test a config entry being initialized during integration setup before the loaded event fires."""
|
||||||
load_events = async_capture_events(hass, EVENT_COMPONENT_LOADED)
|
load_events = async_capture_events(hass, EVENT_COMPONENT_LOADED)
|
||||||
|
|
||||||
async def mock_async_setup(hass, config):
|
async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Mock setup."""
|
"""Mock setup."""
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
|
@ -3292,7 +3293,7 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None:
|
||||||
entry = MockConfigEntry(domain="comp", data={"value": "initial"})
|
entry = MockConfigEntry(domain="comp", data={"value": "initial"})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
async def mock_async_setup(hass, config):
|
async def mock_async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Mock setup."""
|
"""Mock setup."""
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
|
@ -3303,7 +3304,7 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def mock_async_setup_entry(hass, entry):
|
async def mock_async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setting up an entry."""
|
"""Mock setting up an entry."""
|
||||||
assert entry.data["value"] == "updated"
|
assert entry.data["value"] == "updated"
|
||||||
return True
|
return True
|
||||||
|
@ -3791,7 +3792,7 @@ async def test_setup_raise_entry_error_from_first_coordinator_update(
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry with a simple coordinator."""
|
"""Mock setup entry with a simple coordinator."""
|
||||||
|
|
||||||
async def _async_update_data():
|
async def _async_update_data():
|
||||||
|
@ -3831,7 +3832,7 @@ async def test_setup_not_raise_entry_error_from_future_coordinator_update(
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry with a simple coordinator."""
|
"""Mock setup entry with a simple coordinator."""
|
||||||
|
|
||||||
async def _async_update_data():
|
async def _async_update_data():
|
||||||
|
@ -3910,7 +3911,7 @@ async def test_setup_raise_auth_failed_from_first_coordinator_update(
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry with a simple coordinator."""
|
"""Mock setup entry with a simple coordinator."""
|
||||||
|
|
||||||
async def _async_update_data():
|
async def _async_update_data():
|
||||||
|
@ -3962,7 +3963,7 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(
|
||||||
entry = MockConfigEntry(title="test_title", domain="test")
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setup entry with a simple coordinator."""
|
"""Mock setup entry with a simple coordinator."""
|
||||||
|
|
||||||
async def _async_update_data():
|
async def _async_update_data():
|
||||||
|
@ -4409,12 +4410,12 @@ async def test_unique_id_update_while_setup_in_progress(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we handle the case where the config entry is updated while setup is in progress."""
|
"""Test we handle the case where the config entry is updated while setup is in progress."""
|
||||||
|
|
||||||
async def mock_setup_entry(hass, entry):
|
async def mock_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setting up entry."""
|
"""Mock setting up entry."""
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def mock_unload_entry(hass, entry):
|
async def mock_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock unloading an entry."""
|
"""Mock unloading an entry."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -5463,7 +5464,7 @@ async def test_reload_during_setup(hass: HomeAssistant) -> None:
|
||||||
in_setup = False
|
in_setup = False
|
||||||
setup_calls = 0
|
setup_calls = 0
|
||||||
|
|
||||||
async def mock_async_setup_entry(hass, entry):
|
async def mock_async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setting up an entry."""
|
"""Mock setting up an entry."""
|
||||||
nonlocal in_setup
|
nonlocal in_setup
|
||||||
nonlocal setup_calls
|
nonlocal setup_calls
|
||||||
|
|
|
@ -658,7 +658,9 @@ def _get_test_integration(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_application_credentials(hass, name):
|
def _get_test_integration_with_application_credentials(
|
||||||
|
hass: HomeAssistant, name: str
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with application_credentials support."""
|
"""Return a generated test integration with application_credentials support."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
@ -678,7 +680,9 @@ def _get_test_integration_with_application_credentials(hass, name):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_zeroconf_matcher(hass, name, config_flow):
|
def _get_test_integration_with_zeroconf_matcher(
|
||||||
|
hass: HomeAssistant, name: str, config_flow: bool
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with a zeroconf matcher."""
|
"""Return a generated test integration with a zeroconf matcher."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
@ -697,7 +701,9 @@ def _get_test_integration_with_zeroconf_matcher(hass, name, config_flow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_legacy_zeroconf_matcher(hass, name, config_flow):
|
def _get_test_integration_with_legacy_zeroconf_matcher(
|
||||||
|
hass: HomeAssistant, name: str, config_flow: bool
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with a legacy zeroconf matcher."""
|
"""Return a generated test integration with a legacy zeroconf matcher."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
@ -724,7 +730,9 @@ def _get_test_integration_with_legacy_zeroconf_matcher(hass, name, config_flow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_dhcp_matcher(hass, name, config_flow):
|
def _get_test_integration_with_dhcp_matcher(
|
||||||
|
hass: HomeAssistant, name: str, config_flow: bool
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with a dhcp matcher."""
|
"""Return a generated test integration with a dhcp matcher."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
@ -748,7 +756,9 @@ def _get_test_integration_with_dhcp_matcher(hass, name, config_flow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_bluetooth_matcher(hass, name, config_flow):
|
def _get_test_integration_with_bluetooth_matcher(
|
||||||
|
hass: HomeAssistant, name: str, config_flow: bool
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with a bluetooth matcher."""
|
"""Return a generated test integration with a bluetooth matcher."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
@ -767,7 +777,9 @@ def _get_test_integration_with_bluetooth_matcher(hass, name, config_flow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_test_integration_with_usb_matcher(hass, name, config_flow):
|
def _get_test_integration_with_usb_matcher(
|
||||||
|
hass: HomeAssistant, name: str, config_flow: bool
|
||||||
|
) -> loader.Integration:
|
||||||
"""Return a generated test integration with a usb matcher."""
|
"""Return a generated test integration with a usb matcher."""
|
||||||
return loader.Integration(
|
return loader.Integration(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, loader, setup
|
from homeassistant import config_entries, loader, setup
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START
|
from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_HOMEASSISTANT_START
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
DOMAIN as HOMEASSISTANT_DOMAIN,
|
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||||
|
@ -23,6 +24,7 @@ from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.issue_registry import IssueRegistry
|
from homeassistant.helpers.issue_registry import IssueRegistry
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
|
@ -298,9 +300,10 @@ async def test_component_not_setup_twice_if_loaded_during_other_setup(
|
||||||
"""Test component setup while waiting for lock is not set up twice."""
|
"""Test component setup while waiting for lock is not set up twice."""
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Tracking Setup."""
|
"""Tracking Setup."""
|
||||||
result.append(1)
|
result.append(1)
|
||||||
|
return True
|
||||||
|
|
||||||
mock_integration(hass, MockModule("comp", async_setup=async_setup))
|
mock_integration(hass, MockModule("comp", async_setup=async_setup))
|
||||||
|
|
||||||
|
@ -345,7 +348,7 @@ async def test_component_exception_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test component that raises exception during setup."""
|
"""Test component that raises exception during setup."""
|
||||||
setup.async_set_domains_to_be_loaded(hass, {"comp"})
|
setup.async_set_domains_to_be_loaded(hass, {"comp"})
|
||||||
|
|
||||||
def exception_setup(hass, config):
|
def exception_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Raise exception."""
|
"""Raise exception."""
|
||||||
raise Exception("fail!") # noqa: TRY002
|
raise Exception("fail!") # noqa: TRY002
|
||||||
|
|
||||||
|
@ -359,7 +362,7 @@ async def test_component_base_exception_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test component that raises exception during setup."""
|
"""Test component that raises exception during setup."""
|
||||||
setup.async_set_domains_to_be_loaded(hass, {"comp"})
|
setup.async_set_domains_to_be_loaded(hass, {"comp"})
|
||||||
|
|
||||||
def exception_setup(hass, config):
|
def exception_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Raise exception."""
|
"""Raise exception."""
|
||||||
raise BaseException("fail!") # noqa: TRY002
|
raise BaseException("fail!") # noqa: TRY002
|
||||||
|
|
||||||
|
@ -377,7 +380,7 @@ async def test_component_setup_with_validation_and_dependency(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test all config is passed to dependencies."""
|
"""Test all config is passed to dependencies."""
|
||||||
|
|
||||||
def config_check_setup(hass, config):
|
def config_check_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Test that config is passed in."""
|
"""Test that config is passed in."""
|
||||||
if config.get("comp_a", {}).get("valid", False):
|
if config.get("comp_a", {}).get("valid", False):
|
||||||
return True
|
return True
|
||||||
|
@ -499,7 +502,7 @@ async def test_all_work_done_before_start(hass: HomeAssistant) -> None:
|
||||||
"""Test all init work done till start."""
|
"""Test all init work done till start."""
|
||||||
call_order = []
|
call_order = []
|
||||||
|
|
||||||
async def component1_setup(hass, config):
|
async def component1_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up mock component."""
|
"""Set up mock component."""
|
||||||
await discovery.async_discover(
|
await discovery.async_discover(
|
||||||
hass, "test_component2", {}, "test_component2", {}
|
hass, "test_component2", {}, "test_component2", {}
|
||||||
|
@ -509,7 +512,7 @@ async def test_all_work_done_before_start(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def component_track_setup(hass, config):
|
def component_track_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up mock component."""
|
"""Set up mock component."""
|
||||||
call_order.append(1)
|
call_order.append(1)
|
||||||
return True
|
return True
|
||||||
|
@ -585,7 +588,7 @@ async def test_when_setup_already_loaded(hass: HomeAssistant) -> None:
|
||||||
"""Test when setup."""
|
"""Test when setup."""
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def mock_callback(hass, component):
|
async def mock_callback(hass: HomeAssistant, component: str) -> None:
|
||||||
"""Mock callback."""
|
"""Mock callback."""
|
||||||
calls.append(component)
|
calls.append(component)
|
||||||
|
|
||||||
|
@ -613,7 +616,7 @@ async def test_async_when_setup_or_start_already_loaded(hass: HomeAssistant) ->
|
||||||
"""Test when setup or start."""
|
"""Test when setup or start."""
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def mock_callback(hass, component):
|
async def mock_callback(hass: HomeAssistant, component: str) -> None:
|
||||||
"""Mock callback."""
|
"""Mock callback."""
|
||||||
calls.append(component)
|
calls.append(component)
|
||||||
|
|
||||||
|
@ -659,7 +662,7 @@ async def test_parallel_entry_setup(hass: HomeAssistant, mock_handlers) -> None:
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def mock_async_setup_entry(hass, entry):
|
async def mock_async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Mock setting up an entry."""
|
"""Mock setting up an entry."""
|
||||||
calls.append(entry.data["value"])
|
calls.append(entry.data["value"])
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue