From b53ae884a6247b0971a41c20c345331cb4e1fe61 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:16:34 +0200 Subject: [PATCH] Add missing hass type hint in component tests (o) (#124226) --- tests/components/onvif/__init__.py | 4 ++- tests/components/otbr/test_config_flow.py | 2 +- .../components/owntracks/test_config_flow.py | 2 +- .../owntracks/test_device_tracker.py | 31 +++++++++++++------ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/components/onvif/__init__.py b/tests/components/onvif/__init__.py index 0857dfef798..8a86538b977 100644 --- a/tests/components/onvif/__init__.py +++ b/tests/components/onvif/__init__.py @@ -151,7 +151,9 @@ def setup_mock_device(mock_device, capabilities=None): pullpoint_manager=MagicMock(state=PullPointManagerState.PAUSED), ) - def mock_constructor(hass, config): + def mock_constructor( + hass: HomeAssistant, config: config_entries.ConfigEntry + ) -> MagicMock: """Fake the controller constructor.""" return mock_device diff --git a/tests/components/otbr/test_config_flow.py b/tests/components/otbr/test_config_flow.py index b3f829eb4f0..c4972bb5f83 100644 --- a/tests/components/otbr/test_config_flow.py +++ b/tests/components/otbr/test_config_flow.py @@ -355,7 +355,7 @@ async def test_hassio_discovery_flow_2x_addons( aioclient_mock.get(f"{url1}/node/dataset/active", text="aa") aioclient_mock.get(f"{url2}/node/dataset/active", text="bb") - async def _addon_info(hass, slug): + async def _addon_info(hass: HomeAssistant, slug: str) -> dict[str, Any]: await asyncio.sleep(0) if slug == "otbr": return { diff --git a/tests/components/owntracks/test_config_flow.py b/tests/components/owntracks/test_config_flow.py index 818524c1c50..b1172eb4a31 100644 --- a/tests/components/owntracks/test_config_flow.py +++ b/tests/components/owntracks/test_config_flow.py @@ -51,7 +51,7 @@ def mock_not_supports_encryption(): yield -async def init_config_flow(hass): +async def init_config_flow(hass: HomeAssistant) -> config_flow.OwnTracksFlow: """Init a configuration flow.""" await async_process_ha_core_config( hass, diff --git a/tests/components/owntracks/test_device_tracker.py b/tests/components/owntracks/test_device_tracker.py index bc2ae7ce4d8..2f35139c021 100644 --- a/tests/components/owntracks/test_device_tracker.py +++ b/tests/components/owntracks/test_device_tracker.py @@ -4,6 +4,7 @@ import base64 from collections.abc import Callable, Generator import json import pickle +from typing import Any from unittest.mock import patch from nacl.encoding import Base64Encoder @@ -305,7 +306,9 @@ def setup_comp( hass.states.async_set("zone.outer", "zoning", OUTER_ZONE) -async def setup_owntracks(hass, config, ctx_cls=owntracks.OwnTracksContext): +async def setup_owntracks( + hass: HomeAssistant, config: dict[str, Any], ctx_cls=owntracks.OwnTracksContext +) -> None: """Set up OwnTracks.""" MockConfigEntry( domain="owntracks", data={"webhook_id": "owntracks_test", "secret": "abcd"} @@ -347,7 +350,9 @@ def context(hass: HomeAssistant, setup_comp: None) -> OwnTracksContextFactory: return get_context -async def send_message(hass, topic, message, corrupt=False): +async def send_message( + hass: HomeAssistant, topic: str, message: dict[str, Any], corrupt: bool = False +) -> None: """Test the sending of a message.""" str_message = json.dumps(message) if corrupt: @@ -359,51 +364,57 @@ async def send_message(hass, topic, message, corrupt=False): await hass.async_block_till_done() -def assert_location_state(hass, location): +def assert_location_state(hass: HomeAssistant, location: str) -> None: """Test the assertion of a location state.""" state = hass.states.get(DEVICE_TRACKER_STATE) assert state.state == location -def assert_location_latitude(hass, latitude): +def assert_location_latitude(hass: HomeAssistant, latitude: float) -> None: """Test the assertion of a location latitude.""" state = hass.states.get(DEVICE_TRACKER_STATE) assert state.attributes.get("latitude") == latitude -def assert_location_longitude(hass, longitude): +def assert_location_longitude(hass: HomeAssistant, longitude: float) -> None: """Test the assertion of a location longitude.""" state = hass.states.get(DEVICE_TRACKER_STATE) assert state.attributes.get("longitude") == longitude -def assert_location_accuracy(hass, accuracy): +def assert_location_accuracy(hass: HomeAssistant, accuracy: int) -> None: """Test the assertion of a location accuracy.""" state = hass.states.get(DEVICE_TRACKER_STATE) assert state.attributes.get("gps_accuracy") == accuracy -def assert_location_source_type(hass, source_type): +def assert_location_source_type(hass: HomeAssistant, source_type: str) -> None: """Test the assertion of source_type.""" state = hass.states.get(DEVICE_TRACKER_STATE) assert state.attributes.get("source_type") == source_type -def assert_mobile_tracker_state(hass, location, beacon=IBEACON_DEVICE): +def assert_mobile_tracker_state( + hass: HomeAssistant, location: str, beacon: str = IBEACON_DEVICE +) -> None: """Test the assertion of a mobile beacon tracker state.""" dev_id = MOBILE_BEACON_FMT.format(beacon) state = hass.states.get(dev_id) assert state.state == location -def assert_mobile_tracker_latitude(hass, latitude, beacon=IBEACON_DEVICE): +def assert_mobile_tracker_latitude( + hass: HomeAssistant, latitude: float, beacon: str = IBEACON_DEVICE +) -> None: """Test the assertion of a mobile beacon tracker latitude.""" dev_id = MOBILE_BEACON_FMT.format(beacon) state = hass.states.get(dev_id) assert state.attributes.get("latitude") == latitude -def assert_mobile_tracker_accuracy(hass, accuracy, beacon=IBEACON_DEVICE): +def assert_mobile_tracker_accuracy( + hass: HomeAssistant, accuracy: int, beacon: str = IBEACON_DEVICE +) -> None: """Test the assertion of a mobile beacon tracker accuracy.""" dev_id = MOBILE_BEACON_FMT.format(beacon) state = hass.states.get(dev_id)