Skip to content

Commit

Permalink
Add missing hass type in tests/*.py (#124048)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 18, 2024
1 parent 69843e9 commit ba3872f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 50 deletions.
17 changes: 12 additions & 5 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from homeassistant.components.device_automation import ( # noqa: F401
_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.const import (
DEVICE_DEFAULT_NAME,
Expand Down Expand Up @@ -439,14 +439,16 @@ def mock_service_log(call):


@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."""
intents = []
intents: list[intent.Intent] = []

class MockIntentHandler(intent.IntentHandler):
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."""
intents.append(intent_obj)
return intent_obj.create_response()
Expand Down Expand Up @@ -1159,7 +1161,12 @@ def assert_setup_component(count, domain=None):
"""
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."""
domain_input = integration.domain
integration_config_info = await async_process_component_config(
Expand Down
24 changes: 12 additions & 12 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def test_setup_after_deps_all_present(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -260,7 +260,7 @@ async def test_setup_after_deps_in_stage_1_ignored(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -315,7 +315,7 @@ async def test_setup_after_deps_manifests_are_loaded_even_if_not_setup(
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -392,7 +392,7 @@ async def test_setup_frontend_before_recorder(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -471,7 +471,7 @@ async def test_setup_after_deps_via_platform(hass: HomeAssistant) -> None:
after_dep_event = asyncio.Event()

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":
await after_dep_event.wait()

Expand Down Expand Up @@ -520,7 +520,7 @@ async def test_setup_after_deps_not_trigger_load(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -559,7 +559,7 @@ async def test_setup_after_deps_not_present(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down Expand Up @@ -969,7 +969,7 @@ async def test_empty_integrations_list_is_only_sent_at_the_end_of_bootstrap(
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
await asyncio.sleep(0.05)

Expand Down Expand Up @@ -1029,7 +1029,7 @@ async def test_warning_logged_on_wrap_up_timeout(
task: asyncio.Task | None = None

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
nonlocal task

async def _not_marked_background_task():
Expand Down Expand Up @@ -1067,7 +1067,7 @@ async def test_tasks_logged_that_block_stage_1(
"""Test we log tasks that delay stage 1 startup."""

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():
await asyncio.sleep(0.2)

Expand Down Expand Up @@ -1110,7 +1110,7 @@ async def test_tasks_logged_that_block_stage_2(
done_future = hass.loop.create_future()

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():
await done_future

Expand Down Expand Up @@ -1452,7 +1452,7 @@ async def test_setup_does_base_platforms_first(hass: HomeAssistant) -> None:
order = []

def gen_domain_setup(domain):
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
order.append(domain)
return True

Expand Down
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
DOMAIN as HOMEASSISTANT_DOMAIN,
ConfigSource,
HomeAssistant,
State,
)
from homeassistant.exceptions import ConfigValidationError, HomeAssistantError
from homeassistant.helpers import (
Expand Down Expand Up @@ -579,7 +580,7 @@ def test_customize_glob_is_ordered() -> None:
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)

entity = Entity()
Expand Down
35 changes: 18 additions & 17 deletions tests/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.components import dhcp
from homeassistant.components.hassio import HassioServiceInfo
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
EVENT_COMPONENT_LOADED,
EVENT_HOMEASSISTANT_STARTED,
Expand Down Expand Up @@ -104,12 +105,12 @@ async def test_setup_race_only_setup_once(hass: HomeAssistant) -> None:
fast_config_entry_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."""
await slow_setup_future
return True

async def async_setup_entry(hass, entry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Mock setup entry."""
slow = entry.data["slow"]
if slow:
Expand All @@ -122,7 +123,7 @@ async def async_setup_entry(hass, entry):
await fast_config_entry_setup_future
return True

async def async_unload_entry(hass, entry):
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Mock unload entry."""
return True

Expand Down Expand Up @@ -582,7 +583,7 @@ async def test_remove_entry_raises(
) -> None:
"""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."""
raise Exception("BROKEN") # noqa: TRY002

Expand Down Expand Up @@ -1326,7 +1327,7 @@ async def test_update_entry_options_and_trigger_listener(
entry.add_to_manager(manager)
update_listener_calls = []

async def update_listener(hass, entry):
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Test function."""
assert entry.options == {"second": True}
update_listener_calls.append(None)
Expand Down Expand Up @@ -1491,7 +1492,7 @@ async def test_reload_during_setup_retrying_waits(hass: HomeAssistant) -> None:
load_attempts = []
sleep_duration = 0

async def _mock_setup_entry(hass, entry):
async def _mock_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Mock setup entry."""
nonlocal sleep_duration
await asyncio.sleep(sleep_duration)
Expand Down Expand Up @@ -1536,7 +1537,7 @@ async def test_create_entry_options(
) -> None:
"""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."""
hass.async_create_task(
hass.config_entries.flow.async_init(
Expand Down Expand Up @@ -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."""
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."""
hass.async_create_task(
hass.config_entries.flow.async_init(
Expand Down Expand Up @@ -3292,7 +3293,7 @@ async def test_async_setup_update_entry(hass: HomeAssistant) -> None:
entry = MockConfigEntry(domain="comp", data={"value": "initial"})
entry.add_to_hass(hass)

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(
Expand All @@ -3303,7 +3304,7 @@ async def mock_async_setup(hass, config):
)
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."""
assert entry.data["value"] == "updated"
return True
Expand Down Expand Up @@ -3791,7 +3792,7 @@ async def test_setup_raise_entry_error_from_first_coordinator_update(
entry = MockConfigEntry(title="test_title", domain="test")
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."""

async def _async_update_data():
Expand Down Expand Up @@ -3831,7 +3832,7 @@ async def test_setup_not_raise_entry_error_from_future_coordinator_update(
entry = MockConfigEntry(title="test_title", domain="test")
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."""

async def _async_update_data():
Expand Down Expand Up @@ -3910,7 +3911,7 @@ async def test_setup_raise_auth_failed_from_first_coordinator_update(
entry = MockConfigEntry(title="test_title", domain="test")
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."""

async def _async_update_data():
Expand Down Expand Up @@ -3962,7 +3963,7 @@ async def test_setup_raise_auth_failed_from_future_coordinator_update(
entry = MockConfigEntry(title="test_title", domain="test")
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."""

async def _async_update_data():
Expand Down Expand Up @@ -4409,12 +4410,12 @@ async def test_unique_id_update_while_setup_in_progress(
) -> None:
"""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."""
await asyncio.sleep(0.1)
return True

async def mock_unload_entry(hass, entry):
async def mock_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Mock unloading an entry."""
return True

Expand Down Expand Up @@ -5463,7 +5464,7 @@ async def test_reload_during_setup(hass: HomeAssistant) -> None:
in_setup = False
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."""
nonlocal in_setup
nonlocal setup_calls
Expand Down
24 changes: 18 additions & 6 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 loader.Integration(
hass,
Expand All @@ -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 loader.Integration(
hass,
Expand All @@ -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 loader.Integration(
hass,
Expand All @@ -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 loader.Integration(
hass,
Expand All @@ -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 loader.Integration(
hass,
Expand All @@ -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 loader.Integration(
hass,
Expand Down
Loading

0 comments on commit ba3872f

Please sign in to comment.