From a0ed91e30c0d4f3db1d1961fd6433328c64002b7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:30:29 +0100 Subject: [PATCH] Add type hints to rest tests (#81304) --- tests/components/rest/test_binary_sensor.py | 35 ++++----- tests/components/rest/test_init.py | 13 ++-- tests/components/rest/test_notify.py | 3 +- tests/components/rest/test_sensor.py | 75 ++++++++++++-------- tests/components/rest/test_switch.py | 78 +++++++++++++++------ 5 files changed, 130 insertions(+), 74 deletions(-) diff --git a/tests/components/rest/test_binary_sensor.py b/tests/components/rest/test_binary_sensor.py index a6655f6ddbc..757c331529e 100644 --- a/tests/components/rest/test_binary_sensor.py +++ b/tests/components/rest/test_binary_sensor.py @@ -5,6 +5,7 @@ from http import HTTPStatus from unittest.mock import MagicMock, patch import httpx +import pytest import respx from homeassistant import config as hass_config @@ -26,7 +27,7 @@ from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_setup_missing_basic_config(hass): +async def test_setup_missing_basic_config(hass: HomeAssistant) -> None: """Test setup with configuration missing required entries.""" assert await async_setup_component( hass, Platform.BINARY_SENSOR, {"binary_sensor": {"platform": "rest"}} @@ -35,7 +36,7 @@ async def test_setup_missing_basic_config(hass): assert len(hass.states.async_all("binary_sensor")) == 0 -async def test_setup_missing_config(hass): +async def test_setup_missing_config(hass: HomeAssistant) -> None: """Test setup with configuration missing required entries.""" assert await async_setup_component( hass, @@ -53,7 +54,9 @@ async def test_setup_missing_config(hass): @respx.mock -async def test_setup_failed_connect(hass, caplog): +async def test_setup_failed_connect( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setup when connection error occurs.""" respx.get("http://localhost").mock( @@ -76,7 +79,7 @@ async def test_setup_failed_connect(hass, caplog): @respx.mock -async def test_setup_timeout(hass): +async def test_setup_timeout(hass: HomeAssistant) -> None: """Test setup when connection timeout occurs.""" respx.get("http://localhost").mock(side_effect=asyncio.TimeoutError()) assert await async_setup_component( @@ -95,7 +98,7 @@ async def test_setup_timeout(hass): @respx.mock -async def test_setup_minimum(hass): +async def test_setup_minimum(hass: HomeAssistant) -> None: """Test setup with minimum configuration.""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -114,7 +117,7 @@ async def test_setup_minimum(hass): @respx.mock -async def test_setup_minimum_resource_template(hass): +async def test_setup_minimum_resource_template(hass: HomeAssistant) -> None: """Test setup with minimum configuration (resource_template).""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -132,7 +135,7 @@ async def test_setup_minimum_resource_template(hass): @respx.mock -async def test_setup_duplicate_resource_template(hass): +async def test_setup_duplicate_resource_template(hass: HomeAssistant) -> None: """Test setup with duplicate resources.""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -151,7 +154,7 @@ async def test_setup_duplicate_resource_template(hass): @respx.mock -async def test_setup_get(hass): +async def test_setup_get(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -184,7 +187,7 @@ async def test_setup_get(hass): @respx.mock -async def test_setup_get_template_headers_params(hass): +async def test_setup_get_template_headers_params(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=200, json={}) assert await async_setup_component( @@ -218,7 +221,7 @@ async def test_setup_get_template_headers_params(hass): @respx.mock -async def test_setup_get_digest_auth(hass): +async def test_setup_get_digest_auth(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -246,7 +249,7 @@ async def test_setup_get_digest_auth(hass): @respx.mock -async def test_setup_post(hass): +async def test_setup_post(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.post("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -274,7 +277,7 @@ async def test_setup_post(hass): @respx.mock -async def test_setup_get_off(hass): +async def test_setup_get_off(hass: HomeAssistant) -> None: """Test setup with valid off configuration.""" respx.get("http://localhost").respond( status_code=HTTPStatus.OK, @@ -304,7 +307,7 @@ async def test_setup_get_off(hass): @respx.mock -async def test_setup_get_on(hass): +async def test_setup_get_on(hass: HomeAssistant) -> None: """Test setup with valid on configuration.""" respx.get("http://localhost").respond( status_code=HTTPStatus.OK, @@ -334,7 +337,7 @@ async def test_setup_get_on(hass): @respx.mock -async def test_setup_with_exception(hass): +async def test_setup_with_exception(hass: HomeAssistant) -> None: """Test setup with exception.""" respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -376,7 +379,7 @@ async def test_setup_with_exception(hass): @respx.mock -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Verify we can reload reset sensors.""" respx.get("http://localhost") % HTTPStatus.OK @@ -416,7 +419,7 @@ async def test_reload(hass): @respx.mock -async def test_setup_query_params(hass): +async def test_setup_query_params(hass: HomeAssistant) -> None: """Test setup with query params.""" respx.get("http://localhost", params={"search": "something"}) % HTTPStatus.OK assert await async_setup_component( diff --git a/tests/components/rest/test_init.py b/tests/components/rest/test_init.py index 988f88b348e..6dd2650c25c 100644 --- a/tests/components/rest/test_init.py +++ b/tests/components/rest/test_init.py @@ -15,6 +15,7 @@ from homeassistant.const import ( SERVICE_RELOAD, STATE_UNAVAILABLE, ) +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow @@ -22,7 +23,7 @@ from tests.common import async_fire_time_changed, get_fixture_path @respx.mock -async def test_setup_with_endpoint_timeout_with_recovery(hass): +async def test_setup_with_endpoint_timeout_with_recovery(hass: HomeAssistant) -> None: """Test setup with an endpoint that times out that recovers.""" await async_setup_component(hass, "homeassistant", {}) @@ -129,7 +130,7 @@ async def test_setup_with_endpoint_timeout_with_recovery(hass): @respx.mock -async def test_setup_minimum_resource_template(hass): +async def test_setup_minimum_resource_template(hass: HomeAssistant) -> None: """Test setup with minimum configuration (resource_template).""" respx.get("http://localhost").respond( @@ -187,7 +188,7 @@ async def test_setup_minimum_resource_template(hass): @respx.mock -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Verify we can reload.""" respx.get("http://localhost") % HTTPStatus.OK @@ -236,7 +237,7 @@ async def test_reload(hass): @respx.mock -async def test_reload_and_remove_all(hass): +async def test_reload_and_remove_all(hass: HomeAssistant) -> None: """Verify we can reload and remove all.""" respx.get("http://localhost") % HTTPStatus.OK @@ -283,7 +284,7 @@ async def test_reload_and_remove_all(hass): @respx.mock -async def test_reload_fails_to_read_configuration(hass): +async def test_reload_fails_to_read_configuration(hass: HomeAssistant) -> None: """Verify reload when configuration is missing or broken.""" respx.get("http://localhost") % HTTPStatus.OK @@ -327,7 +328,7 @@ async def test_reload_fails_to_read_configuration(hass): @respx.mock -async def test_multiple_rest_endpoints(hass): +async def test_multiple_rest_endpoints(hass: HomeAssistant) -> None: """Test multiple rest endpoints.""" respx.get("http://date.jsontest.com").respond( diff --git a/tests/components/rest/test_notify.py b/tests/components/rest/test_notify.py index 31567ae63f0..f9a2e88c732 100644 --- a/tests/components/rest/test_notify.py +++ b/tests/components/rest/test_notify.py @@ -7,13 +7,14 @@ from homeassistant import config as hass_config import homeassistant.components.notify as notify from homeassistant.components.rest import DOMAIN from homeassistant.const import SERVICE_RELOAD +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import get_fixture_path @respx.mock -async def test_reload_notify(hass): +async def test_reload_notify(hass: HomeAssistant) -> None: """Verify we can reload the notify service.""" respx.get("http://localhost") % 200 diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index a89d20f2510..49ad69b1caa 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -4,6 +4,7 @@ from http import HTTPStatus from unittest.mock import MagicMock, patch import httpx +import pytest import respx from homeassistant import config as hass_config @@ -31,14 +32,14 @@ from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_setup_missing_config(hass): +async def test_setup_missing_config(hass: HomeAssistant) -> None: """Test setup with configuration missing required entries.""" assert await async_setup_component(hass, DOMAIN, {"sensor": {"platform": "rest"}}) await hass.async_block_till_done() assert len(hass.states.async_all("sensor")) == 0 -async def test_setup_missing_schema(hass): +async def test_setup_missing_schema(hass: HomeAssistant) -> None: """Test setup with resource missing schema.""" assert await async_setup_component( hass, @@ -50,7 +51,9 @@ async def test_setup_missing_schema(hass): @respx.mock -async def test_setup_failed_connect(hass, caplog): +async def test_setup_failed_connect( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setup when connection error occurs.""" respx.get("http://localhost").mock( side_effect=httpx.RequestError("server offline", request=MagicMock()) @@ -72,7 +75,7 @@ async def test_setup_failed_connect(hass, caplog): @respx.mock -async def test_setup_timeout(hass): +async def test_setup_timeout(hass: HomeAssistant) -> None: """Test setup when connection timeout occurs.""" respx.get("http://localhost").mock(side_effect=asyncio.TimeoutError()) assert await async_setup_component( @@ -85,7 +88,7 @@ async def test_setup_timeout(hass): @respx.mock -async def test_setup_minimum(hass): +async def test_setup_minimum(hass: HomeAssistant) -> None: """Test setup with minimum configuration.""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -104,7 +107,7 @@ async def test_setup_minimum(hass): @respx.mock -async def test_manual_update(hass): +async def test_manual_update(hass: HomeAssistant) -> None: """Test setup with minimum configuration.""" await async_setup_component(hass, "homeassistant", {}) respx.get("http://localhost").respond( @@ -140,7 +143,7 @@ async def test_manual_update(hass): @respx.mock -async def test_setup_minimum_resource_template(hass): +async def test_setup_minimum_resource_template(hass: HomeAssistant) -> None: """Test setup with minimum configuration (resource_template).""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -158,7 +161,7 @@ async def test_setup_minimum_resource_template(hass): @respx.mock -async def test_setup_duplicate_resource_template(hass): +async def test_setup_duplicate_resource_template(hass: HomeAssistant) -> None: """Test setup with duplicate resources.""" respx.get("http://localhost") % HTTPStatus.OK assert await async_setup_component( @@ -177,7 +180,7 @@ async def test_setup_duplicate_resource_template(hass): @respx.mock -async def test_setup_get(hass): +async def test_setup_get(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -223,7 +226,9 @@ async def test_setup_get(hass): @respx.mock -async def test_setup_timestamp(hass, caplog): +async def test_setup_timestamp( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond( status_code=HTTPStatus.OK, json={"key": "2021-11-11 11:39Z"} @@ -286,7 +291,7 @@ async def test_setup_timestamp(hass, caplog): @respx.mock -async def test_setup_get_templated_headers_params(hass): +async def test_setup_get_templated_headers_params(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=200, json={}) assert await async_setup_component( @@ -320,7 +325,7 @@ async def test_setup_get_templated_headers_params(hass): @respx.mock -async def test_setup_get_digest_auth(hass): +async def test_setup_get_digest_auth(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -349,7 +354,7 @@ async def test_setup_get_digest_auth(hass): @respx.mock -async def test_setup_post(hass): +async def test_setup_post(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" respx.post("http://localhost").respond(status_code=HTTPStatus.OK, json={}) assert await async_setup_component( @@ -378,7 +383,7 @@ async def test_setup_post(hass): @respx.mock -async def test_setup_get_xml(hass): +async def test_setup_get_xml(hass: HomeAssistant) -> None: """Test setup with valid xml configuration.""" respx.get("http://localhost").respond( status_code=HTTPStatus.OK, @@ -410,7 +415,7 @@ async def test_setup_get_xml(hass): @respx.mock -async def test_setup_query_params(hass): +async def test_setup_query_params(hass: HomeAssistant) -> None: """Test setup with query params.""" respx.get("http://localhost", params={"search": "something"}) % HTTPStatus.OK assert await async_setup_component( @@ -430,7 +435,7 @@ async def test_setup_query_params(hass): @respx.mock -async def test_update_with_json_attrs(hass): +async def test_update_with_json_attrs(hass: HomeAssistant) -> None: """Test attributes get extracted from a JSON result.""" respx.get("http://localhost").respond( @@ -463,7 +468,7 @@ async def test_update_with_json_attrs(hass): @respx.mock -async def test_update_with_no_template(hass): +async def test_update_with_no_template(hass: HomeAssistant) -> None: """Test update when there is no value template.""" respx.get("http://localhost").respond( @@ -495,7 +500,9 @@ async def test_update_with_no_template(hass): @respx.mock -async def test_update_with_json_attrs_no_data(hass, caplog): +async def test_update_with_json_attrs_no_data( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test attributes when no JSON result fetched.""" respx.get("http://localhost").respond( @@ -531,7 +538,9 @@ async def test_update_with_json_attrs_no_data(hass, caplog): @respx.mock -async def test_update_with_json_attrs_not_dict(hass, caplog): +async def test_update_with_json_attrs_not_dict( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test attributes get extracted from a JSON result.""" respx.get("http://localhost").respond( @@ -566,7 +575,9 @@ async def test_update_with_json_attrs_not_dict(hass, caplog): @respx.mock -async def test_update_with_json_attrs_bad_JSON(hass, caplog): +async def test_update_with_json_attrs_bad_JSON( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test attributes get extracted from a JSON result.""" respx.get("http://localhost").respond( @@ -602,7 +613,7 @@ async def test_update_with_json_attrs_bad_JSON(hass, caplog): @respx.mock -async def test_update_with_json_attrs_with_json_attrs_path(hass): +async def test_update_with_json_attrs_with_json_attrs_path(hass: HomeAssistant) -> None: """Test attributes get extracted from a JSON result with a template for the attributes.""" respx.get("http://localhost").respond( @@ -646,7 +657,9 @@ async def test_update_with_json_attrs_with_json_attrs_path(hass): @respx.mock -async def test_update_with_xml_convert_json_attrs_with_json_attrs_path(hass): +async def test_update_with_xml_convert_json_attrs_with_json_attrs_path( + hass: HomeAssistant, +) -> None: """Test attributes get extracted from a JSON result that was converted from XML with a template for the attributes.""" respx.get("http://localhost").respond( @@ -682,7 +695,9 @@ async def test_update_with_xml_convert_json_attrs_with_json_attrs_path(hass): @respx.mock -async def test_update_with_xml_convert_json_attrs_with_jsonattr_template(hass): +async def test_update_with_xml_convert_json_attrs_with_jsonattr_template( + hass: HomeAssistant, +) -> None: """Test attributes get extracted from a JSON result that was converted from XML.""" respx.get("http://localhost").respond( @@ -722,8 +737,8 @@ async def test_update_with_xml_convert_json_attrs_with_jsonattr_template(hass): @respx.mock async def test_update_with_application_xml_convert_json_attrs_with_jsonattr_template( - hass, -): + hass: HomeAssistant, +) -> None: """Test attributes get extracted from a JSON result that was converted from XML with application/xml mime type.""" respx.get("http://localhost").respond( @@ -759,7 +774,9 @@ async def test_update_with_application_xml_convert_json_attrs_with_jsonattr_temp @respx.mock -async def test_update_with_xml_convert_bad_xml(hass, caplog): +async def test_update_with_xml_convert_bad_xml( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test attributes get extracted from a XML result with bad xml.""" respx.get("http://localhost").respond( @@ -794,7 +811,9 @@ async def test_update_with_xml_convert_bad_xml(hass, caplog): @respx.mock -async def test_update_with_failed_get(hass, caplog): +async def test_update_with_failed_get( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test attributes get extracted from a XML result with bad xml.""" respx.get("http://localhost").respond( @@ -829,7 +848,7 @@ async def test_update_with_failed_get(hass, caplog): @respx.mock -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Verify we can reload reset sensors.""" respx.get("http://localhost") % HTTPStatus.OK diff --git a/tests/components/rest/test_switch.py b/tests/components/rest/test_switch.py index a3c0f78db1c..6275314bcf0 100644 --- a/tests/components/rest/test_switch.py +++ b/tests/components/rest/test_switch.py @@ -33,12 +33,12 @@ STATE_RESOURCE = RESOURCE PARAMS = None -async def test_setup_missing_config(hass): +async def test_setup_missing_config(hass: HomeAssistant) -> None: """Test setup with configuration missing required entries.""" assert not await rest.async_setup_platform(hass, {CONF_PLATFORM: DOMAIN}, None) -async def test_setup_missing_schema(hass): +async def test_setup_missing_schema(hass: HomeAssistant) -> None: """Test setup with resource missing schema.""" assert not await rest.async_setup_platform( hass, @@ -47,7 +47,9 @@ async def test_setup_missing_schema(hass): ) -async def test_setup_failed_connect(hass, aioclient_mock): +async def test_setup_failed_connect( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup when connection error occurs.""" aioclient_mock.get("http://localhost", exc=aiohttp.ClientError) assert not await rest.async_setup_platform( @@ -57,7 +59,9 @@ async def test_setup_failed_connect(hass, aioclient_mock): ) -async def test_setup_timeout(hass, aioclient_mock): +async def test_setup_timeout( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup when connection timeout occurs.""" aioclient_mock.get("http://localhost", exc=asyncio.TimeoutError()) assert not await rest.async_setup_platform( @@ -67,7 +71,9 @@ async def test_setup_timeout(hass, aioclient_mock): ) -async def test_setup_minimum(hass, aioclient_mock): +async def test_setup_minimum( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup with minimum configuration.""" aioclient_mock.get("http://localhost", status=HTTPStatus.OK) with assert_setup_component(1, Platform.SWITCH): @@ -85,7 +91,9 @@ async def test_setup_minimum(hass, aioclient_mock): assert aioclient_mock.call_count == 1 -async def test_setup_query_params(hass, aioclient_mock): +async def test_setup_query_params( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup with query params.""" aioclient_mock.get("http://localhost/?search=something", status=HTTPStatus.OK) with assert_setup_component(1, Platform.SWITCH): @@ -105,7 +113,7 @@ async def test_setup_query_params(hass, aioclient_mock): assert aioclient_mock.call_count == 1 -async def test_setup(hass, aioclient_mock): +async def test_setup(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test setup with valid configuration.""" aioclient_mock.get("http://localhost", status=HTTPStatus.OK) assert await async_setup_component( @@ -127,7 +135,9 @@ async def test_setup(hass, aioclient_mock): assert_setup_component(1, Platform.SWITCH) -async def test_setup_with_state_resource(hass, aioclient_mock): +async def test_setup_with_state_resource( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup with valid configuration.""" aioclient_mock.get("http://localhost", status=HTTPStatus.NOT_FOUND) aioclient_mock.get("http://localhost/state", status=HTTPStatus.OK) @@ -151,7 +161,9 @@ async def test_setup_with_state_resource(hass, aioclient_mock): assert_setup_component(1, Platform.SWITCH) -async def test_setup_with_templated_headers_params(hass, aioclient_mock): +async def test_setup_with_templated_headers_params( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup with valid configuration.""" aioclient_mock.get("http://localhost", status=HTTPStatus.OK) assert await async_setup_component( @@ -185,7 +197,7 @@ async def test_setup_with_templated_headers_params(hass, aioclient_mock): """Tests for REST switch platform.""" -def _setup_test_switch(hass): +def _setup_test_switch(hass: HomeAssistant) -> None: body_on = Template("on", hass) body_off = Template("off", hass) headers = {"Content-type": Template(CONTENT_TYPE_JSON, hass)} @@ -211,25 +223,27 @@ def _setup_test_switch(hass): return switch, body_on, body_off -def test_name(hass): +def test_name(hass: HomeAssistant) -> None: """Test the name.""" switch, body_on, body_off = _setup_test_switch(hass) assert switch.name == NAME -def test_device_class(hass): +def test_device_class(hass: HomeAssistant) -> None: """Test the name.""" switch, body_on, body_off = _setup_test_switch(hass) assert switch.device_class == DEVICE_CLASS -def test_is_on_before_update(hass): +def test_is_on_before_update(hass: HomeAssistant) -> None: """Test is_on in initial state.""" switch, body_on, body_off = _setup_test_switch(hass) assert switch.is_on is None -async def test_turn_on_success(hass, aioclient_mock): +async def test_turn_on_success( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_on.""" aioclient_mock.post(RESOURCE, status=HTTPStatus.OK) switch, body_on, body_off = _setup_test_switch(hass) @@ -239,7 +253,9 @@ async def test_turn_on_success(hass, aioclient_mock): assert switch.is_on -async def test_turn_on_status_not_ok(hass, aioclient_mock): +async def test_turn_on_status_not_ok( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_on when error status returned.""" aioclient_mock.post(RESOURCE, status=HTTPStatus.INTERNAL_SERVER_ERROR) switch, body_on, body_off = _setup_test_switch(hass) @@ -249,7 +265,9 @@ async def test_turn_on_status_not_ok(hass, aioclient_mock): assert switch.is_on is None -async def test_turn_on_timeout(hass, aioclient_mock): +async def test_turn_on_timeout( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_on when timeout occurs.""" aioclient_mock.post(RESOURCE, status=HTTPStatus.INTERNAL_SERVER_ERROR) switch, body_on, body_off = _setup_test_switch(hass) @@ -258,7 +276,9 @@ async def test_turn_on_timeout(hass, aioclient_mock): assert switch.is_on is None -async def test_turn_off_success(hass, aioclient_mock): +async def test_turn_off_success( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_off.""" aioclient_mock.post(RESOURCE, status=HTTPStatus.OK) switch, body_on, body_off = _setup_test_switch(hass) @@ -268,7 +288,9 @@ async def test_turn_off_success(hass, aioclient_mock): assert not switch.is_on -async def test_turn_off_status_not_ok(hass, aioclient_mock): +async def test_turn_off_status_not_ok( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_off when error status returned.""" aioclient_mock.post(RESOURCE, status=HTTPStatus.INTERNAL_SERVER_ERROR) switch, body_on, body_off = _setup_test_switch(hass) @@ -278,7 +300,9 @@ async def test_turn_off_status_not_ok(hass, aioclient_mock): assert switch.is_on is None -async def test_turn_off_timeout(hass, aioclient_mock): +async def test_turn_off_timeout( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test turn_off when timeout occurs.""" aioclient_mock.post(RESOURCE, exc=asyncio.TimeoutError()) switch, body_on, body_off = _setup_test_switch(hass) @@ -287,7 +311,9 @@ async def test_turn_off_timeout(hass, aioclient_mock): assert switch.is_on is None -async def test_update_when_on(hass, aioclient_mock): +async def test_update_when_on( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test update when switch is on.""" switch, body_on, body_off = _setup_test_switch(hass) aioclient_mock.get(RESOURCE, text=body_on.template) @@ -296,7 +322,9 @@ async def test_update_when_on(hass, aioclient_mock): assert switch.is_on -async def test_update_when_off(hass, aioclient_mock): +async def test_update_when_off( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test update when switch is off.""" switch, body_on, body_off = _setup_test_switch(hass) aioclient_mock.get(RESOURCE, text=body_off.template) @@ -305,7 +333,9 @@ async def test_update_when_off(hass, aioclient_mock): assert not switch.is_on -async def test_update_when_unknown(hass, aioclient_mock): +async def test_update_when_unknown( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test update when unknown status returned.""" aioclient_mock.get(RESOURCE, text="unknown status") switch, body_on, body_off = _setup_test_switch(hass) @@ -314,7 +344,9 @@ async def test_update_when_unknown(hass, aioclient_mock): assert switch.is_on is None -async def test_update_timeout(hass, aioclient_mock): +async def test_update_timeout( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test update when timeout occurs.""" aioclient_mock.get(RESOURCE, exc=asyncio.TimeoutError()) switch, body_on, body_off = _setup_test_switch(hass)