Guard imports for type hinting in Bluetooth (#75984)
parent
bd3de4452b
commit
fc399f21e9
|
@ -8,12 +8,10 @@ from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import logging
|
import logging
|
||||||
from typing import Final
|
from typing import TYPE_CHECKING, Final
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from bleak import BleakError
|
from bleak import BleakError
|
||||||
from bleak.backends.device import BLEDevice
|
|
||||||
from bleak.backends.scanner import AdvertisementData
|
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
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 import discovery_flow
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
from homeassistant.loader import async_get_bluetooth
|
from homeassistant.loader import async_get_bluetooth
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -42,6 +39,13 @@ from .models import HaBleakScanner, HaBleakScannerWrapper
|
||||||
from .usage import install_multiple_bleak_catcher, uninstall_multiple_bleak_catcher
|
from .usage import install_multiple_bleak_catcher, uninstall_multiple_bleak_catcher
|
||||||
from .util import async_get_bluetooth_adapters
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
"""Config flow to configure the Bluetooth integration."""
|
"""Config flow to configure the Bluetooth integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import onboarding
|
from homeassistant.components import onboarding
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
|
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
|
||||||
|
|
||||||
from .const import CONF_ADAPTER, DEFAULT_NAME, DOMAIN
|
from .const import CONF_ADAPTER, DEFAULT_NAME, DOMAIN
|
||||||
from .util import async_get_bluetooth_adapters
|
from .util import async_get_bluetooth_adapters
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
|
|
||||||
class BluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
class BluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Config flow for Bluetooth."""
|
"""Config flow for Bluetooth."""
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
"""The bluetooth integration matchers."""
|
"""The bluetooth integration matchers."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import fnmatch
|
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 lru import LRU # pylint: disable=no-name-in-module
|
||||||
|
|
||||||
from homeassistant.loader import BluetoothMatcher, BluetoothMatcherOptional
|
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
|
MAX_REMEMBER_ADDRESSES: Final = 2048
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,9 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Final
|
from typing import TYPE_CHECKING, Any, Final
|
||||||
|
|
||||||
from bleak import BleakScanner
|
from bleak import BleakScanner
|
||||||
from bleak.backends.device import BLEDevice
|
|
||||||
from bleak.backends.scanner import (
|
from bleak.backends.scanner import (
|
||||||
AdvertisementData,
|
AdvertisementData,
|
||||||
AdvertisementDataCallback,
|
AdvertisementDataCallback,
|
||||||
|
@ -16,6 +15,10 @@ from bleak.backends.scanner import (
|
||||||
|
|
||||||
from homeassistant.core import CALLBACK_TYPE, callback as hass_callback
|
from homeassistant.core import CALLBACK_TYPE, callback as hass_callback
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from bleak.backends.device import BLEDevice
|
||||||
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
FILTER_UUIDS: Final = "UUIDs"
|
FILTER_UUIDS: Final = "UUIDs"
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
"""Passive update coordinator for the Bluetooth integration."""
|
"""Passive update coordinator for the Bluetooth integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable, Generator
|
from typing import TYPE_CHECKING, Any
|
||||||
import logging
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
|
|
||||||
from .update_coordinator import BasePassiveBluetoothCoordinator
|
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 PassiveBluetoothDataUpdateCoordinator(BasePassiveBluetoothCoordinator):
|
||||||
"""Class to manage passive bluetooth advertisements.
|
"""Class to manage passive bluetooth advertisements.
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
"""Passive update processors for the Bluetooth integration."""
|
"""Passive update processors for the Bluetooth integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable, Mapping
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import logging
|
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.const import ATTR_IDENTIFIERS, ATTR_NAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
|
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 .const import DOMAIN
|
||||||
from .update_coordinator import BasePassiveBluetoothCoordinator
|
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)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class PassiveBluetoothEntityKey:
|
class PassiveBluetoothEntityKey:
|
||||||
|
|
Loading…
Reference in New Issue