mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Small cleanups to bluetooth manager advertisement processing (#95453)
Avoid a few lookups that are rarely used now
This commit is contained in:
parent
dfe7c5ebed
commit
54255331d5
@ -413,23 +413,20 @@ class BluetoothManager:
|
|||||||
|
|
||||||
# Pre-filter noisy apple devices as they can account for 20-35% of the
|
# Pre-filter noisy apple devices as they can account for 20-35% of the
|
||||||
# traffic on a typical network.
|
# traffic on a typical network.
|
||||||
advertisement_data = service_info.advertisement
|
|
||||||
manufacturer_data = advertisement_data.manufacturer_data
|
|
||||||
if (
|
if (
|
||||||
len(manufacturer_data) == 1
|
(manufacturer_data := service_info.manufacturer_data)
|
||||||
and (apple_data := manufacturer_data.get(APPLE_MFR_ID))
|
and APPLE_MFR_ID in manufacturer_data
|
||||||
and apple_data[0] not in APPLE_START_BYTES_WANTED
|
and manufacturer_data[APPLE_MFR_ID][0] not in APPLE_START_BYTES_WANTED
|
||||||
and not advertisement_data.service_data
|
and len(manufacturer_data) == 1
|
||||||
|
and not service_info.service_data
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
device = service_info.device
|
address = service_info.device.address
|
||||||
address = device.address
|
|
||||||
all_history = self._all_history
|
all_history = self._all_history
|
||||||
connectable = service_info.connectable
|
connectable = service_info.connectable
|
||||||
connectable_history = self._connectable_history
|
connectable_history = self._connectable_history
|
||||||
old_connectable_service_info = connectable and connectable_history.get(address)
|
old_connectable_service_info = connectable and connectable_history.get(address)
|
||||||
|
|
||||||
source = service_info.source
|
source = service_info.source
|
||||||
# This logic is complex due to the many combinations of scanners
|
# This logic is complex due to the many combinations of scanners
|
||||||
# that are supported.
|
# that are supported.
|
||||||
@ -544,13 +541,17 @@ class BluetoothManager:
|
|||||||
"%s: %s %s match: %s",
|
"%s: %s %s match: %s",
|
||||||
self._async_describe_source(service_info),
|
self._async_describe_source(service_info),
|
||||||
address,
|
address,
|
||||||
advertisement_data,
|
service_info.advertisement,
|
||||||
matched_domains,
|
matched_domains,
|
||||||
)
|
)
|
||||||
|
|
||||||
if connectable or old_connectable_service_info:
|
if (connectable or old_connectable_service_info) and (
|
||||||
|
bleak_callbacks := self._bleak_callbacks
|
||||||
|
):
|
||||||
# Bleak callbacks must get a connectable device
|
# Bleak callbacks must get a connectable device
|
||||||
for callback_filters in self._bleak_callbacks:
|
device = service_info.device
|
||||||
|
advertisement_data = service_info.advertisement
|
||||||
|
for callback_filters in bleak_callbacks:
|
||||||
_dispatch_bleak_callback(*callback_filters, device, advertisement_data)
|
_dispatch_bleak_callback(*callback_filters, device, advertisement_data)
|
||||||
|
|
||||||
for match in self._callback_index.match_callbacks(service_info):
|
for match in self._callback_index.match_callbacks(service_info):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user