Skip to content

Commit a658ce5

Browse files
committed
Fix HACS and Hassfest validation
1 parent 0802542 commit a658ce5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

custom_components/ble_monitor/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import logging
66
import struct
7+
import importlib
78
from threading import Thread
89

910
import aioblescan as aiobs
@@ -17,10 +18,6 @@
1718
from homeassistant.helpers import config_validation as cv
1819
from homeassistant.helpers import device_registry, entity_registry
1920
from homeassistant.util import dt
20-
try:
21-
from homeassistant.components import bluetooth
22-
except ImportError:
23-
bluetooth = None
2421

2522
from .ble_parser import BleParser
2623
from .bt_helpers import (BT_INTERFACES, BT_MULTI_SELECT, DEFAULT_BT_INTERFACE,
@@ -516,6 +513,10 @@ def __init__(self, config, dataqueue):
516513
self.report_unknown_whitelist = []
517514
self.last_bt_reset = dt.now()
518515
self.scanners = {}
516+
try:
517+
self.bluetooth = importlib.import_module("homeassistant.components.bluetooth")
518+
except ImportError:
519+
self.bluetooth = None
519520
if self.config[CONF_REPORT_UNKNOWN]:
520521
if self.config[CONF_REPORT_UNKNOWN] != "Off":
521522
self.report_unknown = self.config[CONF_REPORT_UNKNOWN]
@@ -588,8 +589,7 @@ def __init__(self, config, dataqueue):
588589
aeskeys=self.aeskeys,
589590
)
590591

591-
@staticmethod
592-
def hci_packet_on_advertisement(scanner, packet):
592+
def hci_packet_on_advertisement(self, scanner, packet):
593593
def _format_uuid(uuid: bytes) -> str:
594594
if len(uuid) == 2 or len(uuid) == 4:
595595
return "{:08x}-0000-1000-8000-00805f9b34fb".format(
@@ -675,15 +675,15 @@ def _format_uuid(uuid: bytes) -> str:
675675
manufacturer_data=manufacturer_data,
676676
tx_power=tx_power,
677677
details={"address_type": address_type},
678-
advertisement_monotonic_time=bluetooth.MONOTONIC_TIME(),
678+
advertisement_monotonic_time=self.bluetooth.MONOTONIC_TIME(),
679679
)
680680

681681
def process_hci_events(self, data, device_id=None, gateway_id=DOMAIN, proxy=False):
682682
"""Parse HCI events."""
683683
self.evt_cnt += 1
684684
if len(data) < 12:
685685
return
686-
if bluetooth is not None and proxy:
686+
if self.bluetooth is not None and proxy:
687687
try:
688688
scanner_name = device_id or gateway_id
689689
scanner = self.scanners.get(scanner_name)
@@ -694,8 +694,8 @@ def process_hci_events(self, data, device_id=None, gateway_id=DOMAIN, proxy=Fals
694694
if entry.name.lower() == gateway_id.lower()), None)
695695
source = next((connection[1] for connection in device.connections if
696696
connection[0] in ["mac", "bluetooth"]), gateway_id) if device else gateway_id
697-
scanner = bluetooth.BaseHaRemoteScanner(source, gateway_id, None, False)
698-
bluetooth.async_register_scanner(hass, scanner)
697+
scanner = self.bluetooth.BaseHaRemoteScanner(source, gateway_id, None, False)
698+
self.bluetooth.async_register_scanner(hass, scanner)
699699
self.scanners[scanner_name] = scanner
700700
self.hci_packet_on_advertisement(scanner, data)
701701
except Exception as e:

0 commit comments

Comments
 (0)