Add type hints to integration tests (part 15) (#88006)
This commit is contained in:
parent
6c23d6abfe
commit
50cbabb2d8
51 changed files with 896 additions and 427 deletions
|
@ -3,7 +3,6 @@
|
|||
These tests fake out the subscriber/devicemanager, and are not using a real
|
||||
pubsub subscriber.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
@ -26,6 +25,7 @@ from .common import DEVICE_ID, CreateDevice, FakeSubscriber, PlatformSetup
|
|||
from .conftest import FakeAuth
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
PLATFORM = "camera"
|
||||
CAMERA_DEVICE_TYPE = "sdm.devices.types.CAMERA"
|
||||
|
@ -178,7 +178,7 @@ async def fire_alarm(hass, point_in_time):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_no_devices(hass: HomeAssistant, setup_platform: PlatformSetup):
|
||||
async def test_no_devices(hass: HomeAssistant, setup_platform: PlatformSetup) -> None:
|
||||
"""Test configuration that returns no devices."""
|
||||
await setup_platform()
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
@ -186,7 +186,7 @@ async def test_no_devices(hass: HomeAssistant, setup_platform: PlatformSetup):
|
|||
|
||||
async def test_ineligible_device(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test configuration with devices that do not support cameras."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -202,7 +202,7 @@ async def test_ineligible_device(
|
|||
|
||||
async def test_camera_device(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, camera_device: None
|
||||
):
|
||||
) -> None:
|
||||
"""Test a basic camera with a live stream."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -230,7 +230,7 @@ async def test_camera_stream(
|
|||
camera_device: None,
|
||||
auth: FakeAuth,
|
||||
mock_create_stream: Mock,
|
||||
):
|
||||
) -> None:
|
||||
"""Test a basic camera and fetch its live stream."""
|
||||
auth.responses = [make_stream_url_response()]
|
||||
await setup_platform()
|
||||
|
@ -248,13 +248,13 @@ async def test_camera_stream(
|
|||
|
||||
|
||||
async def test_camera_ws_stream(
|
||||
hass,
|
||||
hass: HomeAssistant,
|
||||
setup_platform,
|
||||
camera_device,
|
||||
hass_ws_client,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
auth,
|
||||
mock_create_stream,
|
||||
):
|
||||
) -> None:
|
||||
"""Test a basic camera that supports web rtc."""
|
||||
auth.responses = [make_stream_url_response()]
|
||||
await setup_platform()
|
||||
|
@ -284,8 +284,12 @@ async def test_camera_ws_stream(
|
|||
|
||||
|
||||
async def test_camera_ws_stream_failure(
|
||||
hass, setup_platform, camera_device, hass_ws_client, auth
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
setup_platform,
|
||||
camera_device,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
auth,
|
||||
) -> None:
|
||||
"""Test a basic camera that supports web rtc."""
|
||||
auth.responses = [aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST)]
|
||||
await setup_platform()
|
||||
|
@ -312,7 +316,9 @@ async def test_camera_ws_stream_failure(
|
|||
assert msg["error"]["message"].startswith("Nest API error")
|
||||
|
||||
|
||||
async def test_camera_stream_missing_trait(hass, setup_platform, create_device):
|
||||
async def test_camera_stream_missing_trait(
|
||||
hass: HomeAssistant, setup_platform, create_device
|
||||
) -> None:
|
||||
"""Test fetching a video stream when not supported by the API."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -346,7 +352,7 @@ async def test_refresh_expired_stream_token(
|
|||
setup_platform: PlatformSetup,
|
||||
auth: FakeAuth,
|
||||
camera_device: None,
|
||||
):
|
||||
) -> None:
|
||||
"""Test a camera stream expiration and refresh."""
|
||||
now = utcnow()
|
||||
stream_1_expiration = now + datetime.timedelta(seconds=90)
|
||||
|
@ -423,7 +429,7 @@ async def test_stream_response_already_expired(
|
|||
auth: FakeAuth,
|
||||
setup_platform: PlatformSetup,
|
||||
camera_device: None,
|
||||
):
|
||||
) -> None:
|
||||
"""Test a API response returning an expired stream url."""
|
||||
now = utcnow()
|
||||
stream_1_expiration = now + datetime.timedelta(seconds=-90)
|
||||
|
@ -456,7 +462,7 @@ async def test_camera_removed(
|
|||
camera_device: None,
|
||||
subscriber: FakeSubscriber,
|
||||
setup_platform: PlatformSetup,
|
||||
):
|
||||
) -> None:
|
||||
"""Test case where entities are removed and stream tokens revoked."""
|
||||
await setup_platform()
|
||||
# Simplify test setup
|
||||
|
@ -486,7 +492,7 @@ async def test_camera_remove_failure(
|
|||
auth: FakeAuth,
|
||||
camera_device: None,
|
||||
setup_platform: PlatformSetup,
|
||||
):
|
||||
) -> None:
|
||||
"""Test case where revoking the stream token fails on unload."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -516,7 +522,7 @@ async def test_refresh_expired_stream_failure(
|
|||
auth: FakeAuth,
|
||||
setup_platform: PlatformSetup,
|
||||
camera_device: None,
|
||||
):
|
||||
) -> None:
|
||||
"""Tests a failure when refreshing the stream."""
|
||||
now = utcnow()
|
||||
stream_1_expiration = now + datetime.timedelta(seconds=90)
|
||||
|
@ -569,8 +575,12 @@ async def test_refresh_expired_stream_failure(
|
|||
|
||||
|
||||
async def test_camera_web_rtc(
|
||||
hass, auth, hass_ws_client, webrtc_camera_device, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
webrtc_camera_device,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a basic camera that supports web rtc."""
|
||||
expiration = utcnow() + datetime.timedelta(seconds=100)
|
||||
auth.responses = [
|
||||
|
@ -614,8 +624,12 @@ async def test_camera_web_rtc(
|
|||
|
||||
|
||||
async def test_camera_web_rtc_unsupported(
|
||||
hass, auth, hass_ws_client, camera_device, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
camera_device,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a basic camera that supports web rtc."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -644,8 +658,12 @@ async def test_camera_web_rtc_unsupported(
|
|||
|
||||
|
||||
async def test_camera_web_rtc_offer_failure(
|
||||
hass, auth, hass_ws_client, webrtc_camera_device, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
webrtc_camera_device,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a basic camera that supports web rtc."""
|
||||
auth.responses = [
|
||||
aiohttp.web.Response(status=HTTPStatus.BAD_REQUEST),
|
||||
|
@ -676,8 +694,13 @@ async def test_camera_web_rtc_offer_failure(
|
|||
|
||||
|
||||
async def test_camera_multiple_streams(
|
||||
hass, auth, hass_ws_client, create_device, setup_platform, mock_create_stream
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
mock_create_stream,
|
||||
) -> None:
|
||||
"""Test a camera supporting multiple stream types."""
|
||||
expiration = utcnow() + datetime.timedelta(seconds=100)
|
||||
auth.responses = [
|
||||
|
|
|
@ -113,7 +113,7 @@ async def test_climate_devices(
|
|||
|
||||
async def test_thermostat_off(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is not running."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ async def test_thermostat_off(
|
|||
|
||||
async def test_thermostat_heat(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is heating."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ async def test_thermostat_heat(
|
|||
|
||||
async def test_thermostat_cool(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is cooling."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -236,7 +236,7 @@ async def test_thermostat_cool(
|
|||
|
||||
async def test_thermostat_heatcool(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is cooling in heatcool mode."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -1489,7 +1489,7 @@ async def test_thermostat_hvac_mode_failure(
|
|||
|
||||
async def test_thermostat_available(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is available."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -1519,7 +1519,7 @@ async def test_thermostat_available(
|
|||
|
||||
async def test_thermostat_unavailable(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, create_device: CreateDevice
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat that is unavailable."""
|
||||
create_device.create(
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Test the Google Nest Device Access config flow."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
@ -21,6 +20,7 @@ from homeassistant.components.application_credentials import (
|
|||
)
|
||||
from homeassistant.components.nest.const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
|
||||
|
@ -197,7 +197,9 @@ async def oauth(hass, hass_client_no_auth, aioclient_mock, current_request_with_
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_app_credentials(hass, oauth, subscriber, setup_platform):
|
||||
async def test_app_credentials(
|
||||
hass: HomeAssistant, oauth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Check full flow."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -229,7 +231,9 @@ async def test_app_credentials(hass, oauth, subscriber, setup_platform):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_flow_restart(hass, oauth, subscriber, setup_platform):
|
||||
async def test_config_flow_restart(
|
||||
hass: HomeAssistant, oauth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Check with auth implementation is re-initialized when aborting the flow."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -280,7 +284,9 @@ async def test_config_flow_restart(hass, oauth, subscriber, setup_platform):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_flow_wrong_project_id(hass, oauth, subscriber, setup_platform):
|
||||
async def test_config_flow_wrong_project_id(
|
||||
hass: HomeAssistant, oauth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Check the case where the wrong project ids are entered."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -331,11 +337,11 @@ async def test_config_flow_wrong_project_id(hass, oauth, subscriber, setup_platf
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_flow_pubsub_configuration_error(
|
||||
hass,
|
||||
hass: HomeAssistant,
|
||||
oauth,
|
||||
setup_platform,
|
||||
mock_subscriber,
|
||||
):
|
||||
) -> None:
|
||||
"""Check full flow fails with configuration error."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -354,8 +360,8 @@ async def test_config_flow_pubsub_configuration_error(
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_flow_pubsub_subscriber_error(
|
||||
hass, oauth, setup_platform, mock_subscriber
|
||||
):
|
||||
hass: HomeAssistant, oauth, setup_platform, mock_subscriber
|
||||
) -> None:
|
||||
"""Check full flow with a subscriber error."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -374,7 +380,7 @@ async def test_config_flow_pubsub_subscriber_error(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_YAML_ONLY])
|
||||
async def test_config_yaml_ignored(hass, oauth, setup_platform):
|
||||
async def test_config_yaml_ignored(hass: HomeAssistant, oauth, setup_platform) -> None:
|
||||
"""Check full flow."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -391,7 +397,9 @@ async def test_config_yaml_ignored(hass, oauth, setup_platform):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIG_YAML_ONLY])
|
||||
async def test_web_reauth(hass, oauth, setup_platform, config_entry):
|
||||
async def test_web_reauth(
|
||||
hass: HomeAssistant, oauth, setup_platform, config_entry
|
||||
) -> None:
|
||||
"""Test Nest reauthentication."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -415,7 +423,9 @@ async def test_web_reauth(hass, oauth, setup_platform, config_entry):
|
|||
assert entry.data.get("subscriber_id") == orig_subscriber_id # Not updated
|
||||
|
||||
|
||||
async def test_multiple_config_entries(hass, oauth, setup_platform):
|
||||
async def test_multiple_config_entries(
|
||||
hass: HomeAssistant, oauth, setup_platform
|
||||
) -> None:
|
||||
"""Verify config flow can be started when existing config entry exists."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -434,7 +444,9 @@ async def test_multiple_config_entries(hass, oauth, setup_platform):
|
|||
assert len(entries) == 2
|
||||
|
||||
|
||||
async def test_duplicate_config_entries(hass, oauth, setup_platform):
|
||||
async def test_duplicate_config_entries(
|
||||
hass: HomeAssistant, oauth, setup_platform
|
||||
) -> None:
|
||||
"""Verify that config entries must be for unique projects."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -457,8 +469,8 @@ async def test_duplicate_config_entries(hass, oauth, setup_platform):
|
|||
|
||||
|
||||
async def test_reauth_multiple_config_entries(
|
||||
hass, oauth, setup_platform, config_entry
|
||||
):
|
||||
hass: HomeAssistant, oauth, setup_platform, config_entry
|
||||
) -> None:
|
||||
"""Test Nest reauthentication with multiple existing config entries."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -508,7 +520,9 @@ async def test_reauth_multiple_config_entries(
|
|||
@pytest.mark.parametrize(
|
||||
"nest_test_config,auth_implementation", [(TEST_CONFIG_HYBRID, APP_AUTH_DOMAIN)]
|
||||
)
|
||||
async def test_app_auth_yaml_reauth(hass, oauth, setup_platform, config_entry):
|
||||
async def test_app_auth_yaml_reauth(
|
||||
hass: HomeAssistant, oauth, setup_platform, config_entry
|
||||
) -> None:
|
||||
"""Test reauth for deprecated app auth credentails upgrade instructions."""
|
||||
|
||||
await setup_platform()
|
||||
|
@ -571,7 +585,9 @@ async def test_app_auth_yaml_reauth(hass, oauth, setup_platform, config_entry):
|
|||
@pytest.mark.parametrize(
|
||||
"nest_test_config,auth_implementation", [(TEST_CONFIG_YAML_ONLY, WEB_AUTH_DOMAIN)]
|
||||
)
|
||||
async def test_web_auth_yaml_reauth(hass, oauth, setup_platform, config_entry):
|
||||
async def test_web_auth_yaml_reauth(
|
||||
hass: HomeAssistant, oauth, setup_platform, config_entry
|
||||
) -> None:
|
||||
"""Test Nest reauthentication for Installed App Auth."""
|
||||
|
||||
await setup_platform()
|
||||
|
@ -597,8 +613,8 @@ async def test_web_auth_yaml_reauth(hass, oauth, setup_platform, config_entry):
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_pubsub_subscription_strip_whitespace(
|
||||
hass, oauth, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant, oauth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Check that project id has whitespace stripped on entry."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -626,8 +642,8 @@ async def test_pubsub_subscription_strip_whitespace(
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_pubsub_subscription_auth_failure(
|
||||
hass, oauth, setup_platform, mock_subscriber
|
||||
):
|
||||
hass: HomeAssistant, oauth, setup_platform, mock_subscriber
|
||||
) -> None:
|
||||
"""Check flow that creates a pub/sub subscription."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -646,8 +662,13 @@ async def test_pubsub_subscription_auth_failure(
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIG_APP_CREDS])
|
||||
async def test_pubsub_subscriber_config_entry_reauth(
|
||||
hass, oauth, setup_platform, subscriber, config_entry, auth_implementation
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
oauth,
|
||||
setup_platform,
|
||||
subscriber,
|
||||
config_entry,
|
||||
auth_implementation,
|
||||
) -> None:
|
||||
"""Test the pubsub subscriber id is preserved during reauth."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -670,7 +691,9 @@ async def test_pubsub_subscriber_config_entry_reauth(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_entry_title_from_home(hass, oauth, setup_platform, subscriber):
|
||||
async def test_config_entry_title_from_home(
|
||||
hass: HomeAssistant, oauth, setup_platform, subscriber
|
||||
) -> None:
|
||||
"""Test that the Google Home name is used for the config entry title."""
|
||||
|
||||
device_manager = await subscriber.async_get_device_manager()
|
||||
|
@ -703,8 +726,8 @@ async def test_config_entry_title_from_home(hass, oauth, setup_platform, subscri
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_config_entry_title_multiple_homes(
|
||||
hass, oauth, setup_platform, subscriber
|
||||
):
|
||||
hass: HomeAssistant, oauth, setup_platform, subscriber
|
||||
) -> None:
|
||||
"""Test handling of multiple Google Homes authorized."""
|
||||
|
||||
device_manager = await subscriber.async_get_device_manager()
|
||||
|
@ -745,7 +768,9 @@ async def test_config_entry_title_multiple_homes(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_title_failure_fallback(hass, oauth, setup_platform, mock_subscriber):
|
||||
async def test_title_failure_fallback(
|
||||
hass: HomeAssistant, oauth, setup_platform, mock_subscriber
|
||||
) -> None:
|
||||
"""Test exception handling when determining the structure names."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -763,7 +788,9 @@ async def test_title_failure_fallback(hass, oauth, setup_platform, mock_subscrib
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_structure_missing_trait(hass, oauth, setup_platform, subscriber):
|
||||
async def test_structure_missing_trait(
|
||||
hass: HomeAssistant, oauth, setup_platform, subscriber
|
||||
) -> None:
|
||||
"""Test handling the case where a structure has no name set."""
|
||||
|
||||
device_manager = await subscriber.async_get_device_manager()
|
||||
|
@ -790,7 +817,7 @@ async def test_structure_missing_trait(hass, oauth, setup_platform, subscriber):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [NestTestConfig()])
|
||||
async def test_dhcp_discovery(hass, oauth, subscriber):
|
||||
async def test_dhcp_discovery(hass: HomeAssistant, oauth, subscriber) -> None:
|
||||
"""Exercise discovery dhcp starts the config flow and kicks user to frontend creds flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
|
@ -807,7 +834,9 @@ async def test_dhcp_discovery(hass, oauth, subscriber):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_dhcp_discovery_with_creds(hass, oauth, subscriber, setup_platform):
|
||||
async def test_dhcp_discovery_with_creds(
|
||||
hass: HomeAssistant, oauth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Exercise discovery dhcp with no config present (can't run)."""
|
||||
await setup_platform()
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ async def test_no_triggers(
|
|||
assert triggers == []
|
||||
|
||||
|
||||
async def test_fires_on_camera_motion(hass, calls):
|
||||
async def test_fires_on_camera_motion(hass: HomeAssistant, calls) -> None:
|
||||
"""Test camera_motion triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
|
@ -244,7 +244,7 @@ async def test_fires_on_camera_motion(hass, calls):
|
|||
assert calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_camera_person(hass, calls):
|
||||
async def test_fires_on_camera_person(hass: HomeAssistant, calls) -> None:
|
||||
"""Test camera_person triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_person")
|
||||
|
||||
|
@ -255,7 +255,7 @@ async def test_fires_on_camera_person(hass, calls):
|
|||
assert calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_camera_sound(hass, calls):
|
||||
async def test_fires_on_camera_sound(hass: HomeAssistant, calls) -> None:
|
||||
"""Test camera_person triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_sound")
|
||||
|
||||
|
@ -266,7 +266,7 @@ async def test_fires_on_camera_sound(hass, calls):
|
|||
assert calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_doorbell_chime(hass, calls):
|
||||
async def test_fires_on_doorbell_chime(hass: HomeAssistant, calls) -> None:
|
||||
"""Test doorbell_chime triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "doorbell_chime")
|
||||
|
||||
|
@ -277,7 +277,7 @@ async def test_fires_on_doorbell_chime(hass, calls):
|
|||
assert calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_trigger_for_wrong_device_id(hass, calls):
|
||||
async def test_trigger_for_wrong_device_id(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for turn_on and turn_off triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
|
@ -291,7 +291,7 @@ async def test_trigger_for_wrong_device_id(hass, calls):
|
|||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_trigger_for_wrong_event_type(hass, calls):
|
||||
async def test_trigger_for_wrong_event_type(hass: HomeAssistant, calls) -> None:
|
||||
"""Test for turn_on and turn_off triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Test nest diagnostics."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from google_nest_sdm.exceptions import SubscriberException
|
||||
|
@ -7,6 +6,7 @@ import pytest
|
|||
|
||||
from homeassistant.components.nest.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .common import TEST_CONFIG_LEGACY
|
||||
|
@ -15,6 +15,7 @@ from tests.components.diagnostics import (
|
|||
get_diagnostics_for_config_entry,
|
||||
get_diagnostics_for_device,
|
||||
)
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
NEST_DEVICE_ID = "enterprises/project-id/devices/device-id"
|
||||
|
||||
|
@ -88,8 +89,12 @@ def platforms() -> list[str]:
|
|||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass, hass_client, create_device, setup_platform, config_entry
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=DEVICE_API_DATA)
|
||||
await setup_platform()
|
||||
|
@ -102,8 +107,12 @@ async def test_entry_diagnostics(
|
|||
|
||||
|
||||
async def test_device_diagnostics(
|
||||
hass, hass_client, create_device, setup_platform, config_entry
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=DEVICE_API_DATA)
|
||||
await setup_platform()
|
||||
|
@ -120,11 +129,11 @@ async def test_device_diagnostics(
|
|||
|
||||
|
||||
async def test_setup_susbcriber_failure(
|
||||
hass,
|
||||
hass_client,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry,
|
||||
setup_base_platform,
|
||||
):
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
with patch(
|
||||
"homeassistant.components.nest.api.GoogleNestSubscriber.start_async",
|
||||
|
@ -139,8 +148,11 @@ async def test_setup_susbcriber_failure(
|
|||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIG_LEGACY])
|
||||
async def test_legacy_config_entry_diagnostics(
|
||||
hass, hass_client, config_entry, setup_base_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry,
|
||||
setup_base_platform,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics for legacy integration doesn't fail."""
|
||||
|
||||
with patch("homeassistant.components.nest.legacy.Nest"):
|
||||
|
@ -150,8 +162,12 @@ async def test_legacy_config_entry_diagnostics(
|
|||
|
||||
|
||||
async def test_camera_diagnostics(
|
||||
hass, hass_client, create_device, setup_platform, config_entry
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=CAMERA_API_DATA)
|
||||
await setup_platform()
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
These tests fake out the subscriber/devicemanager, and are not using a real
|
||||
pubsub subscriber.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
|
@ -15,6 +14,7 @@ from google_nest_sdm.device import Device
|
|||
from google_nest_sdm.event import EventMessage
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
|
@ -150,8 +150,14 @@ def create_events(events, device_id=DEVICE_ID, timestamp=None):
|
|||
],
|
||||
)
|
||||
async def test_event(
|
||||
hass, auth, setup_platform, subscriber, event_trait, expected_model, expected_type
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
setup_platform,
|
||||
subscriber,
|
||||
event_trait,
|
||||
expected_model,
|
||||
expected_type,
|
||||
) -> None:
|
||||
"""Test a pubsub message for a doorbell event."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -187,7 +193,9 @@ async def test_event(
|
|||
["sdm.devices.traits.CameraMotion", "sdm.devices.traits.CameraPerson"],
|
||||
],
|
||||
)
|
||||
async def test_camera_multiple_event(hass, subscriber, setup_platform):
|
||||
async def test_camera_multiple_event(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for a camera person event."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -224,7 +232,7 @@ async def test_camera_multiple_event(hass, subscriber, setup_platform):
|
|||
}
|
||||
|
||||
|
||||
async def test_unknown_event(hass, subscriber, setup_platform):
|
||||
async def test_unknown_event(hass: HomeAssistant, subscriber, setup_platform) -> None:
|
||||
"""Test a pubsub message for an unknown event type."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -234,7 +242,9 @@ async def test_unknown_event(hass, subscriber, setup_platform):
|
|||
assert len(events) == 0
|
||||
|
||||
|
||||
async def test_unknown_device_id(hass, subscriber, setup_platform):
|
||||
async def test_unknown_device_id(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for an unknown event type."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -246,7 +256,9 @@ async def test_unknown_device_id(hass, subscriber, setup_platform):
|
|||
assert len(events) == 0
|
||||
|
||||
|
||||
async def test_event_message_without_device_event(hass, subscriber, setup_platform):
|
||||
async def test_event_message_without_device_event(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for an unknown event type."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -270,7 +282,9 @@ async def test_event_message_without_device_event(hass, subscriber, setup_platfo
|
|||
["sdm.devices.traits.CameraClipPreview", "sdm.devices.traits.CameraPerson"],
|
||||
],
|
||||
)
|
||||
async def test_doorbell_event_thread(hass, subscriber, setup_platform):
|
||||
async def test_doorbell_event_thread(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a series of pubsub messages in the same thread."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -339,7 +353,9 @@ async def test_doorbell_event_thread(hass, subscriber, setup_platform):
|
|||
],
|
||||
],
|
||||
)
|
||||
async def test_doorbell_event_session_update(hass, subscriber, setup_platform):
|
||||
async def test_doorbell_event_session_update(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message with updates to an existing session."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -401,7 +417,9 @@ async def test_doorbell_event_session_update(hass, subscriber, setup_platform):
|
|||
}
|
||||
|
||||
|
||||
async def test_structure_update_event(hass, subscriber, setup_platform):
|
||||
async def test_structure_update_event(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for a new device being added."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
@ -463,7 +481,7 @@ async def test_structure_update_event(hass, subscriber, setup_platform):
|
|||
["sdm.devices.traits.CameraMotion"],
|
||||
],
|
||||
)
|
||||
async def test_event_zones(hass, subscriber, setup_platform):
|
||||
async def test_event_zones(hass: HomeAssistant, subscriber, setup_platform) -> None:
|
||||
"""Test events published with zone information."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
"""Test basic initialization for the Legacy Nest API using mocks for the Nest python library."""
|
||||
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import TEST_CONFIG_ENTRY_LEGACY, TEST_CONFIG_LEGACY
|
||||
|
||||
DOMAIN = "nest"
|
||||
|
@ -36,7 +37,7 @@ def make_thermostat():
|
|||
@pytest.mark.parametrize(
|
||||
"nest_test_config", [TEST_CONFIG_LEGACY, TEST_CONFIG_ENTRY_LEGACY]
|
||||
)
|
||||
async def test_thermostat(hass, setup_base_platform):
|
||||
async def test_thermostat(hass: HomeAssistant, setup_base_platform) -> None:
|
||||
"""Test simple initialization for thermostat entities."""
|
||||
|
||||
thermostat = make_thermostat()
|
||||
|
|
|
@ -7,7 +7,6 @@ By default all tests use test fixtures that run in each possible configuration
|
|||
mode (e.g. yaml, ConfigEntry, etc) however some tests override and just run in
|
||||
relevant modes.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
@ -22,6 +21,7 @@ import pytest
|
|||
|
||||
from homeassistant.components.nest import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import (
|
||||
PROJECT_ID,
|
||||
|
@ -74,7 +74,7 @@ def failing_subscriber(subscriber_side_effect: Any) -> YieldFixture[FakeSubscrib
|
|||
yield subscriber
|
||||
|
||||
|
||||
async def test_setup_success(hass, error_caplog, setup_platform):
|
||||
async def test_setup_success(hass: HomeAssistant, error_caplog, setup_platform) -> None:
|
||||
"""Test successful setup."""
|
||||
await setup_platform()
|
||||
assert not error_caplog.records
|
||||
|
@ -86,8 +86,11 @@ async def test_setup_success(hass, error_caplog, setup_platform):
|
|||
|
||||
@pytest.mark.parametrize("subscriber_id", [("invalid-subscriber-format")])
|
||||
async def test_setup_configuration_failure(
|
||||
hass, caplog, subscriber_id, setup_base_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
subscriber_id,
|
||||
setup_base_platform,
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
await setup_base_platform()
|
||||
|
||||
|
@ -102,8 +105,8 @@ async def test_setup_configuration_failure(
|
|||
|
||||
@pytest.mark.parametrize("subscriber_side_effect", [SubscriberException()])
|
||||
async def test_setup_susbcriber_failure(
|
||||
hass, warning_caplog, failing_subscriber, setup_base_platform
|
||||
):
|
||||
hass: HomeAssistant, warning_caplog, failing_subscriber, setup_base_platform
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
await setup_base_platform()
|
||||
assert "Subscriber error:" in warning_caplog.text
|
||||
|
@ -113,7 +116,9 @@ async def test_setup_susbcriber_failure(
|
|||
assert entries[0].state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_setup_device_manager_failure(hass, warning_caplog, setup_base_platform):
|
||||
async def test_setup_device_manager_failure(
|
||||
hass: HomeAssistant, warning_caplog, setup_base_platform
|
||||
) -> None:
|
||||
"""Test device manager api failure."""
|
||||
with patch(
|
||||
"homeassistant.components.nest.api.GoogleNestSubscriber.start_async"
|
||||
|
@ -132,8 +137,11 @@ async def test_setup_device_manager_failure(hass, warning_caplog, setup_base_pla
|
|||
|
||||
@pytest.mark.parametrize("subscriber_side_effect", [AuthException()])
|
||||
async def test_subscriber_auth_failure(
|
||||
hass, caplog, setup_base_platform, failing_subscriber
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_base_platform,
|
||||
failing_subscriber,
|
||||
) -> None:
|
||||
"""Test subscriber throws an authentication error."""
|
||||
await setup_base_platform()
|
||||
|
||||
|
@ -147,7 +155,9 @@ async def test_subscriber_auth_failure(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("subscriber_id", [(None)])
|
||||
async def test_setup_missing_subscriber_id(hass, warning_caplog, setup_base_platform):
|
||||
async def test_setup_missing_subscriber_id(
|
||||
hass: HomeAssistant, warning_caplog, setup_base_platform
|
||||
) -> None:
|
||||
"""Test missing susbcriber id from configuration."""
|
||||
await setup_base_platform()
|
||||
assert "Configuration option" in warning_caplog.text
|
||||
|
@ -159,8 +169,8 @@ async def test_setup_missing_subscriber_id(hass, warning_caplog, setup_base_plat
|
|||
|
||||
@pytest.mark.parametrize("subscriber_side_effect", [(ConfigurationException())])
|
||||
async def test_subscriber_configuration_failure(
|
||||
hass, error_caplog, setup_base_platform, failing_subscriber
|
||||
):
|
||||
hass: HomeAssistant, error_caplog, setup_base_platform, failing_subscriber
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
await setup_base_platform()
|
||||
assert "Configuration error: " in error_caplog.text
|
||||
|
@ -174,7 +184,9 @@ async def test_subscriber_configuration_failure(
|
|||
"nest_test_config",
|
||||
[TEST_CONFIGFLOW_APP_CREDS],
|
||||
)
|
||||
async def test_empty_config(hass, error_caplog, config, setup_platform):
|
||||
async def test_empty_config(
|
||||
hass: HomeAssistant, error_caplog, config, setup_platform
|
||||
) -> None:
|
||||
"""Test setup is a no-op with not config."""
|
||||
await setup_platform()
|
||||
assert not error_caplog.records
|
||||
|
@ -183,7 +195,7 @@ async def test_empty_config(hass, error_caplog, config, setup_platform):
|
|||
assert len(entries) == 0
|
||||
|
||||
|
||||
async def test_unload_entry(hass, setup_platform):
|
||||
async def test_unload_entry(hass: HomeAssistant, setup_platform) -> None:
|
||||
"""Test successful unload of a ConfigEntry."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -214,7 +226,9 @@ async def test_unload_entry(hass, setup_platform):
|
|||
],
|
||||
ids=["yaml-config-only", "hybrid-config", "config-entry"],
|
||||
)
|
||||
async def test_remove_entry(hass, nest_test_config, setup_base_platform, delete_called):
|
||||
async def test_remove_entry(
|
||||
hass: HomeAssistant, nest_test_config, setup_base_platform, delete_called
|
||||
) -> None:
|
||||
"""Test successful unload of a ConfigEntry."""
|
||||
with patch(
|
||||
"homeassistant.components.nest.api.GoogleNestSubscriber",
|
||||
|
@ -248,8 +262,8 @@ async def test_remove_entry(hass, nest_test_config, setup_base_platform, delete_
|
|||
ids=["hyrbid-config", "app-creds"],
|
||||
)
|
||||
async def test_remove_entry_delete_subscriber_failure(
|
||||
hass, nest_test_config, setup_base_platform
|
||||
):
|
||||
hass: HomeAssistant, nest_test_config, setup_base_platform
|
||||
) -> None:
|
||||
"""Test a failure when deleting the subscription."""
|
||||
with patch(
|
||||
"homeassistant.components.nest.api.GoogleNestSubscriber",
|
||||
|
@ -275,8 +289,12 @@ async def test_remove_entry_delete_subscriber_failure(
|
|||
|
||||
@pytest.mark.parametrize("config_entry_unique_id", [DOMAIN, None])
|
||||
async def test_migrate_unique_id(
|
||||
hass, error_caplog, setup_platform, config_entry, config_entry_unique_id
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
error_caplog,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
config_entry_unique_id,
|
||||
) -> None:
|
||||
"""Test successful setup."""
|
||||
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
from urllib.parse import parse_qsl
|
||||
|
||||
import pytest
|
||||
import requests_mock as rmock
|
||||
import requests_mock
|
||||
from requests_mock import create_response
|
||||
|
||||
from homeassistant.components.nest import config_flow, const
|
||||
from homeassistant.components.nest.legacy import local_auth
|
||||
|
@ -15,7 +16,7 @@ def registered_flow(hass):
|
|||
return hass.data[config_flow.DATA_FLOW_IMPL][const.DOMAIN]
|
||||
|
||||
|
||||
async def test_generate_auth_url(registered_flow):
|
||||
async def test_generate_auth_url(registered_flow) -> None:
|
||||
"""Test generating an auth url.
|
||||
|
||||
Mainly testing that it doesn't blow up.
|
||||
|
@ -24,7 +25,9 @@ async def test_generate_auth_url(registered_flow):
|
|||
assert url is not None
|
||||
|
||||
|
||||
async def test_convert_code(requests_mock, registered_flow):
|
||||
async def test_convert_code(
|
||||
requests_mock: requests_mock.Mocker, registered_flow
|
||||
) -> None:
|
||||
"""Test converting a code."""
|
||||
from nest.nest import ACCESS_TOKEN_URL
|
||||
|
||||
|
@ -40,9 +43,7 @@ async def test_convert_code(requests_mock, registered_flow):
|
|||
"grant_type": "authorization_code",
|
||||
}
|
||||
|
||||
return rmock.create_response(
|
||||
request, json={"access_token": "TEST-ACCESS-TOKEN"}
|
||||
)
|
||||
return create_response(request, json={"access_token": "TEST-ACCESS-TOKEN"})
|
||||
|
||||
requests_mock.add_matcher(token_matcher)
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
These tests simulate recent camera events received by the subscriber exposed
|
||||
as media in the media source.
|
||||
"""
|
||||
|
||||
from collections.abc import Generator
|
||||
import datetime
|
||||
from http import HTTPStatus
|
||||
|
@ -25,6 +24,7 @@ from homeassistant.components.media_source import (
|
|||
async_resolve_media,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.template import DATE_STR_FORMAT
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -32,7 +32,8 @@ import homeassistant.util.dt as dt_util
|
|||
|
||||
from .common import DEVICE_ID, CreateDevice, FakeSubscriber
|
||||
|
||||
from tests.common import async_capture_events
|
||||
from tests.common import MockUser, async_capture_events
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
DOMAIN = "nest"
|
||||
DEVICE_NAME = "Front"
|
||||
|
@ -235,7 +236,7 @@ def create_battery_event_data(
|
|||
)
|
||||
],
|
||||
)
|
||||
async def test_no_eligible_devices(hass, setup_platform):
|
||||
async def test_no_eligible_devices(hass: HomeAssistant, setup_platform) -> None:
|
||||
"""Test a media source with no eligible camera devices."""
|
||||
await setup_platform()
|
||||
browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}")
|
||||
|
@ -246,7 +247,7 @@ async def test_no_eligible_devices(hass, setup_platform):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("device_traits", [CAMERA_TRAITS, BATTERY_CAMERA_TRAITS])
|
||||
async def test_supported_device(hass, setup_platform):
|
||||
async def test_supported_device(hass: HomeAssistant, setup_platform) -> None:
|
||||
"""Test a media source with a supported camera."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -276,7 +277,7 @@ async def test_supported_device(hass, setup_platform):
|
|||
assert len(browse.children) == 0
|
||||
|
||||
|
||||
async def test_integration_unloaded(hass, auth, setup_platform):
|
||||
async def test_integration_unloaded(hass: HomeAssistant, auth, setup_platform) -> None:
|
||||
"""Test the media player loads, but has no devices, when config unloaded."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -302,7 +303,13 @@ async def test_integration_unloaded(hass, auth, setup_platform):
|
|||
assert len(browse.children) == 0
|
||||
|
||||
|
||||
async def test_camera_event(hass, hass_client, subscriber, auth, setup_platform):
|
||||
async def test_camera_event(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
auth,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a media source and image created for an event."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -400,7 +407,9 @@ async def test_camera_event(hass, hass_client, subscriber, auth, setup_platform)
|
|||
assert media.mime_type == "image/jpeg"
|
||||
|
||||
|
||||
async def test_event_order(hass, auth, subscriber, setup_platform):
|
||||
async def test_event_order(
|
||||
hass: HomeAssistant, auth, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test multiple events are in descending timestamp order."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -466,8 +475,12 @@ async def test_event_order(hass, auth, subscriber, setup_platform):
|
|||
|
||||
|
||||
async def test_multiple_image_events_in_session(
|
||||
hass, auth, hass_client, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test multiple events published within the same event session."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -577,12 +590,12 @@ async def test_multiple_image_events_in_session(
|
|||
|
||||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_multiple_clip_preview_events_in_session(
|
||||
hass,
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
):
|
||||
) -> None:
|
||||
"""Test multiple events published within the same event session."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -675,7 +688,9 @@ async def test_multiple_clip_preview_events_in_session(
|
|||
assert contents == IMAGE_BYTES_FROM_EVENT
|
||||
|
||||
|
||||
async def test_browse_invalid_device_id(hass, auth, setup_platform):
|
||||
async def test_browse_invalid_device_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source request for an invalid device id."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -694,7 +709,9 @@ async def test_browse_invalid_device_id(hass, auth, setup_platform):
|
|||
)
|
||||
|
||||
|
||||
async def test_browse_invalid_event_id(hass, auth, setup_platform):
|
||||
async def test_browse_invalid_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source browsing for an invalid event id."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -715,7 +732,9 @@ async def test_browse_invalid_event_id(hass, auth, setup_platform):
|
|||
)
|
||||
|
||||
|
||||
async def test_resolve_missing_event_id(hass, auth, setup_platform):
|
||||
async def test_resolve_missing_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source request missing an event id."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -732,7 +751,9 @@ async def test_resolve_missing_event_id(hass, auth, setup_platform):
|
|||
)
|
||||
|
||||
|
||||
async def test_resolve_invalid_device_id(hass, auth, setup_platform):
|
||||
async def test_resolve_invalid_device_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test resolving media for an invalid event id."""
|
||||
await setup_platform()
|
||||
with pytest.raises(Unresolvable):
|
||||
|
@ -743,7 +764,9 @@ async def test_resolve_invalid_device_id(hass, auth, setup_platform):
|
|||
)
|
||||
|
||||
|
||||
async def test_resolve_invalid_event_id(hass, auth, setup_platform):
|
||||
async def test_resolve_invalid_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test resolving media for an invalid event id."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -767,8 +790,13 @@ async def test_resolve_invalid_event_id(hass, auth, setup_platform):
|
|||
|
||||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_camera_event_clip_preview(
|
||||
hass, auth, hass_client, mp4, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mp4,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test an event for a battery camera video clip."""
|
||||
# Capture any events published
|
||||
received_events = async_capture_events(hass, NEST_EVENT)
|
||||
|
@ -871,8 +899,8 @@ async def test_camera_event_clip_preview(
|
|||
|
||||
|
||||
async def test_event_media_render_invalid_device_id(
|
||||
hass, auth, hass_client, setup_platform
|
||||
):
|
||||
hass: HomeAssistant, auth, hass_client: ClientSessionGenerator, setup_platform
|
||||
) -> None:
|
||||
"""Test event media API called with an invalid device id."""
|
||||
await setup_platform()
|
||||
client = await hass_client()
|
||||
|
@ -883,8 +911,8 @@ async def test_event_media_render_invalid_device_id(
|
|||
|
||||
|
||||
async def test_event_media_render_invalid_event_id(
|
||||
hass, auth, hass_client, setup_platform
|
||||
):
|
||||
hass: HomeAssistant, auth, hass_client: ClientSessionGenerator, setup_platform
|
||||
) -> None:
|
||||
"""Test event media API called with an invalid device id."""
|
||||
await setup_platform()
|
||||
device_registry = dr.async_get(hass)
|
||||
|
@ -899,7 +927,13 @@ async def test_event_media_render_invalid_event_id(
|
|||
)
|
||||
|
||||
|
||||
async def test_event_media_failure(hass, auth, hass_client, subscriber, setup_platform):
|
||||
async def test_event_media_failure(
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test event media fetch sees a failure from the server."""
|
||||
received_events = async_capture_events(hass, NEST_EVENT)
|
||||
|
||||
|
@ -951,8 +985,12 @@ async def test_event_media_failure(hass, auth, hass_client, subscriber, setup_pl
|
|||
|
||||
|
||||
async def test_media_permission_unauthorized(
|
||||
hass, auth, hass_client, hass_admin_user, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
hass_admin_user: MockUser,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test case where user does not have permissions to view media."""
|
||||
await setup_platform()
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
@ -977,8 +1015,13 @@ async def test_media_permission_unauthorized(
|
|||
|
||||
|
||||
async def test_multiple_devices(
|
||||
hass, auth, hass_client, create_device, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test events received for multiple devices."""
|
||||
device_id2 = f"{DEVICE_ID}-2"
|
||||
create_device.create(
|
||||
|
@ -1066,14 +1109,14 @@ def event_store() -> Generator[None, None, None]:
|
|||
|
||||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_media_store_persistence(
|
||||
hass,
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client,
|
||||
hass_client: ClientSessionGenerator,
|
||||
event_store,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
):
|
||||
) -> None:
|
||||
"""Test the disk backed media store persistence."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -1160,8 +1203,12 @@ async def test_media_store_persistence(
|
|||
|
||||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_media_store_save_filesystem_error(
|
||||
hass, auth, hass_client, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a filesystem error writing event media."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -1211,8 +1258,12 @@ async def test_media_store_save_filesystem_error(
|
|||
|
||||
|
||||
async def test_media_store_load_filesystem_error(
|
||||
hass, auth, hass_client, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test a filesystem error reading event media."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -1261,8 +1312,12 @@ async def test_media_store_load_filesystem_error(
|
|||
|
||||
@pytest.mark.parametrize("device_traits,cache_size", [(BATTERY_CAMERA_TRAITS, 5)])
|
||||
async def test_camera_event_media_eviction(
|
||||
hass, auth, hass_client, subscriber, setup_platform
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test media files getting evicted from the cache."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -1333,7 +1388,13 @@ async def test_camera_event_media_eviction(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_camera_image_resize(hass, auth, hass_client, subscriber, setup_platform):
|
||||
async def test_camera_image_resize(
|
||||
hass: HomeAssistant,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test scaling a thumbnail for an event image."""
|
||||
await setup_platform()
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ def device_traits() -> dict[str, Any]:
|
|||
|
||||
async def test_thermostat_device(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat with temperature and humidity sensors."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ async def test_thermostat_device(
|
|||
|
||||
async def test_thermostat_device_available(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat with temperature and humidity sensors that is Online."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ async def test_thermostat_device_available(
|
|||
|
||||
async def test_thermostat_device_unavailable(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
):
|
||||
) -> None:
|
||||
"""Test a thermostat with temperature and humidity sensors that is Offline."""
|
||||
create_device.create(
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ async def test_thermostat_device_unavailable(
|
|||
assert humidity.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_no_devices(hass: HomeAssistant, setup_platform: PlatformSetup):
|
||||
async def test_no_devices(hass: HomeAssistant, setup_platform: PlatformSetup) -> None:
|
||||
"""Test no devices returned by the api."""
|
||||
await setup_platform()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue