From d961e20b15c7c97879aec5267e3e08013f451f38 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:52:33 +0200 Subject: [PATCH] Add missing hass type hint in component tests (p) (#124227) --- tests/components/panasonic_viera/test_remote.py | 2 +- tests/components/pilight/test_sensor.py | 5 ++++- tests/components/plex/helpers.py | 3 ++- tests/components/point/test_config_flow.py | 6 ++++-- tests/components/powerwall/mocks.py | 5 +++-- tests/components/ps4/test_init.py | 2 +- tests/components/ps4/test_media_player.py | 9 +++++++-- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/components/panasonic_viera/test_remote.py b/tests/components/panasonic_viera/test_remote.py index 3ae241fc5e9c31..43f11c7d7666e0 100644 --- a/tests/components/panasonic_viera/test_remote.py +++ b/tests/components/panasonic_viera/test_remote.py @@ -18,7 +18,7 @@ from tests.common import MockConfigEntry -async def setup_panasonic_viera(hass): +async def setup_panasonic_viera(hass: HomeAssistant) -> None: """Initialize integration for tests.""" mock_entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/pilight/test_sensor.py b/tests/components/pilight/test_sensor.py index 9f529117642c0c..e960e46b50aa7d 100644 --- a/tests/components/pilight/test_sensor.py +++ b/tests/components/pilight/test_sensor.py @@ -1,6 +1,7 @@ """The tests for the Pilight sensor platform.""" import logging +from typing import Any import pytest @@ -17,7 +18,9 @@ def setup_comp(hass: HomeAssistant) -> None: mock_component(hass, "pilight") -def fire_pilight_message(hass, protocol, data): +def fire_pilight_message( + hass: HomeAssistant, protocol: str, data: dict[str, Any] +) -> None: """Fire the fake Pilight message.""" message = {pilight.CONF_PROTOCOL: protocol} message.update(data) diff --git a/tests/components/plex/helpers.py b/tests/components/plex/helpers.py index 4828b972d9d9ff..434c31996e4161 100644 --- a/tests/components/plex/helpers.py +++ b/tests/components/plex/helpers.py @@ -5,6 +5,7 @@ from plexwebsocket import SIGNAL_CONNECTION_STATE, STATE_CONNECTED +from homeassistant.core import HomeAssistant from homeassistant.helpers.typing import UNDEFINED, UndefinedType import homeassistant.util.dt as dt_util @@ -39,7 +40,7 @@ def trigger_plex_update( callback(msgtype, UPDATE_PAYLOAD if payload is UNDEFINED else payload, None) -async def wait_for_debouncer(hass): +async def wait_for_debouncer(hass: HomeAssistant) -> None: """Move time forward to wait for sensor debouncer.""" next_update = dt_util.utcnow() + timedelta(seconds=3) async_fire_time_changed(hass, next_update) diff --git a/tests/components/point/test_config_flow.py b/tests/components/point/test_config_flow.py index ec71b04b84bcd2..71f3f31ce8da55 100644 --- a/tests/components/point/test_config_flow.py +++ b/tests/components/point/test_config_flow.py @@ -10,7 +10,9 @@ from homeassistant.data_entry_flow import FlowResultType -def init_config_flow(hass, side_effect=None): +def init_config_flow( + hass: HomeAssistant, side_effect: type[Exception] | None = None +) -> config_flow.PointFlowHandler: """Init a configuration flow.""" config_flow.register_flow_implementation(hass, DOMAIN, "id", "secret") flow = config_flow.PointFlowHandler() @@ -22,7 +24,7 @@ def init_config_flow(hass, side_effect=None): @pytest.fixture -def is_authorized(): +def is_authorized() -> bool: """Set PointSession authorized.""" return True diff --git a/tests/components/powerwall/mocks.py b/tests/components/powerwall/mocks.py index e43ccee16f19f7..3081776483cc25 100644 --- a/tests/components/powerwall/mocks.py +++ b/tests/components/powerwall/mocks.py @@ -17,6 +17,7 @@ ) from homeassistant.core import HomeAssistant +from homeassistant.util.json import JsonValueType from tests.common import load_fixture @@ -87,7 +88,7 @@ async def _mock_powerwall_return_value( return powerwall_mock -async def _mock_powerwall_site_name(hass, site_name): +async def _mock_powerwall_site_name(hass: HomeAssistant, site_name: str) -> MagicMock: powerwall_mock = MagicMock(Powerwall) powerwall_mock.__aenter__.return_value = powerwall_mock @@ -110,7 +111,7 @@ async def _mock_powerwall_side_effect(site_info=None): return powerwall_mock -async def _async_load_json_fixture(hass, path): +async def _async_load_json_fixture(hass: HomeAssistant, path: str) -> JsonValueType: fixture = await hass.async_add_executor_job( load_fixture, os.path.join("powerwall", path) ) diff --git a/tests/components/ps4/test_init.py b/tests/components/ps4/test_init.py index 180f51295ac762..3a9aac386465ab 100644 --- a/tests/components/ps4/test_init.py +++ b/tests/components/ps4/test_init.py @@ -199,7 +199,7 @@ async def test_media_player_is_setup(hass: HomeAssistant) -> None: assert len(hass.data[PS4_DATA].devices) == 1 -async def setup_mock_component(hass): +async def setup_mock_component(hass: HomeAssistant) -> None: """Set up Mock Media Player.""" entry = MockConfigEntry(domain=ps4.DOMAIN, data=MOCK_DATA, version=VERSION) entry.add_to_manager(hass.config_entries) diff --git a/tests/components/ps4/test_media_player.py b/tests/components/ps4/test_media_player.py index e0be9d508fcea2..5268306c87af66 100644 --- a/tests/components/ps4/test_media_player.py +++ b/tests/components/ps4/test_media_player.py @@ -1,5 +1,6 @@ """Tests for the PS4 media player platform.""" +from typing import Any from unittest.mock import MagicMock, patch from pyps4_2ndscreen.credential import get_ddp_message @@ -130,7 +131,9 @@ MOCK_LOAD = "homeassistant.components.ps4.media_player.load_games" -async def setup_mock_component(hass, entry=None): +async def setup_mock_component( + hass: HomeAssistant, entry: MockConfigEntry | None = None +) -> str: """Set up Mock Media Player.""" if entry is None: mock_entry = MockConfigEntry( @@ -150,7 +153,9 @@ async def setup_mock_component(hass, entry=None): return mock_entities[0] -async def mock_ddp_response(hass, mock_status_data): +async def mock_ddp_response( + hass: HomeAssistant, mock_status_data: dict[str, Any] +) -> None: """Mock raw UDP response from device.""" mock_protocol = hass.data[PS4_DATA].protocol assert mock_protocol.local_port == DEFAULT_UDP_PORT