diff --git a/tests/components/repairs/test_websocket_api.py b/tests/components/repairs/test_websocket_api.py index dcc6932cf4a..bb3d50f9eb5 100644 --- a/tests/components/repairs/test_websocket_api.py +++ b/tests/components/repairs/test_websocket_api.py @@ -18,7 +18,11 @@ from homeassistant.helpers import issue_registry as ir from homeassistant.setup import async_setup_component from tests.common import MockUser, mock_platform -from tests.typing import ClientSessionGenerator, WebSocketGenerator +from tests.typing import ( + ClientSessionGenerator, + MockHAClientWebSocket, + WebSocketGenerator, +) DEFAULT_ISSUES = [ { @@ -34,7 +38,11 @@ DEFAULT_ISSUES = [ ] -async def create_issues(hass, ws_client, issues=None): +async def create_issues( + hass: HomeAssistant, + ws_client: MockHAClientWebSocket, + issues: list[dict[str, Any]] | None = None, +) -> list[dict[str, Any]]: """Create issues.""" def api_issue(issue): @@ -119,7 +127,11 @@ async def mock_repairs_integration(hass: HomeAssistant) -> None: """Mock a repairs integration.""" hass.config.components.add("fake_integration") - def async_create_fix_flow(hass, issue_id, data): + def async_create_fix_flow( + hass: HomeAssistant, + issue_id: str, + data: dict[str, str | int | float | None] | None, + ) -> RepairsFlow: assert issue_id in EXPECTED_DATA assert data == EXPECTED_DATA[issue_id] diff --git a/tests/components/rfxtrx/test_config_flow.py b/tests/components/rfxtrx/test_config_flow.py index b61440c31b6..1e23bdaf982 100644 --- a/tests/components/rfxtrx/test_config_flow.py +++ b/tests/components/rfxtrx/test_config_flow.py @@ -29,7 +29,9 @@ def com_port(): return port -async def start_options_flow(hass, entry): +async def start_options_flow( + hass: HomeAssistant, entry: MockConfigEntry +) -> config_entries.ConfigFlowResult: """Start the options flow with the entry under test.""" entry.add_to_hass(hass) diff --git a/tests/components/rfxtrx/test_device_action.py b/tests/components/rfxtrx/test_device_action.py index c678f2dfc62..a3522934c57 100644 --- a/tests/components/rfxtrx/test_device_action.py +++ b/tests/components/rfxtrx/test_device_action.py @@ -47,7 +47,7 @@ async def test_device_test_data(rfxtrx, device: DeviceTestData) -> None: } -async def setup_entry(hass, devices): +async def setup_entry(hass: HomeAssistant, devices: dict[str, Any]) -> None: """Construct a config setup.""" entry_data = create_rfx_test_cfg(devices=devices) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) @@ -79,7 +79,10 @@ def _get_expected_actions(data): ], ) async def test_get_actions( - hass: HomeAssistant, device_registry: dr.DeviceRegistry, device, expected + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + device: DeviceTestData, + expected, ) -> None: """Test we get the expected actions from a rfxtrx.""" await setup_entry(hass, {device.code: {}}) @@ -136,7 +139,7 @@ async def test_action( hass: HomeAssistant, device_registry: dr.DeviceRegistry, rfxtrx: RFXtrx.Connect, - device, + device: DeviceTestData, config, expected, ) -> None: diff --git a/tests/components/rfxtrx/test_device_trigger.py b/tests/components/rfxtrx/test_device_trigger.py index 38f7cccc072..9c56951761b 100644 --- a/tests/components/rfxtrx/test_device_trigger.py +++ b/tests/components/rfxtrx/test_device_trigger.py @@ -46,7 +46,7 @@ EVENT_FIREALARM_1 = EventTestData( ) -async def setup_entry(hass, devices): +async def setup_entry(hass: HomeAssistant, devices: dict[str, Any]) -> None: """Construct a config setup.""" entry_data = create_rfx_test_cfg(devices=devices) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) diff --git a/tests/components/ring/common.py b/tests/components/ring/common.py index b129623aa95..3b78adf0e09 100644 --- a/tests/components/ring/common.py +++ b/tests/components/ring/common.py @@ -3,12 +3,14 @@ from unittest.mock import patch from homeassistant.components.ring import DOMAIN +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -async def setup_platform(hass, platform): +async def setup_platform(hass: HomeAssistant, platform: Platform) -> None: """Set up the ring platform and prerequisites.""" MockConfigEntry(domain=DOMAIN, data={"username": "foo", "token": {}}).add_to_hass( hass diff --git a/tests/components/risco/test_alarm_control_panel.py b/tests/components/risco/test_alarm_control_panel.py index 53d5b9573b6..9b554ddbf28 100644 --- a/tests/components/risco/test_alarm_control_panel.py +++ b/tests/components/risco/test_alarm_control_panel.py @@ -1,5 +1,7 @@ """Tests for the Risco alarm control panel device.""" +from collections.abc import Callable +from typing import Any from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch import pytest @@ -180,8 +182,13 @@ async def test_cloud_setup( async def _check_cloud_state( - hass, partitions, property, state, entity_id, partition_id -): + hass: HomeAssistant, + partitions: dict[int, Any], + property: str, + state: str, + entity_id: str, + partition_id: int, +) -> None: with patch.object(partitions[partition_id], property, return_value=True): await async_update_entity(hass, entity_id) await hass.async_block_till_done() @@ -256,7 +263,9 @@ async def test_cloud_states( ) -async def _call_alarm_service(hass, service, entity_id, **kwargs): +async def _call_alarm_service( + hass: HomeAssistant, service: str, entity_id: str, **kwargs: Any +) -> None: data = {"entity_id": entity_id, **kwargs} await hass.services.async_call( @@ -265,16 +274,27 @@ async def _call_alarm_service(hass, service, entity_id, **kwargs): async def _test_cloud_service_call( - hass, service, method, entity_id, partition_id, *args, **kwargs -): + hass: HomeAssistant, + service: str, + method: str, + entity_id: str, + partition_id: int, + *args: Any, + **kwargs: Any, +) -> None: with patch(f"homeassistant.components.risco.RiscoCloud.{method}") as set_mock: await _call_alarm_service(hass, service, entity_id, **kwargs) set_mock.assert_awaited_once_with(partition_id, *args) async def _test_cloud_no_service_call( - hass, service, method, entity_id, partition_id, **kwargs -): + hass: HomeAssistant, + service: str, + method: str, + entity_id: str, + partition_id: int, + **kwargs: Any, +) -> None: with patch(f"homeassistant.components.risco.RiscoCloud.{method}") as set_mock: await _call_alarm_service(hass, service, entity_id, **kwargs) set_mock.assert_not_awaited() @@ -531,8 +551,14 @@ async def test_local_setup( async def _check_local_state( - hass, partitions, property, state, entity_id, partition_id, callback -): + hass: HomeAssistant, + partitions: dict[int, Any], + property: str, + state: str, + entity_id: str, + partition_id: int, + callback: Callable, +) -> None: with patch.object(partitions[partition_id], property, return_value=True): await callback(partition_id, partitions[partition_id]) @@ -629,16 +655,27 @@ async def test_local_states( async def _test_local_service_call( - hass, service, method, entity_id, partition, *args, **kwargs -): + hass: HomeAssistant, + service: str, + method: str, + entity_id: str, + partition: int, + *args: Any, + **kwargs: Any, +) -> None: with patch.object(partition, method, AsyncMock()) as set_mock: await _call_alarm_service(hass, service, entity_id, **kwargs) set_mock.assert_awaited_once_with(*args) async def _test_local_no_service_call( - hass, service, method, entity_id, partition, **kwargs -): + hass: HomeAssistant, + service: str, + method: str, + entity_id: str, + partition: int, + **kwargs: Any, +) -> None: with patch.object(partition, method, AsyncMock()) as set_mock: await _call_alarm_service(hass, service, entity_id, **kwargs) set_mock.assert_not_awaited() diff --git a/tests/components/risco/test_binary_sensor.py b/tests/components/risco/test_binary_sensor.py index b6ff29a0bce..600cfa02c0e 100644 --- a/tests/components/risco/test_binary_sensor.py +++ b/tests/components/risco/test_binary_sensor.py @@ -1,6 +1,8 @@ """Tests for the Risco binary sensors.""" -from unittest.mock import PropertyMock, patch +from collections.abc import Callable +from typing import Any +from unittest.mock import MagicMock, PropertyMock, patch import pytest @@ -59,7 +61,13 @@ async def test_cloud_setup( assert device.manufacturer == "Risco" -async def _check_cloud_state(hass, zones, triggered, entity_id, zone_id): +async def _check_cloud_state( + hass: HomeAssistant, + zones: dict[int, Any], + triggered: bool, + entity_id: str, + zone_id: int, +) -> None: with patch.object( zones[zone_id], "triggered", @@ -130,8 +138,14 @@ async def test_local_setup( async def _check_local_state( - hass, zones, entity_property, value, entity_id, zone_id, callback -): + hass: HomeAssistant, + zones: dict[int, Any], + entity_property: str, + value: bool, + entity_id: str, + zone_id: int, + callback: Callable, +) -> None: with patch.object( zones[zone_id], entity_property, @@ -218,7 +232,13 @@ async def test_armed_local_states( ) -async def _check_system_state(hass, system, entity_property, value, callback): +async def _check_system_state( + hass: HomeAssistant, + system: MagicMock, + entity_property: str, + value: bool, + callback: Callable, +) -> None: with patch.object( system, entity_property, diff --git a/tests/components/risco/test_sensor.py b/tests/components/risco/test_sensor.py index 2b1094554ae..6a3ac6f42e3 100644 --- a/tests/components/risco/test_sensor.py +++ b/tests/components/risco/test_sensor.py @@ -136,7 +136,7 @@ async def test_error_on_login( assert not entity_registry.async_is_registered(entity_id) -def _check_state(hass, category, entity_id): +def _check_state(hass: HomeAssistant, category: str, entity_id: str) -> None: event_index = CATEGORIES_TO_EVENTS[category] event = TEST_EVENTS[event_index] state = hass.states.get(entity_id) diff --git a/tests/components/risco/test_switch.py b/tests/components/risco/test_switch.py index acf80462d54..54e7bc3ca0c 100644 --- a/tests/components/risco/test_switch.py +++ b/tests/components/risco/test_switch.py @@ -1,5 +1,7 @@ """Tests for the Risco binary sensors.""" +from collections.abc import Callable +from typing import Any from unittest.mock import PropertyMock, patch import pytest @@ -40,7 +42,13 @@ async def test_cloud_setup( assert entity_registry.async_is_registered(SECOND_ENTITY_ID) -async def _check_cloud_state(hass, zones, bypassed, entity_id, zone_id): +async def _check_cloud_state( + hass: HomeAssistant, + zones: dict[int, Any], + bypassed: bool, + entity_id: str, + zone_id: int, +) -> None: with patch.object( zones[zone_id], "bypassed", @@ -117,7 +125,14 @@ async def test_local_setup( assert entity_registry.async_is_registered(SECOND_ENTITY_ID) -async def _check_local_state(hass, zones, bypassed, entity_id, zone_id, callback): +async def _check_local_state( + hass: HomeAssistant, + zones: dict[int, Any], + bypassed: bool, + entity_id: str, + zone_id: int, + callback: Callable, +) -> None: with patch.object( zones[zone_id], "bypassed", diff --git a/tests/components/rpi_power/test_binary_sensor.py b/tests/components/rpi_power/test_binary_sensor.py index 1643df6c993..865d7c035b8 100644 --- a/tests/components/rpi_power/test_binary_sensor.py +++ b/tests/components/rpi_power/test_binary_sensor.py @@ -24,7 +24,7 @@ ENTITY_ID = "binary_sensor.rpi_power_status" MODULE = "homeassistant.components.rpi_power.binary_sensor.new_under_voltage" -async def _async_setup_component(hass, detected): +async def _async_setup_component(hass: HomeAssistant, detected: bool) -> MagicMock: mocked_under_voltage = MagicMock() type(mocked_under_voltage).get = MagicMock(return_value=detected) entry = MockConfigEntry(domain=DOMAIN)