diff --git a/tests/components/iaqualink/test_init.py b/tests/components/iaqualink/test_init.py index 8e157b8d1e3..1df199f706a 100644 --- a/tests/components/iaqualink/test_init.py +++ b/tests/components/iaqualink/test_init.py @@ -30,7 +30,7 @@ from .conftest import get_aqualink_device, get_aqualink_system from tests.common import async_fire_time_changed -async def _ffwd_next_update_interval(hass): +async def _ffwd_next_update_interval(hass: HomeAssistant) -> None: now = dt_util.utcnow() async_fire_time_changed(hass, now + UPDATE_INTERVAL) await hass.async_block_till_done() diff --git a/tests/components/image_processing/common.py b/tests/components/image_processing/common.py index 4b3a008c6cd..35b94f2c91c 100644 --- a/tests/components/image_processing/common.py +++ b/tests/components/image_processing/common.py @@ -6,19 +6,19 @@ components. Instead call the service directly. from homeassistant.components.image_processing import DOMAIN, SERVICE_SCAN from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.loader import bind_hass @bind_hass -def scan(hass, entity_id=ENTITY_MATCH_ALL): +def scan(hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL) -> None: """Force process of all cameras or given entity.""" hass.add_job(async_scan, hass, entity_id) @callback @bind_hass -def async_scan(hass, entity_id=ENTITY_MATCH_ALL): +def async_scan(hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL) -> None: """Force process of all cameras or given entity.""" data = {ATTR_ENTITY_ID: entity_id} if entity_id else None hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SCAN, data)) diff --git a/tests/components/image_processing/test_init.py b/tests/components/image_processing/test_init.py index 577d3fc47db..3e7c8f2fb91 100644 --- a/tests/components/image_processing/test_init.py +++ b/tests/components/image_processing/test_init.py @@ -35,13 +35,15 @@ def aiohttp_unused_port_factory( return unused_tcp_port_factory -def get_url(hass): +def get_url(hass: HomeAssistant) -> str: """Return camera url.""" state = hass.states.get("camera.demo_camera") return f"{hass.config.internal_url}{state.attributes.get(ATTR_ENTITY_PICTURE)}" -async def setup_image_processing(hass, aiohttp_unused_port_factory): +async def setup_image_processing( + hass: HomeAssistant, aiohttp_unused_port_factory: Callable[[], int] +) -> None: """Set up things to be run when tests are started.""" await async_setup_component( hass, @@ -55,7 +57,7 @@ async def setup_image_processing(hass, aiohttp_unused_port_factory): await hass.async_block_till_done() -async def setup_image_processing_face(hass): +async def setup_image_processing_face(hass: HomeAssistant) -> None: """Set up things to be run when tests are started.""" config = {ip.DOMAIN: {"platform": "demo"}, "camera": {"platform": "demo"}} @@ -93,7 +95,7 @@ async def test_setup_component_with_service(hass: HomeAssistant) -> None: async def test_get_image_from_camera( mock_camera_read, hass: HomeAssistant, - aiohttp_unused_port_factory, + aiohttp_unused_port_factory: Callable[[], int], ) -> None: """Grab an image from camera entity.""" await setup_image_processing(hass, aiohttp_unused_port_factory) @@ -116,7 +118,7 @@ async def test_get_image_from_camera( async def test_get_image_without_exists_camera( mock_image, hass: HomeAssistant, - aiohttp_unused_port_factory, + aiohttp_unused_port_factory: Callable[[], int], ) -> None: """Try to get image without exists camera.""" await setup_image_processing(hass, aiohttp_unused_port_factory) @@ -191,7 +193,7 @@ async def test_face_event_call_no_confidence( @pytest.mark.usefixtures("enable_custom_integrations") async def test_update_missing_camera( hass: HomeAssistant, - aiohttp_unused_port_factory, + aiohttp_unused_port_factory: Callable[[], int], caplog: pytest.LogCaptureFixture, ) -> None: """Test when entity does not set camera.""" diff --git a/tests/components/influxdb/test_init.py b/tests/components/influxdb/test_init.py index e9592a06fe2..f900be7b700 100644 --- a/tests/components/influxdb/test_init.py +++ b/tests/components/influxdb/test_init.py @@ -334,7 +334,9 @@ async def test_invalid_config( assert not await async_setup_component(hass, influxdb.DOMAIN, config) -async def _setup(hass, mock_influx_client, config_ext, get_write_api): +async def _setup( + hass: HomeAssistant, mock_influx_client, config_ext, get_write_api +) -> None: """Prepare client for next test and return event handler method.""" config = { "influxdb": { diff --git a/tests/components/influxdb/test_sensor.py b/tests/components/influxdb/test_sensor.py index 73dd8375a00..7f5954728a6 100644 --- a/tests/components/influxdb/test_sensor.py +++ b/tests/components/influxdb/test_sensor.py @@ -25,7 +25,7 @@ from homeassistant.components.influxdb.const import ( ) from homeassistant.components.influxdb.sensor import PLATFORM_SCHEMA from homeassistant.const import STATE_UNKNOWN -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, State from homeassistant.helpers.entity_platform import PLATFORM_NOT_READY_BASE_WAIT_TIME from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util @@ -190,7 +190,9 @@ def _set_query_mock_v2( return query_api -async def _setup(hass, config_ext, queries, expected_sensors): +async def _setup( + hass: HomeAssistant, config_ext, queries, expected_sensors +) -> list[State]: """Create client and test expected sensors.""" config = { DOMAIN: config_ext, diff --git a/tests/components/input_datetime/test_init.py b/tests/components/input_datetime/test_init.py index fdbb9a7803f..411f084d39a 100644 --- a/tests/components/input_datetime/test_init.py +++ b/tests/components/input_datetime/test_init.py @@ -79,7 +79,9 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]): return _storage -async def async_set_date_and_time(hass, entity_id, dt_value): +async def async_set_date_and_time( + hass: HomeAssistant, entity_id: str, dt_value: datetime.datetime +) -> None: """Set date and / or time of input_datetime.""" await hass.services.async_call( DOMAIN, @@ -93,7 +95,9 @@ async def async_set_date_and_time(hass, entity_id, dt_value): ) -async def async_set_datetime(hass, entity_id, dt_value): +async def async_set_datetime( + hass: HomeAssistant, entity_id: str, dt_value: datetime.datetime +) -> None: """Set date and / or time of input_datetime.""" await hass.services.async_call( DOMAIN, @@ -103,7 +107,9 @@ async def async_set_datetime(hass, entity_id, dt_value): ) -async def async_set_timestamp(hass, entity_id, timestamp): +async def async_set_timestamp( + hass: HomeAssistant, entity_id: str, timestamp: float +) -> None: """Set date and / or time of input_datetime.""" await hass.services.async_call( DOMAIN, diff --git a/tests/components/input_number/test_init.py b/tests/components/input_number/test_init.py index 73e41f347ce..8ea1c2e25b6 100644 --- a/tests/components/input_number/test_init.py +++ b/tests/components/input_number/test_init.py @@ -65,7 +65,7 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]): return _storage -async def set_value(hass, entity_id, value): +async def set_value(hass: HomeAssistant, entity_id: str, value: str) -> None: """Set input_number to value. This is a legacy helper method. Do not use it for new tests. @@ -78,7 +78,7 @@ async def set_value(hass, entity_id, value): ) -async def increment(hass, entity_id): +async def increment(hass: HomeAssistant, entity_id: str) -> None: """Increment value of entity. This is a legacy helper method. Do not use it for new tests. @@ -88,7 +88,7 @@ async def increment(hass, entity_id): ) -async def decrement(hass, entity_id): +async def decrement(hass: HomeAssistant, entity_id: str) -> None: """Decrement value of entity. This is a legacy helper method. Do not use it for new tests. diff --git a/tests/components/input_text/test_init.py b/tests/components/input_text/test_init.py index 3cae98b6dfe..2ca1d39a983 100644 --- a/tests/components/input_text/test_init.py +++ b/tests/components/input_text/test_init.py @@ -71,7 +71,7 @@ def storage_setup(hass: HomeAssistant, hass_storage: dict[str, Any]): return _storage -async def async_set_value(hass, entity_id, value): +async def async_set_value(hass: HomeAssistant, entity_id: str, value: str) -> None: """Set input_text to value.""" await hass.services.async_call( DOMAIN, diff --git a/tests/components/insteon/test_api_aldb.py b/tests/components/insteon/test_api_aldb.py index 4376628d9a4..9f3c78b4b39 100644 --- a/tests/components/insteon/test_api_aldb.py +++ b/tests/components/insteon/test_api_aldb.py @@ -1,6 +1,7 @@ """Test the Insteon All-Link Database APIs.""" import json +from typing import Any from unittest.mock import patch from pyinsteon import pub @@ -23,7 +24,7 @@ from homeassistant.core import HomeAssistant from .mock_devices import MockDevices from tests.common import load_fixture -from tests.typing import WebSocketGenerator +from tests.typing import MockHAClientWebSocket, WebSocketGenerator @pytest.fixture(name="aldb_data", scope="module") @@ -32,7 +33,9 @@ def aldb_data_fixture(): return json.loads(load_fixture("insteon/aldb_data.json")) -async def _setup(hass, hass_ws_client, aldb_data): +async def _setup( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data: dict[str, Any] +) -> tuple[MockHAClientWebSocket, MockDevices]: """Set up tests.""" ws_client = await hass_ws_client(hass) devices = MockDevices() diff --git a/tests/components/insteon/test_api_properties.py b/tests/components/insteon/test_api_properties.py index aee35cb8994..35ff95a5cc8 100644 --- a/tests/components/insteon/test_api_properties.py +++ b/tests/components/insteon/test_api_properties.py @@ -1,6 +1,7 @@ """Test the Insteon properties APIs.""" import json +from typing import Any from unittest.mock import AsyncMock, patch from pyinsteon.config import MOMENTARY_DELAY, RELAY_MODE, TOGGLE_BUTTON @@ -26,7 +27,7 @@ from homeassistant.core import HomeAssistant from .mock_devices import MockDevices from tests.common import load_fixture -from tests.typing import WebSocketGenerator +from tests.typing import MockHAClientWebSocket, WebSocketGenerator @pytest.fixture(name="kpl_properties_data", scope="module") @@ -41,7 +42,12 @@ def iolinc_properties_data_fixture(): return json.loads(load_fixture("insteon/iolinc_properties.json")) -async def _setup(hass, hass_ws_client, address, properties_data): +async def _setup( + hass: HomeAssistant, + hass_ws_client: WebSocketGenerator, + address: str, + properties_data: dict[str, Any], +) -> tuple[MockHAClientWebSocket, MockDevices]: """Set up tests.""" ws_client = await hass_ws_client(hass) devices = MockDevices() diff --git a/tests/components/insteon/test_config_flow.py b/tests/components/insteon/test_config_flow.py index 51fdd7a550d..31d38a603f1 100644 --- a/tests/components/insteon/test_config_flow.py +++ b/tests/components/insteon/test_config_flow.py @@ -1,6 +1,8 @@ """Test the config flow for the Insteon integration.""" -from unittest.mock import patch +from collections.abc import Callable +from typing import Any +from unittest.mock import AsyncMock, patch import pytest from voluptuous_serialize import convert @@ -14,7 +16,7 @@ from homeassistant.components.insteon.config_flow import ( STEP_PLM_MANUALLY, ) from homeassistant.components.insteon.const import CONF_HUB_VERSION, DOMAIN -from homeassistant.config_entries import ConfigEntryState +from homeassistant.config_entries import ConfigEntryState, ConfigFlowResult from homeassistant.const import CONF_DEVICE, CONF_HOST from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -60,7 +62,7 @@ async def mock_failed_connection(*args, **kwargs): raise ConnectionError("Connection failed") -async def _init_form(hass, modem_type): +async def _init_form(hass: HomeAssistant, modem_type: str) -> ConfigFlowResult: """Run the user form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -73,7 +75,12 @@ async def _init_form(hass, modem_type): ) -async def _device_form(hass, flow_id, connection, user_input): +async def _device_form( + hass: HomeAssistant, + flow_id: str, + connection: Callable[..., Any], + user_input: dict[str, Any] | None, +) -> tuple[ConfigFlowResult, AsyncMock]: """Test the PLM, Hub v1 or Hub v2 form.""" with ( patch( diff --git a/tests/components/izone/test_config_flow.py b/tests/components/izone/test_config_flow.py index 6591e402ec2..3c9707b34c6 100644 --- a/tests/components/izone/test_config_flow.py +++ b/tests/components/izone/test_config_flow.py @@ -1,5 +1,7 @@ """Tests for iZone.""" +from collections.abc import Callable +from typing import Any from unittest.mock import Mock, patch import pytest @@ -12,7 +14,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send @pytest.fixture -def mock_disco(): +def mock_disco() -> Mock: """Mock discovery service.""" disco = Mock() disco.pi_disco = Mock() @@ -20,15 +22,15 @@ def mock_disco(): return disco -def _mock_start_discovery(hass, mock_disco): - def do_disovered(*args): +def _mock_start_discovery(hass: HomeAssistant, mock_disco: Mock) -> Callable[..., Mock]: + def do_disovered(*args: Any) -> Mock: async_dispatcher_send(hass, DISPATCH_CONTROLLER_DISCOVERED, True) return mock_disco return do_disovered -async def test_not_found(hass: HomeAssistant, mock_disco) -> None: +async def test_not_found(hass: HomeAssistant, mock_disco: Mock) -> None: """Test not finding iZone controller.""" with ( @@ -56,7 +58,7 @@ async def test_not_found(hass: HomeAssistant, mock_disco) -> None: stop_disco.assert_called_once() -async def test_found(hass: HomeAssistant, mock_disco) -> None: +async def test_found(hass: HomeAssistant, mock_disco: Mock) -> None: """Test not finding iZone controller.""" mock_disco.pi_disco.controllers["blah"] = object()