1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add type hints to integration tests (a) (#87684)

* Add type hints to accuweather tests

* Adjust a** components

* Adjust aiohttp_client

* ClientSessionGenerator/WebSocketGenerator
This commit is contained in:
epenet
2023-02-08 12:16:23 +01:00
committed by GitHub
parent 7665c89b83
commit 2545694d41
79 changed files with 720 additions and 425 deletions

View File

@@ -66,12 +66,14 @@ from homeassistant.const import (
STATE_STANDBY,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_component import async_update_entity
from homeassistant.util import slugify
from . import patchers
from tests.common import MockConfigEntry
from tests.typing import ClientSessionGenerator
HOST = "127.0.0.1"
@@ -304,7 +306,7 @@ async def test_adb_shell_returns_none(hass, config):
assert state.state == STATE_UNAVAILABLE
async def test_setup_with_adbkey(hass):
async def test_setup_with_adbkey(hass: HomeAssistant) -> None:
"""Test that setup succeeds when using an ADB key."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_PYTHON_ADB_KEY)
config_entry.add_to_hass(hass)
@@ -496,7 +498,7 @@ async def test_select_source_androidtv(hass, source, expected_arg, method_patch)
)
async def test_androidtv_select_source_overridden_app_name(hass):
async def test_androidtv_select_source_overridden_app_name(hass: HomeAssistant) -> None:
"""Test that when an app name is overridden via the `apps` configuration parameter, the app is launched correctly."""
# Evidence that the default YouTube app ID will be overridden
conf_apps = {
@@ -564,7 +566,7 @@ async def test_setup_fail(hass, config, connect):
assert state is None
async def test_adb_command(hass):
async def test_adb_command(hass: HomeAssistant) -> None:
"""Test sending a command via the `androidtv.adb_command` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -593,7 +595,7 @@ async def test_adb_command(hass):
assert state.attributes["adb_response"] == response
async def test_adb_command_unicode_decode_error(hass):
async def test_adb_command_unicode_decode_error(hass: HomeAssistant) -> None:
"""Test sending a command via the `androidtv.adb_command` service that raises a UnicodeDecodeError exception."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -622,7 +624,7 @@ async def test_adb_command_unicode_decode_error(hass):
assert state.attributes["adb_response"] is None
async def test_adb_command_key(hass):
async def test_adb_command_key(hass: HomeAssistant) -> None:
"""Test sending a key command via the `androidtv.adb_command` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -651,7 +653,7 @@ async def test_adb_command_key(hass):
assert state.attributes["adb_response"] is None
async def test_adb_command_get_properties(hass):
async def test_adb_command_get_properties(hass: HomeAssistant) -> None:
"""Test sending the "GET_PROPERTIES" command via the `androidtv.adb_command` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -681,7 +683,7 @@ async def test_adb_command_get_properties(hass):
assert state.attributes["adb_response"] == str(response)
async def test_learn_sendevent(hass):
async def test_learn_sendevent(hass: HomeAssistant) -> None:
"""Test the `androidtv.learn_sendevent` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -710,7 +712,7 @@ async def test_learn_sendevent(hass):
assert state.attributes["adb_response"] == response
async def test_update_lock_not_acquired(hass):
async def test_update_lock_not_acquired(hass: HomeAssistant) -> None:
"""Test that the state does not get updated when a `LockNotAcquiredException` is raised."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -743,7 +745,7 @@ async def test_update_lock_not_acquired(hass):
assert state.state == STATE_STANDBY
async def test_download(hass):
async def test_download(hass: HomeAssistant) -> None:
"""Test the `androidtv.download` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -789,7 +791,7 @@ async def test_download(hass):
patch_pull.assert_called_with(local_path, device_path)
async def test_upload(hass):
async def test_upload(hass: HomeAssistant) -> None:
"""Test the `androidtv.upload` service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -835,7 +837,7 @@ async def test_upload(hass):
patch_push.assert_called_with(local_path, device_path)
async def test_androidtv_volume_set(hass):
async def test_androidtv_volume_set(hass: HomeAssistant) -> None:
"""Test setting the volume for an Android TV device."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -859,7 +861,9 @@ async def test_androidtv_volume_set(hass):
patch_set_volume_level.assert_called_with(0.5)
async def test_get_image_http(hass, hass_client_no_auth):
async def test_get_image_http(
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
) -> None:
"""Test taking a screen capture.
This is based on `test_get_image_http` in tests/components/media_player/test_init.py.
@@ -904,7 +908,7 @@ async def test_get_image_http(hass, hass_client_no_auth):
assert state.state == STATE_UNAVAILABLE
async def test_get_image_disabled(hass):
async def test_get_image_disabled(hass: HomeAssistant) -> None:
"""Test that the screencap option can disable entity_picture."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -959,7 +963,7 @@ async def _test_service(
assert service_call.called
async def test_services_androidtv(hass):
async def test_services_androidtv(hass: HomeAssistant) -> None:
"""Test media player services for an Android TV device."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -1000,7 +1004,7 @@ async def test_services_androidtv(hass):
)
async def test_services_firetv(hass):
async def test_services_firetv(hass: HomeAssistant) -> None:
"""Test media player services for a Fire TV device."""
patch_key, entity_id, config_entry = _setup(CONFIG_FIRETV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -1023,7 +1027,7 @@ async def test_services_firetv(hass):
await _test_service(hass, entity_id, SERVICE_TURN_ON, "adb_shell")
async def test_volume_mute(hass):
async def test_volume_mute(hass: HomeAssistant) -> None:
"""Test the volume mute service."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -1066,7 +1070,7 @@ async def test_volume_mute(hass):
assert mute_volume.called
async def test_connection_closed_on_ha_stop(hass):
async def test_connection_closed_on_ha_stop(hass: HomeAssistant) -> None:
"""Test that the ADB socket connection is closed when HA stops."""
patch_key, _, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)
@@ -1083,7 +1087,7 @@ async def test_connection_closed_on_ha_stop(hass):
assert adb_close.called
async def test_exception(hass):
async def test_exception(hass: HomeAssistant) -> None:
"""Test that the ADB connection gets closed when there is an unforeseen exception.
HA will attempt to reconnect on the next update.
@@ -1116,7 +1120,7 @@ async def test_exception(hass):
assert state.state == STATE_OFF
async def test_options_reload(hass):
async def test_options_reload(hass: HomeAssistant) -> None:
"""Test changing an option that will cause integration reload."""
patch_key, entity_id, config_entry = _setup(CONFIG_ANDROIDTV_DEFAULT)
config_entry.add_to_hass(hass)