mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Improve type hints in esphome tests (#120674)
This commit is contained in:
parent
3895252965
commit
e446875c7e
@ -24,6 +24,7 @@ from aioesphomeapi import (
|
||||
VoiceAssistantFeature,
|
||||
)
|
||||
import pytest
|
||||
from typing_extensions import AsyncGenerator
|
||||
from zeroconf import Zeroconf
|
||||
|
||||
from homeassistant.components.esphome import dashboard
|
||||
@ -175,7 +176,7 @@ def mock_client(mock_device_info) -> APIClient:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_dashboard(hass):
|
||||
async def mock_dashboard(hass: HomeAssistant) -> AsyncGenerator[dict[str, Any]]:
|
||||
"""Mock dashboard."""
|
||||
data = {"configured": [], "importable": []}
|
||||
with patch(
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from ipaddress import ip_address
|
||||
import json
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aioesphomeapi import (
|
||||
@ -329,7 +330,7 @@ async def test_user_invalid_password(hass: HomeAssistant, mock_client) -> None:
|
||||
async def test_user_dashboard_has_wrong_key(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step with key from dashboard that is incorrect."""
|
||||
@ -376,7 +377,7 @@ async def test_user_dashboard_has_wrong_key(
|
||||
async def test_user_discovers_name_and_gets_key_from_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name and get the key from the dashboard."""
|
||||
@ -429,7 +430,7 @@ async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
|
||||
hass: HomeAssistant,
|
||||
dashboard_exception: Exception,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name and get the key from the dashboard."""
|
||||
@ -484,7 +485,7 @@ async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
|
||||
async def test_user_discovers_name_and_dashboard_is_unavailable(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name but the dashboard is unavailable."""
|
||||
@ -843,7 +844,7 @@ async def test_reauth_confirm_valid(
|
||||
async def test_reauth_fixed_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test reauth fixed automatically via dashboard."""
|
||||
@ -894,7 +895,7 @@ async def test_reauth_fixed_via_dashboard(
|
||||
async def test_reauth_fixed_via_dashboard_add_encryption_remove_password(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_config_entry,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
@ -938,7 +939,7 @@ async def test_reauth_fixed_via_remove_password(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_config_entry,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test reauth fixed automatically by seeing password removed."""
|
||||
@ -962,7 +963,7 @@ async def test_reauth_fixed_via_remove_password(
|
||||
async def test_reauth_fixed_via_dashboard_at_confirm(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test reauth fixed automatically via dashboard at confirm step."""
|
||||
@ -1153,7 +1154,9 @@ async def test_discovery_dhcp_no_changes(
|
||||
assert entry.data[CONF_HOST] == "192.168.43.183"
|
||||
|
||||
|
||||
async def test_discovery_hassio(hass: HomeAssistant, mock_dashboard) -> None:
|
||||
async def test_discovery_hassio(
|
||||
hass: HomeAssistant, mock_dashboard: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test dashboard discovery."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"esphome",
|
||||
@ -1181,7 +1184,7 @@ async def test_discovery_hassio(hass: HomeAssistant, mock_dashboard) -> None:
|
||||
async def test_zeroconf_encryption_key_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test encryption key retrieved from dashboard."""
|
||||
@ -1247,7 +1250,7 @@ async def test_zeroconf_encryption_key_via_dashboard(
|
||||
async def test_zeroconf_encryption_key_via_dashboard_with_api_encryption_prop(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test encryption key retrieved from dashboard with api_encryption property set."""
|
||||
@ -1313,7 +1316,7 @@ async def test_zeroconf_encryption_key_via_dashboard_with_api_encryption_prop(
|
||||
async def test_zeroconf_no_encryption_key_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test encryption key not retrieved from dashboard."""
|
||||
|
@ -16,7 +16,10 @@ from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_dashboard_storage(
|
||||
hass: HomeAssistant, init_integration, mock_dashboard, hass_storage: dict[str, Any]
|
||||
hass: HomeAssistant,
|
||||
init_integration,
|
||||
mock_dashboard: dict[str, Any],
|
||||
hass_storage: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test dashboard storage."""
|
||||
assert hass_storage[dashboard.STORAGE_KEY]["data"] == {
|
||||
@ -197,7 +200,9 @@ async def test_new_dashboard_fix_reauth(
|
||||
assert mock_config_entry.data[CONF_NOISE_PSK] == VALID_NOISE_PSK
|
||||
|
||||
|
||||
async def test_dashboard_supports_update(hass: HomeAssistant, mock_dashboard) -> None:
|
||||
async def test_dashboard_supports_update(
|
||||
hass: HomeAssistant, mock_dashboard: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test dashboard supports update."""
|
||||
dash = dashboard.async_get_dashboard(hass)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Tests for the diagnostics data provided by the ESPHome integration."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
@ -20,7 +21,7 @@ async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Test ESPHome update entities."""
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aioesphomeapi import (
|
||||
@ -84,7 +85,7 @@ async def test_update_entity(
|
||||
stub_reconnect,
|
||||
mock_config_entry,
|
||||
mock_device_info,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
devices_payload,
|
||||
expected_state,
|
||||
expected_attributes,
|
||||
@ -190,7 +191,7 @@ async def test_update_static_info(
|
||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||
Awaitable[MockESPHomeDevice],
|
||||
],
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test ESPHome update entity."""
|
||||
mock_dashboard["configured"] = [
|
||||
@ -236,7 +237,7 @@ async def test_update_device_state_for_availability(
|
||||
expected_disconnect: bool,
|
||||
expected_state: str,
|
||||
has_deep_sleep: bool,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
mock_client: APIClient,
|
||||
mock_esphome_device: Callable[
|
||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||
@ -272,7 +273,7 @@ async def test_update_entity_dashboard_not_available_startup(
|
||||
stub_reconnect,
|
||||
mock_config_entry,
|
||||
mock_device_info,
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test ESPHome update entity when dashboard is not available at startup."""
|
||||
with (
|
||||
@ -321,7 +322,7 @@ async def test_update_entity_dashboard_discovered_after_startup_but_update_faile
|
||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||
Awaitable[MockESPHomeDevice],
|
||||
],
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test ESPHome update entity when dashboard is discovered after startup and the first update fails."""
|
||||
with patch(
|
||||
@ -386,7 +387,7 @@ async def test_update_becomes_available_at_runtime(
|
||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||
Awaitable[MockESPHomeDevice],
|
||||
],
|
||||
mock_dashboard,
|
||||
mock_dashboard: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test ESPHome update entity when the dashboard has no device at startup but gets them later."""
|
||||
await mock_esphome_device(
|
||||
|
Loading…
x
Reference in New Issue
Block a user