@@ -686,7 +686,7 @@ def process_hci_events(self, data, device_id=None, gateway_id=DOMAIN, proxy=Fals
686
686
if self .bluetooth is not None and proxy :
687
687
try :
688
688
scanner_name = device_id or gateway_id
689
- scanner = self .scanners .get (scanner_name )
689
+ scanner , _ = self .scanners .get (scanner_name , ( None , None ) )
690
690
if not scanner :
691
691
hass = async_get_hass ()
692
692
device = hass .data ["device_registry" ].devices .get (device_id ) if device_id \
@@ -695,8 +695,9 @@ def process_hci_events(self, data, device_id=None, gateway_id=DOMAIN, proxy=Fals
695
695
source = next ((connection [1 ] for connection in device .connections if
696
696
connection [0 ] in ["mac" , "bluetooth" ]), gateway_id ) if device else gateway_id
697
697
scanner = self .bluetooth .BaseHaRemoteScanner (source , gateway_id , None , False )
698
- self .bluetooth .async_register_scanner (hass , scanner )
699
- self .scanners [scanner_name ] = scanner
698
+ self .scanners [scanner_name ] = (scanner , [
699
+ self .bluetooth .async_register_scanner (hass , scanner ),
700
+ scanner .async_setup ()])
700
701
self .hci_packet_on_advertisement (scanner , data )
701
702
except Exception as e :
702
703
_LOGGER .error ("%s: %s: %s" , gateway_id , e , data .hex ().upper ())
@@ -853,6 +854,9 @@ def run(self):
853
854
_LOGGER .debug ("%i HCI events processed for previous period" , self .evt_cnt )
854
855
self .evt_cnt = 0
855
856
self ._event_loop .close ()
857
+ for _ , unload_callbacks in self .scanners .values ():
858
+ for callback in unload_callbacks :
859
+ callback ()
856
860
_LOGGER .debug ("HCIdump thread: Run finished" )
857
861
858
862
def join (self , timeout = 10 ):
0 commit comments