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