From ec5c3d63301b2fb80329997374df72cb1870541b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:43:51 +0100 Subject: [PATCH] Add type hints to integration tests (#88476) --- tests/components/elgato/test_light.py | 4 +-- tests/components/history_stats/test_sensor.py | 8 +++--- tests/components/insteon/test_api_scenes.py | 27 ++++++++++++++----- tests/components/litejet/test_light.py | 2 +- tests/components/litejet/test_scene.py | 2 +- tests/components/litejet/test_switch.py | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/components/elgato/test_light.py b/tests/components/elgato/test_light.py index 066e980653f..8a3d3382a5f 100644 --- a/tests/components/elgato/test_light.py +++ b/tests/components/elgato/test_light.py @@ -37,8 +37,8 @@ pytestmark = pytest.mark.usefixtures("init_integration") ) async def test_light_state_temperature( hass: HomeAssistant, - device_registry: dr.DeviceEntry, - entity_registry: er.RegistryEntry, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion, ) -> None: """Test the creation and values of the Elgato Lights in temperature mode.""" diff --git a/tests/components/history_stats/test_sensor.py b/tests/components/history_stats/test_sensor.py index 20c530dce3d..74194bed601 100644 --- a/tests/components/history_stats/test_sensor.py +++ b/tests/components/history_stats/test_sensor.py @@ -22,7 +22,7 @@ import homeassistant.util.dt as dt_util from tests.common import async_fire_time_changed, get_fixture_path -async def test_setup(recorder_mock, hass): +async def test_setup(recorder_mock: Recorder, hass: HomeAssistant) -> None: """Test the history statistics sensor setup.""" config = { @@ -44,7 +44,9 @@ async def test_setup(recorder_mock, hass): assert state.state == "0.0" -async def test_setup_multiple_states(recorder_mock, hass): +async def test_setup_multiple_states( + recorder_mock: Recorder, hass: HomeAssistant +) -> None: """Test the history statistics sensor setup for multiple states.""" config = { @@ -95,7 +97,7 @@ async def test_setup_multiple_states(recorder_mock, hass): }, ], ) -def test_setup_invalid_config(config): +def test_setup_invalid_config(config) -> None: """Test the history statistics sensor setup with invalid config.""" with pytest.raises(vol.Invalid): diff --git a/tests/components/insteon/test_api_scenes.py b/tests/components/insteon/test_api_scenes.py index a7779640526..9730f2427f3 100644 --- a/tests/components/insteon/test_api_scenes.py +++ b/tests/components/insteon/test_api_scenes.py @@ -1,5 +1,4 @@ """Test the Insteon Scenes APIs.""" - import json import os from unittest.mock import AsyncMock, patch @@ -10,10 +9,12 @@ import pytest from homeassistant.components.insteon.api import async_load_api, scenes from homeassistant.components.insteon.const import ID, TYPE +from homeassistant.core import HomeAssistant from .mock_devices import MockDevices from tests.common import load_fixture +from tests.typing import WebSocketGenerator @pytest.fixture(name="scene_data", scope="session") @@ -58,7 +59,9 @@ async def _setup(hass, hass_ws_client, scene_data): return ws_client, devices -async def test_get_scenes(hass, hass_ws_client, scene_data): +async def test_get_scenes( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data +) -> None: """Test getting all Insteon scenes.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) @@ -70,7 +73,9 @@ async def test_get_scenes(hass, hass_ws_client, scene_data): assert len(result["20"]) == 3 -async def test_get_scene(hass, hass_ws_client, scene_data): +async def test_get_scene( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data +) -> None: """Test getting an Insteon scene.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) @@ -81,7 +86,9 @@ async def test_get_scene(hass, hass_ws_client, scene_data): assert len(result["devices"]) == 3 -async def test_save_scene(hass, hass_ws_client, scene_data, remove_json): +async def test_save_scene( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json +) -> None: """Test saving an Insteon scene.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) @@ -108,7 +115,9 @@ async def test_save_scene(hass, hass_ws_client, scene_data, remove_json): assert result["scene_id"] == 20 -async def test_save_new_scene(hass, hass_ws_client, scene_data, remove_json): +async def test_save_new_scene( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json +) -> None: """Test saving a new Insteon scene.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) @@ -135,7 +144,9 @@ async def test_save_new_scene(hass, hass_ws_client, scene_data, remove_json): assert result["scene_id"] == 21 -async def test_save_scene_error(hass, hass_ws_client, scene_data, remove_json): +async def test_save_scene_error( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json +) -> None: """Test saving an Insteon scene with error.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) @@ -162,7 +173,9 @@ async def test_save_scene_error(hass, hass_ws_client, scene_data, remove_json): assert result["scene_id"] == 20 -async def test_delete_scene(hass, hass_ws_client, scene_data, remove_json): +async def test_delete_scene( + hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data, remove_json +) -> None: """Test delete an Insteon scene.""" ws_client, devices = await _setup(hass, hass_ws_client, scene_data) diff --git a/tests/components/litejet/test_light.py b/tests/components/litejet/test_light.py index dd3a905d509..32f121a88a3 100644 --- a/tests/components/litejet/test_light.py +++ b/tests/components/litejet/test_light.py @@ -178,7 +178,7 @@ async def test_deactivated_event(hass: HomeAssistant, mock_litejet) -> None: assert hass.states.get(ENTITY_OTHER_LIGHT).state == "off" -async def test_connected_event(hass, mock_litejet): +async def test_connected_event(hass: HomeAssistant, mock_litejet) -> None: """Test handling an event from LiteJet.""" await async_init_integration(hass) diff --git a/tests/components/litejet/test_scene.py b/tests/components/litejet/test_scene.py index af7a5f10e54..a430fc6387f 100644 --- a/tests/components/litejet/test_scene.py +++ b/tests/components/litejet/test_scene.py @@ -47,7 +47,7 @@ async def test_activate(hass: HomeAssistant, mock_litejet) -> None: mock_litejet.activate_scene.assert_called_once_with(ENTITY_SCENE_NUMBER) -async def test_connected_event(hass, mock_litejet): +async def test_connected_event(hass: HomeAssistant, mock_litejet) -> None: """Test handling an event from LiteJet.""" await async_init_integration(hass, use_scene=True) diff --git a/tests/components/litejet/test_switch.py b/tests/components/litejet/test_switch.py index 21ac42e7e92..472ccc9491a 100644 --- a/tests/components/litejet/test_switch.py +++ b/tests/components/litejet/test_switch.py @@ -84,7 +84,7 @@ async def test_released_event(hass: HomeAssistant, mock_litejet) -> None: assert hass.states.get(ENTITY_OTHER_SWITCH).state == STATE_OFF -async def test_connected_event(hass, mock_litejet): +async def test_connected_event(hass: HomeAssistant, mock_litejet) -> None: """Test handling an event from LiteJet.""" await async_init_integration(hass, use_switch=True)