From 95d6859cb7fb29e58130a03420d77166d03c7124 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 23 Oct 2022 04:34:03 -0500 Subject: [PATCH] Log bluetooth advertisement before firing bleak callbacks (#80800) The debug log was confusing because the bleak callbacks were firing before we were logging the advertisements --- homeassistant/components/bluetooth/manager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/bluetooth/manager.py b/homeassistant/components/bluetooth/manager.py index ba294e8e64a..aaefd3dcfc4 100644 --- a/homeassistant/components/bluetooth/manager.py +++ b/homeassistant/components/bluetooth/manager.py @@ -433,11 +433,7 @@ class BluetoothManager: ): return - if is_connectable_by_any_source := address in self._connectable_history: - # Bleak callbacks must get a connectable device - for callback_filters in self._bleak_callbacks: - _dispatch_bleak_callback(*callback_filters, device, advertisement_data) - + is_connectable_by_any_source = address in self._connectable_history if not connectable and is_connectable_by_any_source: # Since we have a connectable path and our BleakClient will # route any connection attempts to the connectable path, we @@ -456,6 +452,11 @@ class BluetoothManager: advertisement_data.rssi, ) + if is_connectable_by_any_source: + # Bleak callbacks must get a connectable device + for callback_filters in self._bleak_callbacks: + _dispatch_bleak_callback(*callback_filters, device, advertisement_data) + for match in self._callback_index.match_callbacks(service_info): callback = match[CALLBACK] try: