From 3e9d25f81d321511c02b6c459bc9ac6c598e60b9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:26:46 +0200 Subject: [PATCH] Add missing argument type hints to component tests (#119671) --- tests/components/accuweather/__init__.py | 3 ++- tests/components/airly/__init__.py | 6 +++++- .../test_passive_update_coordinator.py | 8 +++++++- tests/components/bthome/test_device_trigger.py | 2 +- tests/components/device_tracker/common.py | 6 ++++-- tests/components/dexcom/__init__.py | 3 ++- tests/components/dlna_dms/conftest.py | 2 +- tests/components/esphome/conftest.py | 4 ++-- tests/components/fan/common.py | 17 +++++++++-------- tests/components/freedompro/conftest.py | 5 +++-- tests/components/gios/__init__.py | 3 ++- tests/components/imgw_pib/__init__.py | 6 +++++- tests/components/kodi/__init__.py | 3 ++- tests/components/litejet/__init__.py | 3 ++- tests/components/loqed/test_init.py | 4 ++-- tests/components/lutron_caseta/__init__.py | 3 ++- tests/components/met/__init__.py | 5 ++++- tests/components/met_eireann/__init__.py | 3 ++- tests/components/motioneye/test_media_source.py | 2 +- tests/components/nam/__init__.py | 5 ++++- tests/components/nest/test_camera.py | 3 ++- tests/components/nest/test_media_source.py | 2 +- tests/components/nightscout/__init__.py | 7 ++++--- tests/components/nina/test_init.py | 2 +- tests/components/nzbget/__init__.py | 3 ++- tests/components/octoprint/__init__.py | 8 +++++--- tests/components/onvif/__init__.py | 3 ++- .../components/owntracks/test_device_tracker.py | 4 +++- tests/components/plex/conftest.py | 3 ++- tests/components/plex/test_init.py | 2 +- tests/components/powerwall/mocks.py | 6 +++++- tests/components/rfxtrx/conftest.py | 3 ++- tests/components/rtsp_to_webrtc/conftest.py | 2 +- tests/components/sia/test_config_flow.py | 2 +- tests/components/smartthings/conftest.py | 4 +++- tests/components/stream/test_hls.py | 2 +- tests/components/system_log/test_init.py | 5 ++++- tests/components/unifi/conftest.py | 6 ++++-- tests/components/v2c/__init__.py | 6 +++++- tests/components/valve/test_init.py | 2 +- tests/components/voip/conftest.py | 2 +- tests/components/ws66i/test_media_player.py | 4 ++-- .../xiaomi_ble/test_device_trigger.py | 4 +++- tests/components/zha/common.py | 5 ++++- tests/components/zha/conftest.py | 9 ++++++--- tests/components/zha/test_discover.py | 4 ++-- tests/components/zha/test_light.py | 6 +++++- 47 files changed, 135 insertions(+), 67 deletions(-) diff --git a/tests/components/accuweather/__init__.py b/tests/components/accuweather/__init__.py index 21cdb2ac558..0e5313ceb94 100644 --- a/tests/components/accuweather/__init__.py +++ b/tests/components/accuweather/__init__.py @@ -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, diff --git a/tests/components/airly/__init__.py b/tests/components/airly/__init__.py index 2e2ec23e4e3..c87c41b5162 100644 --- a/tests/components/airly/__init__.py +++ b/tests/components/airly/__init__.py @@ -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 = ( @@ -14,7 +16,9 @@ HEADERS = { } -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, diff --git a/tests/components/bluetooth/test_passive_update_coordinator.py b/tests/components/bluetooth/test_passive_update_coordinator.py index 53a18e88683..9b668b97177 100644 --- a/tests/components/bluetooth/test_passive_update_coordinator.py +++ b/tests/components/bluetooth/test_passive_update_coordinator.py @@ -52,7 +52,13 @@ GENERIC_BLUETOOTH_SERVICE_INFO = BluetoothServiceInfo( 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] = {} diff --git a/tests/components/bthome/test_device_trigger.py b/tests/components/bthome/test_device_trigger.py index f847ffb9c0a..459654826f9 100644 --- a/tests/components/bthome/test_device_trigger.py +++ b/tests/components/bthome/test_device_trigger.py @@ -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, diff --git a/tests/components/device_tracker/common.py b/tests/components/device_tracker/common.py index a17556cfbaa..d30db984a66 100644 --- a/tests/components/device_tracker/common.py +++ b/tests/components/device_tracker/common.py @@ -20,7 +20,7 @@ from homeassistant.components.device_tracker import ( 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 @@ -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 diff --git a/tests/components/dexcom/__init__.py b/tests/components/dexcom/__init__.py index e9ca303765b..adc9c56049a 100644 --- a/tests/components/dexcom/__init__.py +++ b/tests/components/dexcom/__init__.py @@ -7,6 +7,7 @@ from pydexcom import GlucoseReading 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 @@ -19,7 +20,7 @@ CONFIG = { 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, diff --git a/tests/components/dlna_dms/conftest.py b/tests/components/dlna_dms/conftest.py index c1bee224c5a..1fa56f4bc24 100644 --- a/tests/components/dlna_dms/conftest.py +++ b/tests/components/dlna_dms/conftest.py @@ -38,7 +38,7 @@ NEW_DEVICE_LOCATION: Final = "http://192.88.99.7" + "/dmr_description.xml" @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", {}) diff --git a/tests/components/esphome/conftest.py b/tests/components/esphome/conftest.py index f1fae38e0e3..43edca54158 100644 --- a/tests/components/esphome/conftest.py +++ b/tests/components/esphome/conftest.py @@ -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", {}) @@ -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", diff --git a/tests/components/fan/common.py b/tests/components/fan/common.py index 74939342fac..0b4243e4144 100644 --- a/tests/components/fan/common.py +++ b/tests/components/fan/common.py @@ -25,12 +25,13 @@ from homeassistant.const import ( 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, @@ -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 {} @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { diff --git a/tests/components/freedompro/conftest.py b/tests/components/freedompro/conftest.py index daafc7e8dc7..91eecc24f27 100644 --- a/tests/components/freedompro/conftest.py +++ b/tests/components/freedompro/conftest.py @@ -10,6 +10,7 @@ import pytest from typing_extensions import Generator from homeassistant.components.freedompro.const import DOMAIN +from homeassistant.core import HomeAssistant from .const import DEVICES, DEVICES_STATE @@ -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, @@ -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, diff --git a/tests/components/gios/__init__.py b/tests/components/gios/__init__.py index 435b3209199..07dbd6502b4 100644 --- a/tests/components/gios/__init__.py +++ b/tests/components/gios/__init__.py @@ -4,6 +4,7 @@ import json from unittest.mock import patch from homeassistant.components.gios.const import DOMAIN +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry, load_fixture @@ -14,7 +15,7 @@ STATIONS = [ 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( diff --git a/tests/components/imgw_pib/__init__.py b/tests/components/imgw_pib/__init__.py index c684b596949..adea1c40925 100644 --- a/tests/components/imgw_pib/__init__.py +++ b/tests/components/imgw_pib/__init__.py @@ -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) diff --git a/tests/components/kodi/__init__.py b/tests/components/kodi/__init__.py index d55a67ba235..f78207be404 100644 --- a/tests/components/kodi/__init__.py +++ b/tests/components/kodi/__init__.py @@ -11,13 +11,14 @@ from homeassistant.const import ( 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", diff --git a/tests/components/litejet/__init__.py b/tests/components/litejet/__init__.py index 3116d9e810d..bf992836043 100644 --- a/tests/components/litejet/__init__.py +++ b/tests/components/litejet/__init__.py @@ -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.""" diff --git a/tests/components/loqed/test_init.py b/tests/components/loqed/test_init.py index ed38b63fdb1..e6bff2203a9 100644 --- a/tests/components/loqed/test_init.py +++ b/tests/components/loqed/test_init.py @@ -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.""" @@ -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) diff --git a/tests/components/lutron_caseta/__init__.py b/tests/components/lutron_caseta/__init__.py index cc785f71e19..9b25e2a0164 100644 --- a/tests/components/lutron_caseta/__init__.py +++ b/tests/components/lutron_caseta/__init__.py @@ -9,6 +9,7 @@ from homeassistant.components.lutron_caseta.const import ( CONF_KEYFILE, ) from homeassistant.const import CONF_HOST +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -83,7 +84,7 @@ _LEAP_DEVICE_TYPES = { } -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) diff --git a/tests/components/met/__init__.py b/tests/components/met/__init__.py index 8ea5ce605f0..6556c96bff9 100644 --- a/tests/components/met/__init__.py +++ b/tests/components/met/__init__.py @@ -4,11 +4,14 @@ from unittest.mock import patch 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", diff --git a/tests/components/met_eireann/__init__.py b/tests/components/met_eireann/__init__.py index 86c3090b0ca..c38f197691a 100644 --- a/tests/components/met_eireann/__init__.py +++ b/tests/components/met_eireann/__init__.py @@ -4,11 +4,12 @@ from unittest.mock import patch 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", diff --git a/tests/components/motioneye/test_media_source.py b/tests/components/motioneye/test_media_source.py index f895ed7fcb2..f8a750d50da 100644 --- a/tests/components/motioneye/test_media_source.py +++ b/tests/components/motioneye/test_media_source.py @@ -74,7 +74,7 @@ _LOGGER = logging.getLogger(__name__) @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", {}) diff --git a/tests/components/nam/__init__.py b/tests/components/nam/__init__.py index 9b254de452c..e7560f8f7ce 100644 --- a/tests/components/nam/__init__.py +++ b/tests/components/nam/__init__.py @@ -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 @@ -12,7 +13,9 @@ INCOMPLETE_NAM_DATA = { } -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, diff --git a/tests/components/nest/test_camera.py b/tests/components/nest/test_camera.py index 8db86f5d8c1..1838c18b6d4 100644 --- a/tests/components/nest/test_camera.py +++ b/tests/components/nest/test_camera.py @@ -12,6 +12,7 @@ import aiohttp from freezegun import freeze_time from google_nest_sdm.event import EventMessage import pytest +from typing_extensions import Generator from homeassistant.components import camera from homeassistant.components.camera import STATE_IDLE, STATE_STREAMING, StreamType @@ -149,7 +150,7 @@ def make_stream_url_response( @pytest.fixture -async def mock_create_stream(hass) -> Mock: +async def mock_create_stream(hass: HomeAssistant) -> Generator[AsyncMock]: """Fixture to mock out the create stream call.""" assert await async_setup_component(hass, "stream", {}) with patch( diff --git a/tests/components/nest/test_media_source.py b/tests/components/nest/test_media_source.py index bbc08229d37..f4fb8bdb623 100644 --- a/tests/components/nest/test_media_source.py +++ b/tests/components/nest/test_media_source.py @@ -95,7 +95,7 @@ def platforms() -> list[str]: @pytest.fixture(autouse=True) -async def setup_components(hass) -> None: +async def setup_components(hass: HomeAssistant) -> None: """Fixture to initialize the integration.""" await async_setup_component(hass, "media_source", {}) diff --git a/tests/components/nightscout/__init__.py b/tests/components/nightscout/__init__.py index da421d5bba9..551ecffbed1 100644 --- a/tests/components/nightscout/__init__.py +++ b/tests/components/nightscout/__init__.py @@ -8,6 +8,7 @@ from py_nightscout.models import SGV, ServerStatus from homeassistant.components.nightscout.const import DOMAIN from homeassistant.const import CONF_URL +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -30,7 +31,7 @@ SERVER_STATUS_STATUS_ONLY = ServerStatus.new_from_json_dict( ) -async def init_integration(hass) -> MockConfigEntry: +async def init_integration(hass: HomeAssistant) -> MockConfigEntry: """Set up the Nightscout integration in Home Assistant.""" entry = MockConfigEntry( domain=DOMAIN, @@ -53,7 +54,7 @@ async def init_integration(hass) -> MockConfigEntry: return entry -async def init_integration_unavailable(hass) -> MockConfigEntry: +async def init_integration_unavailable(hass: HomeAssistant) -> MockConfigEntry: """Set up the Nightscout integration in Home Assistant.""" entry = MockConfigEntry( domain=DOMAIN, @@ -76,7 +77,7 @@ async def init_integration_unavailable(hass) -> MockConfigEntry: return entry -async def init_integration_empty_response(hass) -> MockConfigEntry: +async def init_integration_empty_response(hass: HomeAssistant) -> MockConfigEntry: """Set up the Nightscout integration in Home Assistant.""" entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/nina/test_init.py b/tests/components/nina/test_init.py index 5a6b9ab07dd..620b01fdeb8 100644 --- a/tests/components/nina/test_init.py +++ b/tests/components/nina/test_init.py @@ -22,7 +22,7 @@ ENTRY_DATA: dict[str, Any] = { } -async def init_integration(hass) -> MockConfigEntry: +async def init_integration(hass: HomeAssistant) -> MockConfigEntry: """Set up the NINA integration in Home Assistant.""" with patch( diff --git a/tests/components/nzbget/__init__.py b/tests/components/nzbget/__init__.py index d8fa2f87233..e91f6e35e08 100644 --- a/tests/components/nzbget/__init__.py +++ b/tests/components/nzbget/__init__.py @@ -13,6 +13,7 @@ from homeassistant.const import ( CONF_USERNAME, CONF_VERIFY_SSL, ) +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -59,7 +60,7 @@ MOCK_HISTORY = [ ] -async def init_integration(hass) -> MockConfigEntry: +async def init_integration(hass: HomeAssistant) -> MockConfigEntry: """Set up the NZBGet integration in Home Assistant.""" entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG, options=ENTRY_OPTIONS) entry.add_to_hass(hass) diff --git a/tests/components/octoprint/__init__.py b/tests/components/octoprint/__init__.py index 0a35d0a2267..dd3eda0e81f 100644 --- a/tests/components/octoprint/__init__.py +++ b/tests/components/octoprint/__init__.py @@ -14,6 +14,8 @@ from pyoctoprintapi import ( from homeassistant.components.octoprint import DOMAIN from homeassistant.config_entries import ConfigEntryState +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant from homeassistant.helpers.typing import UNDEFINED, UndefinedType from tests.common import MockConfigEntry @@ -33,11 +35,11 @@ DEFAULT_PRINTER = { async def init_integration( - hass, - platform, + hass: HomeAssistant, + platform: Platform, printer: dict[str, Any] | UndefinedType | None = UNDEFINED, job: dict[str, Any] | None = None, -): +) -> None: """Set up the octoprint integration in Home Assistant.""" printer_info: OctoprintPrinterInfo | None = None if printer is UNDEFINED: diff --git a/tests/components/onvif/__init__.py b/tests/components/onvif/__init__.py index 1e7c3273ced..0857dfef798 100644 --- a/tests/components/onvif/__init__.py +++ b/tests/components/onvif/__init__.py @@ -18,6 +18,7 @@ from homeassistant.components.onvif.models import ( WebHookManagerState, ) from homeassistant.const import HTTP_DIGEST_AUTHENTICATION +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -158,7 +159,7 @@ def setup_mock_device(mock_device, capabilities=None): async def setup_onvif_integration( - hass, + hass: HomeAssistant, config=None, options=None, unique_id=MAC, diff --git a/tests/components/owntracks/test_device_tracker.py b/tests/components/owntracks/test_device_tracker.py index 16ce8223845..8246a7f51ac 100644 --- a/tests/components/owntracks/test_device_tracker.py +++ b/tests/components/owntracks/test_device_tracker.py @@ -290,7 +290,9 @@ BAD_JSON_SUFFIX = "** and it ends here ^^" @pytest.fixture def setup_comp( - hass, mock_device_tracker_conf: list[Device], mqtt_mock: MqttMockHAClient + hass: HomeAssistant, + mock_device_tracker_conf: list[Device], + mqtt_mock: MqttMockHAClient, ): """Initialize components.""" hass.loop.run_until_complete(async_setup_component(hass, "device_tracker", {})) diff --git a/tests/components/plex/conftest.py b/tests/components/plex/conftest.py index 40b61dfb17a..a061d9c1105 100644 --- a/tests/components/plex/conftest.py +++ b/tests/components/plex/conftest.py @@ -8,6 +8,7 @@ from typing_extensions import Generator from homeassistant.components.plex.const import DOMAIN, PLEX_SERVER_CONFIG, SERVERS from homeassistant.const import CONF_URL +from homeassistant.core import HomeAssistant from .const import DEFAULT_DATA, DEFAULT_OPTIONS, PLEX_DIRECT_URL from .helpers import websocket_connected @@ -546,7 +547,7 @@ def mock_plex_calls( @pytest.fixture def setup_plex_server( - hass, + hass: HomeAssistant, entry, livetv_sessions, mock_websocket, diff --git a/tests/components/plex/test_init.py b/tests/components/plex/test_init.py index f718e6c86ad..15af78faf65 100644 --- a/tests/components/plex/test_init.py +++ b/tests/components/plex/test_init.py @@ -270,7 +270,7 @@ async def test_setup_when_certificate_changed( assert old_entry.data[const.PLEX_SERVER_CONFIG][CONF_URL] == new_url -async def test_tokenless_server(hass, entry, setup_plex_server) -> None: +async def test_tokenless_server(hass: HomeAssistant, entry, setup_plex_server) -> None: """Test setup with a server with token auth disabled.""" TOKENLESS_DATA = copy.deepcopy(DEFAULT_DATA) TOKENLESS_DATA[const.PLEX_SERVER_CONFIG].pop(CONF_TOKEN, None) diff --git a/tests/components/powerwall/mocks.py b/tests/components/powerwall/mocks.py index 10b070a0db7..e43ccee16f1 100644 --- a/tests/components/powerwall/mocks.py +++ b/tests/components/powerwall/mocks.py @@ -16,12 +16,16 @@ from tesla_powerwall import ( SiteMasterResponse, ) +from homeassistant.core import HomeAssistant + from tests.common import load_fixture MOCK_GATEWAY_DIN = "111-0----2-000000000FFA" -async def _mock_powerwall_with_fixtures(hass, empty_meters: bool = False) -> MagicMock: +async def _mock_powerwall_with_fixtures( + hass: HomeAssistant, empty_meters: bool = False +) -> MagicMock: """Mock data used to build powerwall state.""" async with asyncio.TaskGroup() as tg: meters_file = "meters_empty.json" if empty_meters else "meters.json" diff --git a/tests/components/rfxtrx/conftest.py b/tests/components/rfxtrx/conftest.py index 5e0223173f9..88450638d6c 100644 --- a/tests/components/rfxtrx/conftest.py +++ b/tests/components/rfxtrx/conftest.py @@ -10,6 +10,7 @@ from RFXtrx import Connect, RFXtrxTransport from homeassistant.components import rfxtrx from homeassistant.components.rfxtrx import DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.util.dt import utcnow from tests.common import MockConfigEntry, async_fire_time_changed @@ -37,7 +38,7 @@ def create_rfx_test_cfg( async def setup_rfx_test_cfg( - hass, + hass: HomeAssistant, device="abcd", automatic_add=False, devices: dict[str, dict] | None = None, diff --git a/tests/components/rtsp_to_webrtc/conftest.py b/tests/components/rtsp_to_webrtc/conftest.py index cdb7a9d0cfc..6e790b4ff00 100644 --- a/tests/components/rtsp_to_webrtc/conftest.py +++ b/tests/components/rtsp_to_webrtc/conftest.py @@ -39,7 +39,7 @@ async def webrtc_server() -> None: @pytest.fixture -async def mock_camera(hass) -> AsyncGenerator[None]: +async def mock_camera(hass: HomeAssistant) -> AsyncGenerator[None]: """Initialize a demo camera platform.""" assert await async_setup_component( hass, "camera", {camera.DOMAIN: {"platform": "demo"}} diff --git a/tests/components/sia/test_config_flow.py b/tests/components/sia/test_config_flow.py index 36f2292bdea..95de53d7fbe 100644 --- a/tests/components/sia/test_config_flow.py +++ b/tests/components/sia/test_config_flow.py @@ -139,7 +139,7 @@ async def entry_with_additional_account_config(hass, flow_at_add_account_step): ) -async def setup_sia(hass, config_entry: MockConfigEntry): +async def setup_sia(hass: HomeAssistant, config_entry: MockConfigEntry): """Add mock config to HASS.""" assert await async_setup_component(hass, DOMAIN, {}) config_entry.add_to_hass(hass) diff --git a/tests/components/smartthings/conftest.py b/tests/components/smartthings/conftest.py index baef9d9fa82..17e2c781989 100644 --- a/tests/components/smartthings/conftest.py +++ b/tests/components/smartthings/conftest.py @@ -55,7 +55,9 @@ from tests.components.light.conftest import mock_light_profiles # noqa: F401 COMPONENT_PREFIX = "homeassistant.components.smartthings." -async def setup_platform(hass, platform: str, *, devices=None, scenes=None): +async def setup_platform( + hass: HomeAssistant, platform: str, *, devices=None, scenes=None +): """Set up the SmartThings platform and prerequisites.""" hass.config.components.add(DOMAIN) config_entry = MockConfigEntry( diff --git a/tests/components/stream/test_hls.py b/tests/components/stream/test_hls.py index 6d0b1e12ab8..ce66848a2b1 100644 --- a/tests/components/stream/test_hls.py +++ b/tests/components/stream/test_hls.py @@ -46,7 +46,7 @@ HLS_CONFIG = { @pytest.fixture -async def setup_component(hass) -> None: +async def setup_component(hass: HomeAssistant) -> None: """Test fixture to setup the stream component.""" await async_setup_component(hass, "stream", HLS_CONFIG) diff --git a/tests/components/system_log/test_init.py b/tests/components/system_log/test_init.py index 94d3a1dd400..918d995fab9 100644 --- a/tests/components/system_log/test_init.py +++ b/tests/components/system_log/test_init.py @@ -13,6 +13,7 @@ from unittest.mock import MagicMock, patch from homeassistant.bootstrap import async_setup_component from homeassistant.components import system_log from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.typing import ConfigType from tests.common import async_capture_events from tests.typing import WebSocketGenerator @@ -89,7 +90,9 @@ class WatchLogErrorHandler(system_log.LogErrorHandler): self.watch_event.set() -async def async_setup_system_log(hass, config) -> WatchLogErrorHandler: +async def async_setup_system_log( + hass: HomeAssistant, config: ConfigType +) -> WatchLogErrorHandler: """Set up the system_log component.""" WatchLogErrorHandler.instances = [] with patch( diff --git a/tests/components/unifi/conftest.py b/tests/components/unifi/conftest.py index cbb570088c6..4a7d86eea38 100644 --- a/tests/components/unifi/conftest.py +++ b/tests/components/unifi/conftest.py @@ -65,7 +65,7 @@ def fixture_discovery(): @pytest.fixture(name="mock_device_registry") -def fixture_device_registry(hass, device_registry: dr.DeviceRegistry): +def fixture_device_registry(hass: HomeAssistant, device_registry: dr.DeviceRegistry): """Mock device registry.""" config_entry = MockConfigEntry(domain="something_else") config_entry.add_to_hass(hass) @@ -139,7 +139,9 @@ def fixture_known_wireless_clients() -> list[str]: @pytest.fixture(autouse=True, name="mock_wireless_client_storage") -def fixture_wireless_client_storage(hass_storage, known_wireless_clients: list[str]): +def fixture_wireless_client_storage( + hass_storage: dict[str, Any], known_wireless_clients: list[str] +): """Mock the known wireless storage.""" data: dict[str, list[str]] = ( {"wireless_clients": known_wireless_clients} if known_wireless_clients else {} diff --git a/tests/components/v2c/__init__.py b/tests/components/v2c/__init__.py index 6cb6662b850..02f8ade6179 100644 --- a/tests/components/v2c/__init__.py +++ b/tests/components/v2c/__init__.py @@ -1,9 +1,13 @@ """Tests for the V2C 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 V2C integration in Home Assistant.""" config_entry.add_to_hass(hass) diff --git a/tests/components/valve/test_init.py b/tests/components/valve/test_init.py index 704f690f2f8..3ef3b1ff4b0 100644 --- a/tests/components/valve/test_init.py +++ b/tests/components/valve/test_init.py @@ -131,7 +131,7 @@ def config_flow_fixture(hass: HomeAssistant) -> Generator[None]: @pytest.fixture -def mock_config_entry(hass) -> tuple[MockConfigEntry, list[ValveEntity]]: +def mock_config_entry(hass: HomeAssistant) -> tuple[MockConfigEntry, list[ValveEntity]]: """Mock a config entry which sets up a couple of valve entities.""" entities = [ MockBinaryValveEntity( diff --git a/tests/components/voip/conftest.py b/tests/components/voip/conftest.py index bcd9becbc5a..b039a49e0f0 100644 --- a/tests/components/voip/conftest.py +++ b/tests/components/voip/conftest.py @@ -17,7 +17,7 @@ from tests.common import MockConfigEntry @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", {}) diff --git a/tests/components/ws66i/test_media_player.py b/tests/components/ws66i/test_media_player.py index 2784d74d292..a66e79bf9e0 100644 --- a/tests/components/ws66i/test_media_player.py +++ b/tests/components/ws66i/test_media_player.py @@ -138,7 +138,7 @@ async def test_setup_success(hass: HomeAssistant) -> None: assert hass.states.get(ZONE_1_ID) is not None -async def _setup_ws66i(hass, ws66i) -> MockConfigEntry: +async def _setup_ws66i(hass: HomeAssistant, ws66i) -> MockConfigEntry: config_entry = MockConfigEntry( domain=DOMAIN, data=MOCK_CONFIG, options=MOCK_DEFAULT_OPTIONS ) @@ -154,7 +154,7 @@ async def _setup_ws66i(hass, ws66i) -> MockConfigEntry: return config_entry -async def _setup_ws66i_with_options(hass, ws66i) -> MockConfigEntry: +async def _setup_ws66i_with_options(hass: HomeAssistant, ws66i) -> MockConfigEntry: config_entry = MockConfigEntry( domain=DOMAIN, data=MOCK_CONFIG, options=MOCK_OPTIONS ) diff --git a/tests/components/xiaomi_ble/test_device_trigger.py b/tests/components/xiaomi_ble/test_device_trigger.py index 404eb6a4258..87a4d340d8c 100644 --- a/tests/components/xiaomi_ble/test_device_trigger.py +++ b/tests/components/xiaomi_ble/test_device_trigger.py @@ -35,7 +35,9 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]: return async_mock_service(hass, "test", "automation") -async def _async_setup_xiaomi_device(hass, mac: str, data: Any | None = None): +async def _async_setup_xiaomi_device( + hass: HomeAssistant, mac: str, data: Any | None = None +): config_entry = MockConfigEntry(domain=DOMAIN, unique_id=mac, data=data) config_entry.add_to_hass(hass) diff --git a/tests/components/zha/common.py b/tests/components/zha/common.py index addf1e24ea9..a8bec33a23a 100644 --- a/tests/components/zha/common.py +++ b/tests/components/zha/common.py @@ -14,6 +14,7 @@ from homeassistant.components.zha.core.helpers import ( async_get_zha_config_value, get_zha_gateway, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er import homeassistant.util.dt as dt_util @@ -102,7 +103,9 @@ def send_attribute_report(hass, cluster, attrid, value): return send_attributes_report(hass, cluster, {attrid: value}) -async def send_attributes_report(hass, cluster: zigpy.zcl.Cluster, attributes: dict): +async def send_attributes_report( + hass: HomeAssistant, cluster: zigpy.zcl.Cluster, attributes: dict +): """Cause the sensor to receive an attribute report from the network. This is to simulate the normal device communication that happens when a diff --git a/tests/components/zha/conftest.py b/tests/components/zha/conftest.py index 326c3cfcd76..410eaceda76 100644 --- a/tests/components/zha/conftest.py +++ b/tests/components/zha/conftest.py @@ -29,6 +29,7 @@ import homeassistant.components.zha.core.const as zha_const import homeassistant.components.zha.core.device as zha_core_device from homeassistant.components.zha.core.gateway import ZHAGateway from homeassistant.components.zha.core.helpers import get_zha_gateway +from homeassistant.core import HomeAssistant from homeassistant.helpers import restore_state from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -198,7 +199,7 @@ async def zigpy_app_controller(): @pytest.fixture(name="config_entry") -async def config_entry_fixture(hass) -> MockConfigEntry: +async def config_entry_fixture() -> MockConfigEntry: """Fixture representing a config entry.""" return MockConfigEntry( version=3, @@ -243,7 +244,9 @@ def mock_zigpy_connect( @pytest.fixture def setup_zha( - hass, config_entry: MockConfigEntry, mock_zigpy_connect: ControllerApplication + hass: HomeAssistant, + config_entry: MockConfigEntry, + mock_zigpy_connect: ControllerApplication, ): """Set up ZHA component.""" zha_config = {zha_const.CONF_ENABLE_QUIRKS: False} @@ -395,7 +398,7 @@ def zha_device_joined_restored(request: pytest.FixtureRequest): @pytest.fixture def zha_device_mock( - hass, config_entry, zigpy_device_mock + hass: HomeAssistant, config_entry, zigpy_device_mock ) -> Callable[..., zha_core_device.ZHADevice]: """Return a ZHA Device factory.""" diff --git a/tests/components/zha/test_discover.py b/tests/components/zha/test_discover.py index de30bc44b87..c59acc3395f 100644 --- a/tests/components/zha/test_discover.py +++ b/tests/components/zha/test_discover.py @@ -493,7 +493,7 @@ async def test_group_probe_cleanup_called( async def test_quirks_v2_entity_discovery( - hass, + hass: HomeAssistant, zigpy_device_mock, zha_device_joined, ) -> None: @@ -561,7 +561,7 @@ async def test_quirks_v2_entity_discovery( async def test_quirks_v2_entity_discovery_e1_curtain( - hass, + hass: HomeAssistant, zigpy_device_mock, zha_device_joined, ) -> None: diff --git a/tests/components/zha/test_light.py b/tests/components/zha/test_light.py index fda5971cbf7..a9d32362863 100644 --- a/tests/components/zha/test_light.py +++ b/tests/components/zha/test_light.py @@ -1466,7 +1466,11 @@ async def async_test_off_from_hass(hass, cluster, entity_id): async def async_test_level_on_off_from_hass( - hass, on_off_cluster, level_cluster, entity_id, expected_default_transition: int = 0 + hass: HomeAssistant, + on_off_cluster, + level_cluster, + entity_id, + expected_default_transition: int = 0, ): """Test on off functionality from hass."""