Skip to content

Commit

Permalink
Add missing hass type hint in component tests (u) (#124275)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 20, 2024
1 parent f66b539 commit d901cb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
5 changes: 4 additions & 1 deletion tests/components/upb/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from homeassistant import config_entries
from homeassistant.components.upb.const import DOMAIN
from homeassistant.config_entries import ConfigFlowResult
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

Expand All @@ -26,7 +27,9 @@ def _upb_lib_connect(callback):
)


async def valid_tcp_flow(hass, sync_complete=True, config_ok=True):
async def valid_tcp_flow(
hass: HomeAssistant, sync_complete: bool = True, config_ok: bool = True
) -> ConfigFlowResult:
"""Get result dict that are standard for most tests."""

with (
Expand Down
27 changes: 23 additions & 4 deletions tests/components/upnp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

from collections.abc import Generator
from collections.abc import Callable, Coroutine, Generator
import copy
from datetime import datetime
import socket
from typing import Any
from unittest.mock import AsyncMock, MagicMock, PropertyMock, create_autospec, patch
from urllib.parse import urlparse

Expand Down Expand Up @@ -175,7 +176,13 @@ async def ssdp_instant_discovery():
"""Instant discovery."""

# Set up device discovery callback.
async def register_callback(hass, callback, match_dict):
async def register_callback(
hass: HomeAssistant,
callback: Callable[
[ssdp.SsdpServiceInfo, ssdp.SsdpChange], Coroutine[Any, Any, None] | None
],
match_dict: dict[str, str] | None = None,
) -> MagicMock:
"""Immediately do callback."""
await callback(TEST_DISCOVERY, ssdp.SsdpChange.ALIVE)
return MagicMock()
Expand All @@ -202,7 +209,13 @@ async def ssdp_instant_discovery_multi_location():
test_discovery.ssdp_all_locations = {TEST_LOCATION6, TEST_LOCATION}

# Set up device discovery callback.
async def register_callback(hass, callback, match_dict):
async def register_callback(
hass: HomeAssistant,
callback: Callable[
[ssdp.SsdpServiceInfo, ssdp.SsdpChange], Coroutine[Any, Any, None] | None
],
match_dict: dict[str, str] | None = None,
) -> MagicMock:
"""Immediately do callback."""
await callback(test_discovery, ssdp.SsdpChange.ALIVE)
return MagicMock()
Expand All @@ -225,7 +238,13 @@ async def ssdp_no_discovery():
"""No discovery."""

# Set up device discovery callback.
async def register_callback(hass, callback, match_dict):
async def register_callback(
hass: HomeAssistant,
callback: Callable[
[ssdp.SsdpServiceInfo, ssdp.SsdpChange], Coroutine[Any, Any, None] | None
],
match_dict: dict[str, str] | None = None,
) -> MagicMock:
"""Don't do callback."""
return MagicMock()

Expand Down
10 changes: 9 additions & 1 deletion tests/components/upnp/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from __future__ import annotations

from collections.abc import Callable, Coroutine
import copy
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch

from async_upnp_client.profiles.igd import IgdDevice
Expand Down Expand Up @@ -140,7 +142,13 @@ async def test_async_setup_udn_mismatch(
)

# Set up device discovery callback.
async def register_callback(hass, callback, match_dict):
async def register_callback(
hass: HomeAssistant,
callback: Callable[
[ssdp.SsdpServiceInfo, ssdp.SsdpChange], Coroutine[Any, Any, None] | None
],
match_dict: dict[str, str] | None = None,
) -> MagicMock:
"""Immediately do callback."""
await callback(test_discovery, ssdp.SsdpChange.ALIVE)
return MagicMock()
Expand Down

0 comments on commit d901cb0

Please sign in to comment.