Skip to content

Commit

Permalink
Add missing argument type hints to component tests (home-assistant#11…
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jun 14, 2024
1 parent 83b97d3 commit 3e9d25f
Show file tree
Hide file tree
Showing 47 changed files with 135 additions and 67 deletions.
3 changes: 2 additions & 1 deletion tests/components/accuweather/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Tests for AccuWeather."""

from homeassistant.components.accuweather.const import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def init_integration(hass) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the AccuWeather integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
6 changes: 5 additions & 1 deletion tests/components/airly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for Airly."""

from homeassistant.components.airly.const import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker

API_NEAREST_URL = "https://airapi.airly.eu/v2/measurements/nearest?lat=123.000000&lng=456.000000&maxDistanceKM=5.000000"
API_POINT_URL = (
Expand All @@ -14,7 +16,9 @@
}


async def init_integration(hass, aioclient_mock) -> MockConfigEntry:
async def init_integration(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> MockConfigEntry:
"""Set up the Airly integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@
class MyCoordinator(PassiveBluetoothDataUpdateCoordinator):
"""An example coordinator that subclasses PassiveBluetoothDataUpdateCoordinator."""

def __init__(self, hass, logger, device_id, mode) -> None:
def __init__(
self,
hass: HomeAssistant,
logger: logging.Logger,
device_id: str,
mode: BluetoothScanningMode,
) -> None:
"""Initialize the coordinator."""
super().__init__(hass, logger, device_id, mode)
self.data: dict[str, Any] = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/bthome/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_device_id(mac: str) -> tuple[str, str]:
return (BLUETOOTH_DOMAIN, mac)


async def _async_setup_bthome_device(hass, mac: str):
async def _async_setup_bthome_device(hass: HomeAssistant, mac: str) -> MockConfigEntry:
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=mac,
Expand Down
6 changes: 4 additions & 2 deletions tests/components/device_tracker/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SourceType,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import GPSType
from homeassistant.helpers.typing import ConfigType, GPSType
from homeassistant.loader import bind_hass

from tests.common import MockPlatform, mock_platform
Expand Down Expand Up @@ -143,7 +143,9 @@ def mock_legacy_device_tracker_setup(
) -> None:
"""Mock legacy device tracker platform setup."""

async def _async_get_scanner(hass, config) -> MockScanner:
async def _async_get_scanner(
hass: HomeAssistant, config: ConfigType
) -> MockScanner:
"""Return the test scanner."""
return legacy_device_scanner

Expand Down
3 changes: 2 additions & 1 deletion tests/components/dexcom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from homeassistant.components.dexcom.const import CONF_SERVER, DOMAIN, SERVER_US
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_fixture

Expand All @@ -19,7 +20,7 @@
GLUCOSE_READING = GlucoseReading(json.loads(load_fixture("data.json", "dexcom")))


async def init_integration(hass) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Dexcom integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
2 changes: 1 addition & 1 deletion tests/components/dlna_dms/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


@pytest.fixture
async def setup_media_source(hass) -> None:
async def setup_media_source(hass: HomeAssistant) -> None:
"""Set up media source."""
assert await async_setup_component(hass, "media_source", {})

Expand Down
4 changes: 2 additions & 2 deletions tests/components/esphome/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def esphome_mock_async_zeroconf(mock_async_zeroconf: MagicMock) -> None:


@pytest.fixture(autouse=True)
async def load_homeassistant(hass) -> None:
async def load_homeassistant(hass: HomeAssistant) -> None:
"""Load the homeassistant integration."""
assert await async_setup_component(hass, "homeassistant", {})

Expand All @@ -63,7 +63,7 @@ def mock_tts(mock_tts_cache_dir: Path) -> None:


@pytest.fixture
def mock_config_entry(hass) -> MockConfigEntry:
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Return the default mocked config entry."""
config_entry = MockConfigEntry(
title="ESPHome Device",
Expand Down
17 changes: 9 additions & 8 deletions tests/components/fan/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.core import HomeAssistant

from tests.common import MockEntity


async def async_turn_on(
hass,
hass: HomeAssistant,
entity_id=ENTITY_MATCH_ALL,
percentage: int | None = None,
preset_mode: str | None = None,
Expand All @@ -50,7 +51,7 @@ async def async_turn_on(
await hass.async_block_till_done()


async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL) -> None:
async def async_turn_off(hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL) -> None:
"""Turn all or specified fan off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}

Expand All @@ -59,7 +60,7 @@ async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL) -> None:


async def async_oscillate(
hass, entity_id=ENTITY_MATCH_ALL, should_oscillate: bool = True
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, should_oscillate: bool = True
) -> None:
"""Set oscillation on all or specified fan."""
data = {
Expand All @@ -76,7 +77,7 @@ async def async_oscillate(


async def async_set_preset_mode(
hass, entity_id=ENTITY_MATCH_ALL, preset_mode: str | None = None
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, preset_mode: str | None = None
) -> None:
"""Set preset mode for all or specified fan."""
data = {
Expand All @@ -90,7 +91,7 @@ async def async_set_preset_mode(


async def async_set_percentage(
hass, entity_id=ENTITY_MATCH_ALL, percentage: int | None = None
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, percentage: int | None = None
) -> None:
"""Set percentage for all or specified fan."""
data = {
Expand All @@ -104,7 +105,7 @@ async def async_set_percentage(


async def async_increase_speed(
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
) -> None:
"""Increase speed for all or specified fan."""
data = {
Expand All @@ -121,7 +122,7 @@ async def async_increase_speed(


async def async_decrease_speed(
hass, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, percentage_step: int | None = None
) -> None:
"""Decrease speed for all or specified fan."""
data = {
Expand All @@ -138,7 +139,7 @@ async def async_decrease_speed(


async def async_set_direction(
hass, entity_id=ENTITY_MATCH_ALL, direction: str | None = None
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, direction: str | None = None
) -> None:
"""Set direction for all or specified fan."""
data = {
Expand Down
5 changes: 3 additions & 2 deletions tests/components/freedompro/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing_extensions import Generator

from homeassistant.components.freedompro.const import DOMAIN
from homeassistant.core import HomeAssistant

from .const import DEVICES, DEVICES_STATE

Expand Down Expand Up @@ -45,7 +46,7 @@ def mock_freedompro():


@pytest.fixture
async def init_integration(hass) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Freedompro integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand All @@ -64,7 +65,7 @@ async def init_integration(hass) -> MockConfigEntry:


@pytest.fixture
async def init_integration_no_state(hass) -> MockConfigEntry:
async def init_integration_no_state(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Freedompro integration in Home Assistant without state."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
3 changes: 2 additions & 1 deletion tests/components/gios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

from homeassistant.components.gios.const import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_fixture

Expand All @@ -14,7 +15,7 @@


async def init_integration(
hass, incomplete_data=False, invalid_indexes=False
hass: HomeAssistant, incomplete_data=False, invalid_indexes=False
) -> MockConfigEntry:
"""Set up the GIOS integration in Home Assistant."""
entry = MockConfigEntry(
Expand Down
6 changes: 5 additions & 1 deletion tests/components/imgw_pib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Tests for the IMGW-PIB integration."""

from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def init_integration(hass, config_entry: MockConfigEntry) -> MockConfigEntry:
async def init_integration(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> MockConfigEntry:
"""Set up the IMGW-PIB integration in Home Assistant."""
config_entry.add_to_hass(hass)

Expand Down
3 changes: 2 additions & 1 deletion tests/components/kodi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
CONF_SSL,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant

from .util import MockConnection

from tests.common import MockConfigEntry


async def init_integration(hass) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Kodi integration in Home Assistant."""
entry_data = {
CONF_NAME: "name",
Expand Down
3 changes: 2 additions & 1 deletion tests/components/litejet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from homeassistant.components import scene, switch
from homeassistant.components.litejet import DOMAIN
from homeassistant.const import CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

from tests.common import MockConfigEntry


async def async_init_integration(
hass, use_switch=False, use_scene=False
hass: HomeAssistant, use_switch: bool = False, use_scene: bool = False
) -> MockConfigEntry:
"""Set up the LiteJet integration in Home Assistant."""

Expand Down
4 changes: 2 additions & 2 deletions tests/components/loqed/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def test_setup_cloudhook_from_entry_in_bridge(


async def test_unload_entry(
hass, integration: MockConfigEntry, lock: loqed.Lock
hass: HomeAssistant, integration: MockConfigEntry, lock: loqed.Lock
) -> None:
"""Test successful unload of entry."""

Expand All @@ -157,7 +157,7 @@ async def test_unload_entry(


async def test_unload_entry_fails(
hass, integration: MockConfigEntry, lock: loqed.Lock
hass: HomeAssistant, integration: MockConfigEntry, lock: loqed.Lock
) -> None:
"""Test unsuccessful unload of entry."""
lock.deleteWebhook = AsyncMock(side_effect=Exception)
Expand Down
3 changes: 2 additions & 1 deletion tests/components/lutron_caseta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CONF_KEYFILE,
)
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry

Expand Down Expand Up @@ -83,7 +84,7 @@
}


async def async_setup_integration(hass, mock_bridge) -> MockConfigEntry:
async def async_setup_integration(hass: HomeAssistant, mock_bridge) -> MockConfigEntry:
"""Set up a mock bridge."""
mock_entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_MOCK_DATA)
mock_entry.add_to_hass(hass)
Expand Down
5 changes: 4 additions & 1 deletion tests/components/met/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from homeassistant.components.met.const import CONF_TRACK_HOME, DOMAIN
from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def init_integration(hass, track_home=False) -> MockConfigEntry:
async def init_integration(
hass: HomeAssistant, track_home: bool = False
) -> MockConfigEntry:
"""Set up the Met integration in Home Assistant."""
entry_data = {
CONF_NAME: "test",
Expand Down
3 changes: 2 additions & 1 deletion tests/components/met_eireann/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

from homeassistant.components.met_eireann.const import DOMAIN
from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry


async def init_integration(hass) -> MockConfigEntry:
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
"""Set up the Met Éireann integration in Home Assistant."""
entry_data = {
CONF_NAME: "test",
Expand Down
2 changes: 1 addition & 1 deletion tests/components/motioneye/test_media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


@pytest.fixture(autouse=True)
async def setup_media_source(hass) -> None:
async def setup_media_source(hass: HomeAssistant) -> None:
"""Set up media source."""
assert await async_setup_component(hass, "media_source", {})

Expand Down
5 changes: 4 additions & 1 deletion tests/components/nam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import AsyncMock, Mock, patch

from homeassistant.components.nam.const import DOMAIN
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_json_object_fixture

Expand All @@ -12,7 +13,9 @@
}


async def init_integration(hass, co2_sensor=True) -> MockConfigEntry:
async def init_integration(
hass: HomeAssistant, co2_sensor: bool = True
) -> MockConfigEntry:
"""Set up the Nettigo Air Monitor integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down
Loading

0 comments on commit 3e9d25f

Please sign in to comment.