Add missing hass type hint in alexa tests (#124064)
* Add missing hass type hint in alexa tests * One more
This commit is contained in:
parent
8a110abc82
commit
9b11aaf1eb
4 changed files with 69 additions and 31 deletions
|
@ -10,14 +10,14 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
|||
|
||||
|
||||
async def run_auth_get_access_token(
|
||||
hass,
|
||||
aioclient_mock,
|
||||
expires_in,
|
||||
client_id,
|
||||
client_secret,
|
||||
accept_grant_code,
|
||||
refresh_token,
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
expires_in: int,
|
||||
client_id: str,
|
||||
client_secret: str,
|
||||
accept_grant_code: str,
|
||||
refresh_token: str,
|
||||
) -> None:
|
||||
"""Do auth and request a new token for tests."""
|
||||
aioclient_mock.post(
|
||||
TEST_TOKEN_URL,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
"""Test helpers for the Alexa integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
from uuid import uuid4
|
||||
|
||||
|
@ -7,7 +10,7 @@ import pytest
|
|||
|
||||
from homeassistant.components.alexa import config, smart_home
|
||||
from homeassistant.components.alexa.const import CONF_ENDPOINT, CONF_FILTER, CONF_LOCALE
|
||||
from homeassistant.core import Context, HomeAssistant, callback
|
||||
from homeassistant.core import Context, HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import entityfilter
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
@ -62,7 +65,7 @@ class MockConfig(smart_home.AlexaConfig):
|
|||
"""Accept a grant."""
|
||||
|
||||
|
||||
def get_default_config(hass):
|
||||
def get_default_config(hass: HomeAssistant) -> MockConfig:
|
||||
"""Return a MockConfig instance."""
|
||||
return MockConfig(hass)
|
||||
|
||||
|
@ -93,15 +96,15 @@ def get_new_request(namespace, name, endpoint=None):
|
|||
|
||||
|
||||
async def assert_request_calls_service(
|
||||
namespace,
|
||||
name,
|
||||
endpoint,
|
||||
service,
|
||||
hass,
|
||||
namespace: str,
|
||||
name: str,
|
||||
endpoint: str,
|
||||
service: str,
|
||||
hass: HomeAssistant,
|
||||
response_type="Response",
|
||||
payload=None,
|
||||
instance=None,
|
||||
):
|
||||
payload: dict[str, Any] | None = None,
|
||||
instance: str | None = None,
|
||||
) -> tuple[ServiceCall, dict[str, Any]]:
|
||||
"""Assert an API request calls a hass service."""
|
||||
context = Context()
|
||||
request = get_new_request(namespace, name, endpoint)
|
||||
|
@ -129,8 +132,14 @@ async def assert_request_calls_service(
|
|||
|
||||
|
||||
async def assert_request_fails(
|
||||
namespace, name, endpoint, service_not_called, hass, payload=None, instance=None
|
||||
):
|
||||
namespace: str,
|
||||
name: str,
|
||||
endpoint: str,
|
||||
service_not_called: str,
|
||||
hass: HomeAssistant,
|
||||
payload: dict[str, Any] | None = None,
|
||||
instance: str | None = None,
|
||||
) -> None:
|
||||
"""Assert an API request returns an ErrorResponse."""
|
||||
request = get_new_request(namespace, name, endpoint)
|
||||
if payload:
|
||||
|
@ -152,8 +161,12 @@ async def assert_request_fails(
|
|||
|
||||
|
||||
async def assert_power_controller_works(
|
||||
endpoint, on_service, off_service, hass, timestamp
|
||||
):
|
||||
endpoint: str,
|
||||
on_service: str,
|
||||
off_service: str,
|
||||
hass: HomeAssistant,
|
||||
timestamp: str,
|
||||
) -> None:
|
||||
"""Assert PowerController API requests work."""
|
||||
_, response = await assert_request_calls_service(
|
||||
"Alexa.PowerController", "TurnOn", endpoint, on_service, hass
|
||||
|
@ -169,8 +182,12 @@ async def assert_power_controller_works(
|
|||
|
||||
|
||||
async def assert_scene_controller_works(
|
||||
endpoint, activate_service, deactivate_service, hass, timestamp
|
||||
):
|
||||
endpoint: str,
|
||||
activate_service: str,
|
||||
deactivate_service: str,
|
||||
hass: HomeAssistant,
|
||||
timestamp: str,
|
||||
) -> None:
|
||||
"""Assert SceneController API requests work."""
|
||||
_, response = await assert_request_calls_service(
|
||||
"Alexa.SceneController",
|
||||
|
@ -196,7 +213,9 @@ async def assert_scene_controller_works(
|
|||
assert response["event"]["payload"]["timestamp"] == timestamp
|
||||
|
||||
|
||||
async def reported_properties(hass, endpoint, return_full_response=False):
|
||||
async def reported_properties(
|
||||
hass: HomeAssistant, endpoint: str, return_full_response: bool = False
|
||||
) -> ReportedProperties:
|
||||
"""Use ReportState to get properties and return them.
|
||||
|
||||
The result is a ReportedProperties instance, which has methods to make
|
||||
|
|
|
@ -120,7 +120,9 @@ async def test_wrong_version(hass: HomeAssistant) -> None:
|
|||
await smart_home.async_handle_message(hass, get_default_config(hass), msg)
|
||||
|
||||
|
||||
async def discovery_test(device, hass, expected_endpoints=1):
|
||||
async def discovery_test(
|
||||
device, hass: HomeAssistant, expected_endpoints: int = 1
|
||||
) -> dict[str, Any] | list[dict[str, Any]] | None:
|
||||
"""Test alexa discovery request."""
|
||||
request = get_new_request("Alexa.Discovery", "Discover")
|
||||
|
||||
|
@ -2601,8 +2603,15 @@ async def test_stop_valve(
|
|||
|
||||
|
||||
async def assert_percentage_changes(
|
||||
hass, adjustments, namespace, name, endpoint, parameter, service, changed_parameter
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
adjustments,
|
||||
namespace,
|
||||
name,
|
||||
endpoint,
|
||||
parameter,
|
||||
service,
|
||||
changed_parameter,
|
||||
) -> None:
|
||||
"""Assert an API request making percentage changes works.
|
||||
|
||||
AdjustPercentage, AdjustBrightness, etc. are examples of such requests.
|
||||
|
@ -2616,8 +2625,15 @@ async def assert_percentage_changes(
|
|||
|
||||
|
||||
async def assert_range_changes(
|
||||
hass, adjustments, namespace, name, endpoint, service, changed_parameter, instance
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
adjustments: list[tuple[int | str, int, bool]],
|
||||
namespace: str,
|
||||
name: str,
|
||||
endpoint: str,
|
||||
service: str,
|
||||
changed_parameter: str | None,
|
||||
instance: str,
|
||||
) -> None:
|
||||
"""Assert an API request making range changes works.
|
||||
|
||||
AdjustRangeValue are examples of such requests.
|
||||
|
|
|
@ -5,6 +5,7 @@ import json
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import ClientResponse
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.alexa import DOMAIN, smart_home
|
||||
|
@ -17,7 +18,9 @@ from .test_common import get_new_request
|
|||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def do_http_discovery(config, hass, hass_client):
|
||||
async def do_http_discovery(
|
||||
config: dict[str, Any], hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||
) -> ClientResponse:
|
||||
"""Submit a request to the Smart Home HTTP API."""
|
||||
await async_setup_component(hass, DOMAIN, config)
|
||||
http_client = await hass_client()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue