Update typing 15 (#48079)
This commit is contained in:
parent
dcca29ef68
commit
54d1e9985f
35 changed files with 190 additions and 166 deletions
|
@ -1,4 +1,6 @@
|
|||
"""Test the helper method for writing tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import collections
|
||||
from collections import OrderedDict
|
||||
|
@ -14,7 +16,7 @@ import threading
|
|||
import time
|
||||
from time import monotonic
|
||||
import types
|
||||
from typing import Any, Awaitable, Collection, Optional
|
||||
from typing import Any, Awaitable, Collection
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
import uuid
|
||||
|
||||
|
@ -197,7 +199,7 @@ async def async_test_home_assistant(loop, load_registries=True):
|
|||
"""
|
||||
# To flush out any call_soon_threadsafe
|
||||
await asyncio.sleep(0)
|
||||
start_time: Optional[float] = None
|
||||
start_time: float | None = None
|
||||
|
||||
while len(self._pending_tasks) > max_remaining_tasks:
|
||||
pending = [
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""The tests for the Apache Kafka component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import AbstractEventLoop
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable, Type
|
||||
from typing import Callable
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -31,7 +33,7 @@ class FilterTest:
|
|||
class MockKafkaClient:
|
||||
"""Mock of the Apache Kafka client for testing."""
|
||||
|
||||
init: Callable[[Type[AbstractEventLoop], str, str], None]
|
||||
init: Callable[[type[AbstractEventLoop], str, str], None]
|
||||
start: Callable[[], None]
|
||||
send_and_wait: Callable[[str, str], None]
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"""Common methods used across tests for Bond."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as AsyncIOTimeoutError
|
||||
from contextlib import nullcontext
|
||||
from datetime import timedelta
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from homeassistant import core
|
||||
|
@ -54,14 +56,14 @@ async def setup_bond_entity(
|
|||
async def setup_platform(
|
||||
hass: core.HomeAssistant,
|
||||
platform: str,
|
||||
discovered_device: Dict[str, Any],
|
||||
discovered_device: dict[str, Any],
|
||||
*,
|
||||
bond_device_id: str = "bond-device-id",
|
||||
bond_version: Dict[str, Any] = None,
|
||||
props: Dict[str, Any] = None,
|
||||
state: Dict[str, Any] = None,
|
||||
bridge: Dict[str, Any] = None,
|
||||
token: Dict[str, Any] = None,
|
||||
bond_version: dict[str, Any] = None,
|
||||
props: dict[str, Any] = None,
|
||||
state: dict[str, Any] = None,
|
||||
bridge: dict[str, Any] = None,
|
||||
token: dict[str, Any] = None,
|
||||
):
|
||||
"""Set up the specified Bond platform."""
|
||||
mock_entry = MockConfigEntry(
|
||||
|
@ -89,7 +91,7 @@ async def setup_platform(
|
|||
|
||||
|
||||
def patch_bond_version(
|
||||
enabled: bool = True, return_value: Optional[dict] = None, side_effect=None
|
||||
enabled: bool = True, return_value: dict | None = None, side_effect=None
|
||||
):
|
||||
"""Patch Bond API version endpoint."""
|
||||
if not enabled:
|
||||
|
@ -106,7 +108,7 @@ def patch_bond_version(
|
|||
|
||||
|
||||
def patch_bond_bridge(
|
||||
enabled: bool = True, return_value: Optional[dict] = None, side_effect=None
|
||||
enabled: bool = True, return_value: dict | None = None, side_effect=None
|
||||
):
|
||||
"""Patch Bond API bridge endpoint."""
|
||||
if not enabled:
|
||||
|
@ -127,7 +129,7 @@ def patch_bond_bridge(
|
|||
|
||||
|
||||
def patch_bond_token(
|
||||
enabled: bool = True, return_value: Optional[dict] = None, side_effect=None
|
||||
enabled: bool = True, return_value: dict | None = None, side_effect=None
|
||||
):
|
||||
"""Patch Bond API token endpoint."""
|
||||
if not enabled:
|
||||
|
@ -203,7 +205,7 @@ def patch_bond_device_state(return_value=None, side_effect=None):
|
|||
|
||||
|
||||
async def help_test_entity_available(
|
||||
hass: core.HomeAssistant, domain: str, device: Dict[str, Any], entity_id: str
|
||||
hass: core.HomeAssistant, domain: str, device: dict[str, Any], entity_id: str
|
||||
):
|
||||
"""Run common test to verify available property."""
|
||||
await setup_platform(hass, domain, device)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Test the Bond config flow."""
|
||||
from typing import Any, Dict
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aiohttp import ClientConnectionError, ClientResponseError
|
||||
|
@ -334,8 +336,8 @@ async def _help_test_form_unexpected_error(
|
|||
hass: core.HomeAssistant,
|
||||
*,
|
||||
source: str,
|
||||
initial_input: Dict[str, Any] = None,
|
||||
user_input: Dict[str, Any],
|
||||
initial_input: dict[str, Any] = None,
|
||||
user_input: dict[str, Any],
|
||||
error: Exception,
|
||||
):
|
||||
"""Test we handle unexpected error gracefully."""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for the Bond fan device."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Optional
|
||||
|
||||
from bond_api import Action, DeviceType, Direction
|
||||
|
||||
|
@ -44,8 +45,8 @@ def ceiling_fan(name: str):
|
|||
async def turn_fan_on(
|
||||
hass: core.HomeAssistant,
|
||||
fan_id: str,
|
||||
speed: Optional[str] = None,
|
||||
percentage: Optional[int] = None,
|
||||
speed: str | None = None,
|
||||
percentage: int | None = None,
|
||||
) -> None:
|
||||
"""Turn the fan on at the specified speed."""
|
||||
service_data = {ATTR_ENTITY_ID: fan_id}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""The tests for the Cast Media player platform."""
|
||||
# pylint: disable=protected-access
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Optional
|
||||
from unittest.mock import ANY, MagicMock, Mock, patch
|
||||
from uuid import UUID
|
||||
|
||||
|
@ -50,14 +51,14 @@ def get_fake_chromecast(info: ChromecastInfo):
|
|||
|
||||
|
||||
def get_fake_chromecast_info(
|
||||
host="192.168.178.42", port=8009, uuid: Optional[UUID] = FakeUUID
|
||||
host="192.168.178.42", port=8009, uuid: UUID | None = FakeUUID
|
||||
):
|
||||
"""Generate a Fake ChromecastInfo with the specified arguments."""
|
||||
|
||||
@attr.s(slots=True, frozen=True, eq=False)
|
||||
class ExtendedChromecastInfo(ChromecastInfo):
|
||||
host: Optional[str] = attr.ib(default=None)
|
||||
port: Optional[int] = attr.ib(default=0)
|
||||
host: str | None = attr.ib(default=None)
|
||||
port: int | None = attr.ib(default=0)
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, ChromecastInfo):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""The tests for the climate component."""
|
||||
from typing import List
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
@ -58,7 +59,7 @@ class MockClimateEntity(ClimateEntity):
|
|||
return HVAC_MODE_HEAT
|
||||
|
||||
@property
|
||||
def hvac_modes(self) -> List[str]:
|
||||
def hvac_modes(self) -> list[str]:
|
||||
"""Return the list of available hvac operation modes.
|
||||
|
||||
Need to be a subset of HVAC_MODES.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Tests for the Cloudflare integration."""
|
||||
from typing import List
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pycfdns import CFRecord
|
||||
|
@ -71,7 +72,7 @@ async def init_integration(
|
|||
def _get_mock_cfupdate(
|
||||
zone: str = MOCK_ZONE,
|
||||
zone_id: str = MOCK_ZONE_ID,
|
||||
records: List = MOCK_ZONE_RECORDS,
|
||||
records: list = MOCK_ZONE_RECORDS,
|
||||
):
|
||||
client = AsyncMock()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""deconz conftest."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -13,7 +13,7 @@ def mock_deconz_websocket():
|
|||
"""No real websocket allowed."""
|
||||
with patch("pydeconz.gateway.WSClient") as mock:
|
||||
|
||||
async def make_websocket_call(data: Optional[dict] = None, state: str = ""):
|
||||
async def make_websocket_call(data: dict | None = None, state: str = ""):
|
||||
"""Generate a websocket call."""
|
||||
pydeconz_gateway_session_handler = mock.call_args[0][3]
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""The tests for the DirecTV Media player platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
from unittest.mock import patch
|
||||
|
||||
from pytest import fixture
|
||||
|
@ -77,24 +78,20 @@ def mock_now() -> datetime:
|
|||
return dt_util.utcnow()
|
||||
|
||||
|
||||
async def async_turn_on(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
) -> None:
|
||||
async def async_turn_on(hass: HomeAssistantType, entity_id: str | None = None) -> None:
|
||||
"""Turn on specified media player or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
async def async_turn_off(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
) -> None:
|
||||
async def async_turn_off(hass: HomeAssistantType, entity_id: str | None = None) -> None:
|
||||
"""Turn off specified media player or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
await hass.services.async_call(MP_DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
async def async_media_pause(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
hass: HomeAssistantType, entity_id: str | None = None
|
||||
) -> None:
|
||||
"""Send the media player the command for pause."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -102,7 +99,7 @@ async def async_media_pause(
|
|||
|
||||
|
||||
async def async_media_play(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
hass: HomeAssistantType, entity_id: str | None = None
|
||||
) -> None:
|
||||
"""Send the media player the command for play/pause."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -110,7 +107,7 @@ async def async_media_play(
|
|||
|
||||
|
||||
async def async_media_stop(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
hass: HomeAssistantType, entity_id: str | None = None
|
||||
) -> None:
|
||||
"""Send the media player the command for stop."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -118,7 +115,7 @@ async def async_media_stop(
|
|||
|
||||
|
||||
async def async_media_next_track(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
hass: HomeAssistantType, entity_id: str | None = None
|
||||
) -> None:
|
||||
"""Send the media player the command for next track."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -126,7 +123,7 @@ async def async_media_next_track(
|
|||
|
||||
|
||||
async def async_media_previous_track(
|
||||
hass: HomeAssistantType, entity_id: Optional[str] = None
|
||||
hass: HomeAssistantType, entity_id: str | None = None
|
||||
) -> None:
|
||||
"""Send the media player the command for prev track."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -137,8 +134,8 @@ async def async_play_media(
|
|||
hass: HomeAssistantType,
|
||||
media_type: str,
|
||||
media_id: str,
|
||||
entity_id: Optional[str] = None,
|
||||
enqueue: Optional[str] = None,
|
||||
entity_id: str | None = None,
|
||||
enqueue: str | None = None,
|
||||
) -> None:
|
||||
"""Send the media player the command for playing media."""
|
||||
data = {ATTR_MEDIA_CONTENT_TYPE: media_type, ATTR_MEDIA_CONTENT_ID: media_id}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Common utils for Dyson tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Type
|
||||
from unittest import mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
@ -37,7 +37,7 @@ CONFIG = {
|
|||
|
||||
|
||||
@callback
|
||||
def async_get_basic_device(spec: Type[DysonDevice]) -> DysonDevice:
|
||||
def async_get_basic_device(spec: type[DysonDevice]) -> DysonDevice:
|
||||
"""Return a basic device with common fields filled out."""
|
||||
device = MagicMock(spec=spec)
|
||||
device.serial = SERIAL
|
||||
|
@ -88,7 +88,7 @@ def async_get_purecool_device() -> DysonPureCool:
|
|||
|
||||
|
||||
async def async_update_device(
|
||||
hass: HomeAssistant, device: DysonDevice, state_type: Optional[Type] = None
|
||||
hass: HomeAssistant, device: DysonDevice, state_type: type | None = None
|
||||
) -> None:
|
||||
"""Update the device using callback function."""
|
||||
callbacks = [args[0][0] for args in device.add_message_listener.call_args_list]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Test the Dyson fan component."""
|
||||
|
||||
from typing import Type
|
||||
from __future__ import annotations
|
||||
|
||||
from libpurecool.const import (
|
||||
AutoMode,
|
||||
|
@ -74,7 +73,7 @@ ENTITY_ID = f"{PLATFORM_DOMAIN}.{ENTITY_NAME}"
|
|||
|
||||
|
||||
@callback
|
||||
def async_get_device(spec: Type[DysonDevice]) -> DysonDevice:
|
||||
def async_get_device(spec: type[DysonDevice]) -> DysonDevice:
|
||||
"""Return a Dyson climate device."""
|
||||
device = async_get_basic_device(spec)
|
||||
device.state.heat_target = 2900
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Test the Dyson fan component."""
|
||||
from typing import Type
|
||||
from __future__ import annotations
|
||||
|
||||
from libpurecool.const import FanMode, FanSpeed, NightMode, Oscillation
|
||||
from libpurecool.dyson_pure_cool import DysonPureCool, DysonPureCoolLink
|
||||
|
@ -67,7 +67,7 @@ ENTITY_ID = f"{PLATFORM_DOMAIN}.{ENTITY_NAME}"
|
|||
|
||||
|
||||
@callback
|
||||
def async_get_device(spec: Type[DysonPureCoolLink]) -> DysonPureCoolLink:
|
||||
def async_get_device(spec: type[DysonPureCoolLink]) -> DysonPureCoolLink:
|
||||
"""Return a Dyson fan device."""
|
||||
if spec == DysonPureCoolLink:
|
||||
return async_get_purecoollink_device()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Test the Dyson sensor(s) component."""
|
||||
from typing import List, Type
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from libpurecool.dyson_pure_cool import DysonPureCool
|
||||
|
@ -79,7 +80,7 @@ def _async_assign_values(
|
|||
|
||||
|
||||
@callback
|
||||
def async_get_device(spec: Type[DysonPureCoolLink], combi=False) -> DysonPureCoolLink:
|
||||
def async_get_device(spec: type[DysonPureCoolLink], combi=False) -> DysonPureCoolLink:
|
||||
"""Return a device of the given type."""
|
||||
device = async_get_basic_device(spec)
|
||||
_async_assign_values(device, combi=combi)
|
||||
|
@ -113,7 +114,7 @@ def _async_get_entity_id(sensor_type: str) -> str:
|
|||
indirect=["device"],
|
||||
)
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant, device: DysonPureCoolLink, sensors: List[str]
|
||||
hass: HomeAssistant, device: DysonPureCoolLink, sensors: list[str]
|
||||
) -> None:
|
||||
"""Test the sensors."""
|
||||
# Temperature is given by the device in kelvin
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Configuration for HEOS tests."""
|
||||
from typing import Dict, Sequence
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Sequence
|
||||
from unittest.mock import Mock, patch as patch
|
||||
|
||||
from pyheos import Dispatcher, Heos, HeosPlayer, HeosSource, InputSource, const
|
||||
|
@ -86,7 +88,7 @@ def player_fixture(quick_selects):
|
|||
|
||||
|
||||
@pytest.fixture(name="favorites")
|
||||
def favorites_fixture() -> Dict[int, HeosSource]:
|
||||
def favorites_fixture() -> dict[int, HeosSource]:
|
||||
"""Create favorites fixture."""
|
||||
station = Mock(HeosSource)
|
||||
station.type = const.TYPE_STATION
|
||||
|
@ -131,7 +133,7 @@ def discovery_data_fixture() -> dict:
|
|||
|
||||
|
||||
@pytest.fixture(name="quick_selects")
|
||||
def quick_selects_fixture() -> Dict[int, str]:
|
||||
def quick_selects_fixture() -> dict[int, str]:
|
||||
"""Create a dict of quick selects for testing."""
|
||||
return {
|
||||
1: "Quick Select 1",
|
||||
|
@ -153,12 +155,12 @@ def playlists_fixture() -> Sequence[HeosSource]:
|
|||
|
||||
|
||||
@pytest.fixture(name="change_data")
|
||||
def change_data_fixture() -> Dict:
|
||||
def change_data_fixture() -> dict:
|
||||
"""Create player change data for testing."""
|
||||
return {const.DATA_MAPPED_IDS: {}, const.DATA_NEW: []}
|
||||
|
||||
|
||||
@pytest.fixture(name="change_data_mapped_ids")
|
||||
def change_data_mapped_ids_fixture() -> Dict:
|
||||
def change_data_mapped_ids_fixture() -> dict:
|
||||
"""Create player change data for testing."""
|
||||
return {const.DATA_MAPPED_IDS: {101: 1}, const.DATA_NEW: []}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""Tests for the HomeKit component."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from typing import Dict
|
||||
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
from pyhap.accessory import Accessory
|
||||
|
@ -863,7 +864,7 @@ async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_zeroconf):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
def _write_data(path: str, data: Dict) -> None:
|
||||
def _write_data(path: str, data: dict) -> None:
|
||||
"""Write the data."""
|
||||
if not os.path.isdir(os.path.dirname(path)):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from types import TracebackType
|
||||
from typing import Any, Dict, Optional, Type
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from hyperion import const
|
||||
|
@ -30,25 +30,25 @@ TEST_TITLE = f"{TEST_HOST}:{TEST_PORT}"
|
|||
|
||||
TEST_TOKEN = "sekr1t"
|
||||
TEST_CONFIG_ENTRY_ID = "74565ad414754616000674c87bdc876c"
|
||||
TEST_CONFIG_ENTRY_OPTIONS: Dict[str, Any] = {CONF_PRIORITY: TEST_PRIORITY}
|
||||
TEST_CONFIG_ENTRY_OPTIONS: dict[str, Any] = {CONF_PRIORITY: TEST_PRIORITY}
|
||||
|
||||
TEST_INSTANCE_1: Dict[str, Any] = {
|
||||
TEST_INSTANCE_1: dict[str, Any] = {
|
||||
"friendly_name": "Test instance 1",
|
||||
"instance": 1,
|
||||
"running": True,
|
||||
}
|
||||
TEST_INSTANCE_2: Dict[str, Any] = {
|
||||
TEST_INSTANCE_2: dict[str, Any] = {
|
||||
"friendly_name": "Test instance 2",
|
||||
"instance": 2,
|
||||
"running": True,
|
||||
}
|
||||
TEST_INSTANCE_3: Dict[str, Any] = {
|
||||
TEST_INSTANCE_3: dict[str, Any] = {
|
||||
"friendly_name": "Test instance 3",
|
||||
"instance": 3,
|
||||
"running": True,
|
||||
}
|
||||
|
||||
TEST_AUTH_REQUIRED_RESP: Dict[str, Any] = {
|
||||
TEST_AUTH_REQUIRED_RESP: dict[str, Any] = {
|
||||
"command": "authorize-tokenRequired",
|
||||
"info": {
|
||||
"required": True,
|
||||
|
@ -66,16 +66,16 @@ TEST_AUTH_NOT_REQUIRED_RESP = {
|
|||
class AsyncContextManagerMock(Mock):
|
||||
"""An async context manager mock for Hyperion."""
|
||||
|
||||
async def __aenter__(self) -> Optional[AsyncContextManagerMock]:
|
||||
async def __aenter__(self) -> AsyncContextManagerMock | None:
|
||||
"""Enter context manager and connect the client."""
|
||||
result = await self.async_client_connect()
|
||||
return self if result else None
|
||||
|
||||
async def __aexit__(
|
||||
self,
|
||||
exc_type: Optional[Type[BaseException]],
|
||||
exc: Optional[BaseException],
|
||||
traceback: Optional[TracebackType],
|
||||
exc_type: type[BaseException] | None,
|
||||
exc: BaseException | None,
|
||||
traceback: TracebackType | None,
|
||||
) -> None:
|
||||
"""Leave context manager and disconnect the client."""
|
||||
await self.async_client_disconnect()
|
||||
|
@ -118,7 +118,7 @@ def create_mock_client() -> Mock:
|
|||
|
||||
|
||||
def add_test_config_entry(
|
||||
hass: HomeAssistantType, data: Optional[Dict[str, Any]] = None
|
||||
hass: HomeAssistantType, data: dict[str, Any] | None = None
|
||||
) -> ConfigEntry:
|
||||
"""Add a test config entry."""
|
||||
config_entry: MockConfigEntry = MockConfigEntry( # type: ignore[no-untyped-call]
|
||||
|
@ -139,8 +139,8 @@ def add_test_config_entry(
|
|||
|
||||
async def setup_test_config_entry(
|
||||
hass: HomeAssistantType,
|
||||
config_entry: Optional[ConfigEntry] = None,
|
||||
hyperion_client: Optional[Mock] = None,
|
||||
config_entry: ConfigEntry | None = None,
|
||||
hyperion_client: Mock | None = None,
|
||||
) -> ConfigEntry:
|
||||
"""Add a test Hyperion entity to hass."""
|
||||
config_entry = config_entry or add_test_config_entry(hass)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Tests for the Hyperion config flow."""
|
||||
from typing import Any, Dict, Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from hyperion import const
|
||||
|
@ -40,7 +42,7 @@ from . import (
|
|||
from tests.common import MockConfigEntry
|
||||
|
||||
TEST_IP_ADDRESS = "192.168.0.1"
|
||||
TEST_HOST_PORT: Dict[str, Any] = {
|
||||
TEST_HOST_PORT: dict[str, Any] = {
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_PORT: TEST_PORT,
|
||||
}
|
||||
|
@ -122,7 +124,7 @@ async def _create_mock_entry(hass: HomeAssistantType) -> MockConfigEntry:
|
|||
async def _init_flow(
|
||||
hass: HomeAssistantType,
|
||||
source: str = SOURCE_USER,
|
||||
data: Optional[Dict[str, Any]] = None,
|
||||
data: dict[str, Any] | None = None,
|
||||
) -> Any:
|
||||
"""Initialize a flow."""
|
||||
data = data or {}
|
||||
|
@ -133,7 +135,7 @@ async def _init_flow(
|
|||
|
||||
|
||||
async def _configure_flow(
|
||||
hass: HomeAssistantType, result: Dict, user_input: Optional[Dict[str, Any]] = None
|
||||
hass: HomeAssistantType, result: dict, user_input: dict[str, Any] | None = None
|
||||
) -> Any:
|
||||
"""Provide input to a flow."""
|
||||
user_input = user_input or {}
|
||||
|
@ -528,7 +530,7 @@ async def test_ssdp_failure_bad_port_json(hass: HomeAssistantType) -> None:
|
|||
"""Check an SSDP flow with bad json port."""
|
||||
|
||||
client = create_mock_client()
|
||||
bad_data: Dict[str, Any] = {**TEST_SSDP_SERVICE_INFO}
|
||||
bad_data: dict[str, Any] = {**TEST_SSDP_SERVICE_INFO}
|
||||
bad_data["ports"]["jsonServer"] = "not_a_port"
|
||||
|
||||
with patch(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Tests for the Hyperion integration."""
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, call, patch
|
||||
|
||||
from hyperion import const
|
||||
|
@ -56,7 +57,7 @@ COLOR_BLACK = color_util.COLORS["black"]
|
|||
|
||||
def _get_config_entry_from_unique_id(
|
||||
hass: HomeAssistantType, unique_id: str
|
||||
) -> Optional[ConfigEntry]:
|
||||
) -> ConfigEntry | None:
|
||||
for entry in hass.config_entries.async_entries(domain=DOMAIN):
|
||||
if TEST_SYSINFO_ID == entry.unique_id:
|
||||
return entry
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""The tests for the InfluxDB sensor."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from typing import Dict, List, Type
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError
|
||||
|
@ -55,14 +56,14 @@ BASE_V2_QUERY = {"queries_flux": [{"name": "test", "query": "query"}]}
|
|||
class Record:
|
||||
"""Record in a Table."""
|
||||
|
||||
values: Dict
|
||||
values: dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class Table:
|
||||
"""Table in an Influx 2 resultset."""
|
||||
|
||||
records: List[Type[Record]]
|
||||
records: list[type[Record]]
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_client")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Configure pytest for Litter-Robot tests."""
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pylitterbot
|
||||
|
@ -13,7 +14,7 @@ from .common import CONFIG, ROBOT_DATA
|
|||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
def create_mock_robot(unit_status_code: Optional[str] = None):
|
||||
def create_mock_robot(unit_status_code: str | None = None):
|
||||
"""Create a mock Litter-Robot device."""
|
||||
if not (
|
||||
unit_status_code
|
||||
|
@ -32,7 +33,7 @@ def create_mock_robot(unit_status_code: Optional[str] = None):
|
|||
return robot
|
||||
|
||||
|
||||
def create_mock_account(unit_status_code: Optional[str] = None):
|
||||
def create_mock_account(unit_status_code: str | None = None):
|
||||
"""Create a mock Litter-Robot account."""
|
||||
account = MagicMock(spec=pylitterbot.Account)
|
||||
account.connect = AsyncMock()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Test the MySensors config flow."""
|
||||
from typing import Dict, Optional, Tuple
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -349,7 +350,7 @@ async def test_config_invalid(
|
|||
hass: HomeAssistantType,
|
||||
gateway_type: ConfGatewayType,
|
||||
expected_step_id: str,
|
||||
user_input: Dict[str, any],
|
||||
user_input: dict[str, any],
|
||||
err_field,
|
||||
err_string,
|
||||
):
|
||||
|
@ -420,7 +421,7 @@ async def test_config_invalid(
|
|||
},
|
||||
],
|
||||
)
|
||||
async def test_import(hass: HomeAssistantType, user_input: Dict):
|
||||
async def test_import(hass: HomeAssistantType, user_input: dict):
|
||||
"""Test importing a gateway."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
|
@ -712,9 +713,9 @@ async def test_import(hass: HomeAssistantType, user_input: Dict):
|
|||
)
|
||||
async def test_duplicate(
|
||||
hass: HomeAssistantType,
|
||||
first_input: Dict,
|
||||
second_input: Dict,
|
||||
expected_result: Optional[Tuple[str, str]],
|
||||
first_input: dict,
|
||||
second_input: dict,
|
||||
expected_result: tuple[str, str] | None,
|
||||
):
|
||||
"""Test duplicate detection."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Test function in __init__.py."""
|
||||
from typing import Dict
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -229,7 +230,7 @@ async def test_import(
|
|||
config: ConfigType,
|
||||
expected_calls: int,
|
||||
expected_to_succeed: bool,
|
||||
expected_config_flow_user_input: Dict[str, any],
|
||||
expected_config_flow_user_input: dict[str, any],
|
||||
):
|
||||
"""Test importing a gateway."""
|
||||
with patch("sys.platform", "win32"), patch(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Tests for the seventeentrack sensor."""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from typing import Union
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from py17track.package import Package
|
||||
|
@ -100,7 +101,7 @@ class ProfileMock:
|
|||
return self.__class__.login_result
|
||||
|
||||
async def packages(
|
||||
self, package_state: Union[int, str] = "", show_archived: bool = False
|
||||
self, package_state: int | str = "", show_archived: bool = False
|
||||
) -> list:
|
||||
"""Packages mock."""
|
||||
return self.__class__.package_list[:]
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""Test the Shark IQ vacuum entity."""
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import deepcopy
|
||||
import enum
|
||||
from typing import Any, Iterable, List, Optional
|
||||
from typing import Any, Iterable
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -80,11 +82,11 @@ class MockAyla(AylaApi):
|
|||
async def async_sign_in(self):
|
||||
"""Instead of signing in, just return."""
|
||||
|
||||
async def async_list_devices(self) -> List[dict]:
|
||||
async def async_list_devices(self) -> list[dict]:
|
||||
"""Return the device list."""
|
||||
return [SHARK_DEVICE_DICT]
|
||||
|
||||
async def async_get_devices(self, update: bool = True) -> List[SharkIqVacuum]:
|
||||
async def async_get_devices(self, update: bool = True) -> list[SharkIqVacuum]:
|
||||
"""Get the list of devices."""
|
||||
shark = MockShark(self, SHARK_DEVICE_DICT)
|
||||
shark.properties_full = deepcopy(SHARK_PROPERTIES_DICT)
|
||||
|
@ -98,7 +100,7 @@ class MockAyla(AylaApi):
|
|||
class MockShark(SharkIqVacuum):
|
||||
"""Mocked SharkIqVacuum that won't hit the API."""
|
||||
|
||||
async def async_update(self, property_list: Optional[Iterable[str]] = None):
|
||||
async def async_update(self, property_list: Iterable[str] | None = None):
|
||||
"""Don't do anything."""
|
||||
|
||||
def set_property_value(self, property_name, value):
|
||||
|
@ -224,7 +226,7 @@ async def test_locate(hass):
|
|||
)
|
||||
@patch("sharkiqpy.ayla_api.AylaApi", MockAyla)
|
||||
async def test_coordinator_updates(
|
||||
hass: HomeAssistant, side_effect: Optional[Exception], success: bool
|
||||
hass: HomeAssistant, side_effect: Exception | None, success: bool
|
||||
) -> None:
|
||||
"""Test the update coordinator update functions."""
|
||||
coordinator = hass.data[DOMAIN][ENTRY_ID]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""The tests for the Shell command component."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from typing import Tuple
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from homeassistant.components import shell_command
|
||||
|
@ -12,7 +12,7 @@ from homeassistant.setup import async_setup_component
|
|||
def mock_process_creator(error: bool = False):
|
||||
"""Mock a coroutine that creates a process when yielded."""
|
||||
|
||||
async def communicate() -> Tuple[bytes, bytes]:
|
||||
async def communicate() -> tuple[bytes, bytes]:
|
||||
"""Mock a coroutine that runs a process when yielded.
|
||||
|
||||
Returns a tuple of (stdout, stderr).
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""Test slack notifications."""
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import logging
|
||||
from typing import List
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from _pytest.logging import LogCaptureFixture
|
||||
|
@ -39,7 +40,7 @@ DEFAULT_CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
def filter_log_records(caplog: LogCaptureFixture) -> List[logging.LogRecord]:
|
||||
def filter_log_records(caplog: LogCaptureFixture) -> list[logging.LogRecord]:
|
||||
"""Filter all unrelated log records."""
|
||||
return [
|
||||
rec for rec in caplog.records if rec.name.endswith(f"{DOMAIN}.{notify.DOMAIN}")
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"""Common fixtures and objects for the Switcher integration tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import Queue
|
||||
from datetime import datetime
|
||||
from typing import Any, Generator, Optional
|
||||
from typing import Any, Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pytest import fixture
|
||||
|
@ -56,7 +57,7 @@ class MockSwitcherV2Device:
|
|||
return DUMMY_DEVICE_STATE
|
||||
|
||||
@property
|
||||
def remaining_time(self) -> Optional[str]:
|
||||
def remaining_time(self) -> str | None:
|
||||
"""Return the time left to auto-off."""
|
||||
return DUMMY_REMAINING_TIME
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Tests for the TP-Link component."""
|
||||
from typing import Any, Dict
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from pyHS100 import SmartBulb, SmartDevice, SmartDeviceException, SmartPlug
|
||||
|
@ -88,25 +90,20 @@ class UnknownSmartDevice(SmartDevice):
|
|||
@property
|
||||
def has_emeter(self) -> bool:
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
def turn_off(self) -> None:
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
def turn_on(self) -> None:
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
@property
|
||||
def state_information(self) -> Dict[str, Any]:
|
||||
def state_information(self) -> dict[str, Any]:
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
|
||||
async def test_configuring_devices_from_multiple_sources(hass):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Tests for the integration of a twinly device."""
|
||||
from typing import Tuple
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.twinkly.const import (
|
||||
|
@ -190,7 +191,7 @@ async def test_unload(hass: HomeAssistant):
|
|||
|
||||
async def _create_entries(
|
||||
hass: HomeAssistant, client=None
|
||||
) -> Tuple[RegistryEntry, DeviceEntry, ClientMock]:
|
||||
) -> tuple[RegistryEntry, DeviceEntry, ClientMock]:
|
||||
client = ClientMock() if client is None else client
|
||||
|
||||
def get_client_mock(client, _):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Fixtures for UniFi methods."""
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiounifi.websocket import SIGNAL_CONNECTION_STATE, SIGNAL_DATA
|
||||
|
@ -11,7 +12,7 @@ def mock_unifi_websocket():
|
|||
"""No real websocket allowed."""
|
||||
with patch("aiounifi.controller.WSClient") as mock:
|
||||
|
||||
def make_websocket_call(data: Optional[dict] = None, state: str = ""):
|
||||
def make_websocket_call(data: dict | None = None, state: str = ""):
|
||||
"""Generate a websocket call."""
|
||||
if data:
|
||||
mock.return_value.data = data
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Common code for tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Callable, Dict, NamedTuple, Tuple
|
||||
from typing import Callable, NamedTuple
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pyvera as pv
|
||||
|
@ -29,7 +31,7 @@ class ControllerData(NamedTuple):
|
|||
class ComponentData(NamedTuple):
|
||||
"""Test data about the vera component."""
|
||||
|
||||
controller_data: Tuple[ControllerData]
|
||||
controller_data: tuple[ControllerData]
|
||||
|
||||
|
||||
class ConfigSource(Enum):
|
||||
|
@ -43,12 +45,12 @@ class ConfigSource(Enum):
|
|||
class ControllerConfig(NamedTuple):
|
||||
"""Test config for mocking a vera controller."""
|
||||
|
||||
config: Dict
|
||||
options: Dict
|
||||
config: dict
|
||||
options: dict
|
||||
config_source: ConfigSource
|
||||
serial_number: str
|
||||
devices: Tuple[pv.VeraDevice, ...]
|
||||
scenes: Tuple[pv.VeraScene, ...]
|
||||
devices: tuple[pv.VeraDevice, ...]
|
||||
scenes: tuple[pv.VeraScene, ...]
|
||||
setup_callback: SetupCallback
|
||||
legacy_entity_unique_id: bool
|
||||
|
||||
|
@ -58,8 +60,8 @@ def new_simple_controller_config(
|
|||
options: dict = None,
|
||||
config_source=ConfigSource.CONFIG_FLOW,
|
||||
serial_number="1111",
|
||||
devices: Tuple[pv.VeraDevice, ...] = (),
|
||||
scenes: Tuple[pv.VeraScene, ...] = (),
|
||||
devices: tuple[pv.VeraDevice, ...] = (),
|
||||
scenes: tuple[pv.VeraScene, ...] = (),
|
||||
setup_callback: SetupCallback = None,
|
||||
legacy_entity_unique_id=False,
|
||||
) -> ControllerConfig:
|
||||
|
@ -87,7 +89,7 @@ class ComponentFactory:
|
|||
self,
|
||||
hass: HomeAssistant,
|
||||
controller_config: ControllerConfig = None,
|
||||
controller_configs: Tuple[ControllerConfig] = (),
|
||||
controller_configs: tuple[ControllerConfig] = (),
|
||||
) -> ComponentData:
|
||||
"""Configure the component with multiple specific mock data."""
|
||||
configs = list(controller_configs)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Vera tests."""
|
||||
from typing import Any, Callable, Tuple
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pyvera as pv
|
||||
|
@ -15,7 +17,7 @@ async def run_sensor_test(
|
|||
vera_component_factory: ComponentFactory,
|
||||
category: int,
|
||||
class_property: str,
|
||||
assert_states: Tuple[Tuple[Any, Any]],
|
||||
assert_states: tuple[tuple[Any, Any]],
|
||||
assert_unit_of_measurement: str = None,
|
||||
setup_callback: Callable[[pv.VeraController], None] = None,
|
||||
) -> None:
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""Tests for Vizio config flow."""
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import timedelta
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import pytest
|
||||
|
@ -87,7 +89,7 @@ async def _add_config_entry_to_hass(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
def _get_ha_power_state(vizio_power_state: Optional[bool]) -> str:
|
||||
def _get_ha_power_state(vizio_power_state: bool | None) -> str:
|
||||
"""Return HA power state given Vizio power state."""
|
||||
if vizio_power_state:
|
||||
return STATE_ON
|
||||
|
@ -98,7 +100,7 @@ def _get_ha_power_state(vizio_power_state: Optional[bool]) -> str:
|
|||
return STATE_UNAVAILABLE
|
||||
|
||||
|
||||
def _assert_sources_and_volume(attr: Dict[str, Any], vizio_device_class: str) -> None:
|
||||
def _assert_sources_and_volume(attr: dict[str, Any], vizio_device_class: str) -> None:
|
||||
"""Assert source list, source, and volume level based on attr dict and device class."""
|
||||
assert attr["source_list"] == INPUT_LIST
|
||||
assert attr["source"] == CURRENT_INPUT
|
||||
|
@ -111,7 +113,7 @@ def _assert_sources_and_volume(attr: Dict[str, Any], vizio_device_class: str) ->
|
|||
|
||||
def _get_attr_and_assert_base_attr(
|
||||
hass: HomeAssistantType, device_class: str, power_state: str
|
||||
) -> Dict[str, Any]:
|
||||
) -> dict[str, Any]:
|
||||
"""Return entity attributes after asserting name, device class, and power state."""
|
||||
attr = hass.states.get(ENTITY_ID).attributes
|
||||
assert attr["friendly_name"] == NAME
|
||||
|
@ -123,7 +125,7 @@ def _get_attr_and_assert_base_attr(
|
|||
|
||||
@asynccontextmanager
|
||||
async def _cm_for_test_setup_without_apps(
|
||||
all_settings: Dict[str, Any], vizio_power_state: Optional[bool]
|
||||
all_settings: dict[str, Any], vizio_power_state: bool | None
|
||||
) -> None:
|
||||
"""Context manager to setup test for Vizio devices without including app specific patches."""
|
||||
with patch(
|
||||
|
@ -140,7 +142,7 @@ async def _cm_for_test_setup_without_apps(
|
|||
|
||||
|
||||
async def _test_setup_tv(
|
||||
hass: HomeAssistantType, vizio_power_state: Optional[bool]
|
||||
hass: HomeAssistantType, vizio_power_state: bool | None
|
||||
) -> None:
|
||||
"""Test Vizio TV entity setup."""
|
||||
ha_power_state = _get_ha_power_state(vizio_power_state)
|
||||
|
@ -164,7 +166,7 @@ async def _test_setup_tv(
|
|||
|
||||
|
||||
async def _test_setup_speaker(
|
||||
hass: HomeAssistantType, vizio_power_state: Optional[bool]
|
||||
hass: HomeAssistantType, vizio_power_state: bool | None
|
||||
) -> None:
|
||||
"""Test Vizio Speaker entity setup."""
|
||||
ha_power_state = _get_ha_power_state(vizio_power_state)
|
||||
|
@ -201,7 +203,7 @@ async def _test_setup_speaker(
|
|||
|
||||
@asynccontextmanager
|
||||
async def _cm_for_test_setup_tv_with_apps(
|
||||
hass: HomeAssistantType, device_config: Dict[str, Any], app_config: Dict[str, Any]
|
||||
hass: HomeAssistantType, device_config: dict[str, Any], app_config: dict[str, Any]
|
||||
) -> None:
|
||||
"""Context manager to setup test for Vizio TV with support for apps."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -229,7 +231,7 @@ async def _cm_for_test_setup_tv_with_apps(
|
|||
|
||||
|
||||
def _assert_source_list_with_apps(
|
||||
list_to_test: List[str], attr: Dict[str, Any]
|
||||
list_to_test: list[str], attr: dict[str, Any]
|
||||
) -> None:
|
||||
"""Assert source list matches list_to_test after removing INPUT_APPS from list."""
|
||||
for app_to_remove in INPUT_APPS:
|
||||
|
@ -244,7 +246,7 @@ async def _test_service(
|
|||
domain: str,
|
||||
vizio_func_name: str,
|
||||
ha_service_name: str,
|
||||
additional_service_data: Optional[Dict[str, Any]],
|
||||
additional_service_data: dict[str, Any] | None,
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
|
@ -460,8 +462,8 @@ async def test_options_update(
|
|||
|
||||
async def _test_update_availability_switch(
|
||||
hass: HomeAssistantType,
|
||||
initial_power_state: Optional[bool],
|
||||
final_power_state: Optional[bool],
|
||||
initial_power_state: bool | None,
|
||||
final_power_state: bool | None,
|
||||
caplog: pytest.fixture,
|
||||
) -> None:
|
||||
now = dt_util.utcnow()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Common data for for the withings component tests."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Optional, Tuple, Union
|
||||
from unittest.mock import MagicMock
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
@ -49,27 +50,21 @@ class ProfileConfig:
|
|||
|
||||
profile: str
|
||||
user_id: int
|
||||
api_response_user_get_device: Union[UserGetDeviceResponse, Exception]
|
||||
api_response_measure_get_meas: Union[MeasureGetMeasResponse, Exception]
|
||||
api_response_sleep_get_summary: Union[SleepGetSummaryResponse, Exception]
|
||||
api_response_notify_list: Union[NotifyListResponse, Exception]
|
||||
api_response_notify_revoke: Optional[Exception]
|
||||
api_response_user_get_device: UserGetDeviceResponse | Exception
|
||||
api_response_measure_get_meas: MeasureGetMeasResponse | Exception
|
||||
api_response_sleep_get_summary: SleepGetSummaryResponse | Exception
|
||||
api_response_notify_list: NotifyListResponse | Exception
|
||||
api_response_notify_revoke: Exception | None
|
||||
|
||||
|
||||
def new_profile_config(
|
||||
profile: str,
|
||||
user_id: int,
|
||||
api_response_user_get_device: Optional[
|
||||
Union[UserGetDeviceResponse, Exception]
|
||||
] = None,
|
||||
api_response_measure_get_meas: Optional[
|
||||
Union[MeasureGetMeasResponse, Exception]
|
||||
] = None,
|
||||
api_response_sleep_get_summary: Optional[
|
||||
Union[SleepGetSummaryResponse, Exception]
|
||||
] = None,
|
||||
api_response_notify_list: Optional[Union[NotifyListResponse, Exception]] = None,
|
||||
api_response_notify_revoke: Optional[Exception] = None,
|
||||
api_response_user_get_device: UserGetDeviceResponse | Exception | None = None,
|
||||
api_response_measure_get_meas: MeasureGetMeasResponse | Exception | None = None,
|
||||
api_response_sleep_get_summary: SleepGetSummaryResponse | Exception | None = None,
|
||||
api_response_notify_list: NotifyListResponse | Exception | None = None,
|
||||
api_response_notify_revoke: Exception | None = None,
|
||||
) -> ProfileConfig:
|
||||
"""Create a new profile config immutable object."""
|
||||
return ProfileConfig(
|
||||
|
@ -118,13 +113,13 @@ class ComponentFactory:
|
|||
self._aioclient_mock = aioclient_mock
|
||||
self._client_id = None
|
||||
self._client_secret = None
|
||||
self._profile_configs: Tuple[ProfileConfig, ...] = ()
|
||||
self._profile_configs: tuple[ProfileConfig, ...] = ()
|
||||
|
||||
async def configure_component(
|
||||
self,
|
||||
client_id: str = "my_client_id",
|
||||
client_secret: str = "my_client_secret",
|
||||
profile_configs: Tuple[ProfileConfig, ...] = (),
|
||||
profile_configs: tuple[ProfileConfig, ...] = (),
|
||||
) -> None:
|
||||
"""Configure the wihings component."""
|
||||
self._client_id = client_id
|
||||
|
@ -294,7 +289,7 @@ class ComponentFactory:
|
|||
|
||||
def get_config_entries_for_user_id(
|
||||
hass: HomeAssistant, user_id: int
|
||||
) -> Tuple[ConfigEntry]:
|
||||
) -> tuple[ConfigEntry]:
|
||||
"""Get a list of config entries that apply to a specific withings user."""
|
||||
return tuple(
|
||||
[
|
||||
|
@ -305,7 +300,7 @@ def get_config_entries_for_user_id(
|
|||
)
|
||||
|
||||
|
||||
def async_get_flow_for_user_id(hass: HomeAssistant, user_id: int) -> List[dict]:
|
||||
def async_get_flow_for_user_id(hass: HomeAssistant, user_id: int) -> list[dict]:
|
||||
"""Get a flow for a user id."""
|
||||
return [
|
||||
flow
|
||||
|
@ -316,7 +311,7 @@ def async_get_flow_for_user_id(hass: HomeAssistant, user_id: int) -> List[dict]:
|
|||
|
||||
def get_data_manager_by_user_id(
|
||||
hass: HomeAssistant, user_id: int
|
||||
) -> Optional[DataManager]:
|
||||
) -> DataManager | None:
|
||||
"""Get a data manager by the user id."""
|
||||
return next(
|
||||
iter(
|
||||
|
|
Loading…
Add table
Reference in a new issue