2022-07-08 23:55:31 +00:00
|
|
|
"""Models for bluetooth."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-08-17 00:52:53 +00:00
|
|
|
from collections.abc import Callable
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from enum import Enum
|
2022-11-20 14:44:28 +00:00
|
|
|
from typing import TYPE_CHECKING, Final
|
2022-07-08 23:55:31 +00:00
|
|
|
|
2022-11-20 14:44:28 +00:00
|
|
|
from bleak import BaseBleakClient
|
2022-11-15 20:00:52 +00:00
|
|
|
from home_assistant_bluetooth import BluetoothServiceInfoBleak
|
2022-07-08 23:55:31 +00:00
|
|
|
|
2022-11-13 20:18:36 +00:00
|
|
|
from homeassistant.util.dt import monotonic_time_coarse
|
|
|
|
|
2022-08-01 15:54:06 +00:00
|
|
|
if TYPE_CHECKING:
|
2022-08-17 20:51:56 +00:00
|
|
|
from .manager import BluetoothManager
|
|
|
|
|
2022-08-01 15:54:06 +00:00
|
|
|
|
2022-08-17 20:51:56 +00:00
|
|
|
MANAGER: BluetoothManager | None = None
|
2022-07-08 23:55:31 +00:00
|
|
|
|
2022-11-13 20:18:36 +00:00
|
|
|
MONOTONIC_TIME: Final = monotonic_time_coarse
|
|
|
|
|
2022-07-08 23:55:31 +00:00
|
|
|
|
2022-09-24 01:09:28 +00:00
|
|
|
@dataclass
|
|
|
|
class HaBluetoothConnector:
|
|
|
|
"""Data for how to connect a BLEDevice from a given scanner."""
|
|
|
|
|
|
|
|
client: type[BaseBleakClient]
|
|
|
|
source: str
|
|
|
|
can_connect: Callable[[], bool]
|
|
|
|
|
|
|
|
|
2022-11-20 14:44:28 +00:00
|
|
|
class BluetoothScanningMode(Enum):
|
|
|
|
"""The mode of scanning for bluetooth devices."""
|
2022-09-26 13:12:08 +00:00
|
|
|
|
2022-11-20 14:44:28 +00:00
|
|
|
PASSIVE = "passive"
|
|
|
|
ACTIVE = "active"
|
2022-09-24 01:09:28 +00:00
|
|
|
|
|
|
|
|
2022-11-20 14:44:28 +00:00
|
|
|
BluetoothChange = Enum("BluetoothChange", "ADVERTISEMENT")
|
|
|
|
BluetoothCallback = Callable[[BluetoothServiceInfoBleak, BluetoothChange], None]
|
|
|
|
ProcessAdvertisementCallback = Callable[[BluetoothServiceInfoBleak], bool]
|