Guard imports for type hinting in Bluetooth (#75984)

pull/76047/head
Franck Nijhof 2022-08-01 17:54:06 +02:00 committed by GitHub
parent bd3de4452b
commit fc399f21e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 20 deletions

View File

@ -8,12 +8,10 @@ from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import Enum
import logging
from typing import Final
from typing import TYPE_CHECKING, Final
import async_timeout
from bleak import BleakError
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
from homeassistant import config_entries
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
@ -27,7 +25,6 @@ from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import discovery_flow
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_bluetooth
from . import models
@ -42,6 +39,13 @@ from .models import HaBleakScanner, HaBleakScannerWrapper
from .usage import install_multiple_bleak_catcher, uninstall_multiple_bleak_catcher
from .util import async_get_bluetooth_adapters
if TYPE_CHECKING:
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)

View File

@ -1,18 +1,20 @@
"""Config flow to configure the Bluetooth integration."""
from __future__ import annotations
from typing import Any
from typing import TYPE_CHECKING, Any
import voluptuous as vol
from homeassistant.components import onboarding
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from .const import CONF_ADAPTER, DEFAULT_NAME, DOMAIN
from .util import async_get_bluetooth_adapters
if TYPE_CHECKING:
from homeassistant.data_entry_flow import FlowResult
class BluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow for Bluetooth."""

View File

@ -1,17 +1,21 @@
"""The bluetooth integration matchers."""
from __future__ import annotations
from collections.abc import Mapping
from dataclasses import dataclass
import fnmatch
from typing import Final, TypedDict
from typing import TYPE_CHECKING, Final, TypedDict
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
from lru import LRU # pylint: disable=no-name-in-module
from homeassistant.loader import BluetoothMatcher, BluetoothMatcherOptional
if TYPE_CHECKING:
from collections.abc import Mapping
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import AdvertisementData
MAX_REMEMBER_ADDRESSES: Final = 2048

View File

@ -4,10 +4,9 @@ from __future__ import annotations
import asyncio
import contextlib
import logging
from typing import Any, Final
from typing import TYPE_CHECKING, Any, Final
from bleak import BleakScanner
from bleak.backends.device import BLEDevice
from bleak.backends.scanner import (
AdvertisementData,
AdvertisementDataCallback,
@ -16,6 +15,10 @@ from bleak.backends.scanner import (
from homeassistant.core import CALLBACK_TYPE, callback as hass_callback
if TYPE_CHECKING:
from bleak.backends.device import BLEDevice
_LOGGER = logging.getLogger(__name__)
FILTER_UUIDS: Final = "UUIDs"

View File

@ -1,16 +1,19 @@
"""Passive update coordinator for the Bluetooth integration."""
from __future__ import annotations
from collections.abc import Callable, Generator
import logging
from typing import Any
from typing import TYPE_CHECKING, Any
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
from .update_coordinator import BasePassiveBluetoothCoordinator
if TYPE_CHECKING:
from collections.abc import Callable, Generator
import logging
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
class PassiveBluetoothDataUpdateCoordinator(BasePassiveBluetoothCoordinator):
"""Class to manage passive bluetooth advertisements.

View File

@ -1,20 +1,24 @@
"""Passive update processors for the Bluetooth integration."""
from __future__ import annotations
from collections.abc import Callable, Mapping
import dataclasses
import logging
from typing import Any, Generic, TypeVar
from typing import TYPE_CHECKING, Any, Generic, TypeVar
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_NAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
from .const import DOMAIN
from .update_coordinator import BasePassiveBluetoothCoordinator
if TYPE_CHECKING:
from collections.abc import Callable, Mapping
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
@dataclasses.dataclass(frozen=True)
class PassiveBluetoothEntityKey: