mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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
|
||||
# traffic on a typical network.
|
||||
advertisement_data = service_info.advertisement
|
||||
manufacturer_data = advertisement_data.manufacturer_data
|
||||
if (
|
||||
len(manufacturer_data) == 1
|
||||
and (apple_data := manufacturer_data.get(APPLE_MFR_ID))
|
||||
and apple_data[0] not in APPLE_START_BYTES_WANTED
|
||||
and not advertisement_data.service_data
|
||||
(manufacturer_data := service_info.manufacturer_data)
|
||||
and APPLE_MFR_ID in manufacturer_data
|
||||
and manufacturer_data[APPLE_MFR_ID][0] not in APPLE_START_BYTES_WANTED
|
||||
and len(manufacturer_data) == 1
|
||||
and not service_info.service_data
|
||||
):
|
||||
return
|
||||
|
||||
device = service_info.device
|
||||
address = device.address
|
||||
address = service_info.device.address
|
||||
all_history = self._all_history
|
||||
connectable = service_info.connectable
|
||||
connectable_history = self._connectable_history
|
||||
old_connectable_service_info = connectable and connectable_history.get(address)
|
||||
|
||||
source = service_info.source
|
||||
# This logic is complex due to the many combinations of scanners
|
||||
# that are supported.
|
||||
@ -544,13 +541,17 @@ class BluetoothManager:
|
||||
"%s: %s %s match: %s",
|
||||
self._async_describe_source(service_info),
|
||||
address,
|
||||
advertisement_data,
|
||||
service_info.advertisement,
|
||||
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
|
||||
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)
|
||||
|
||||
for match in self._callback_index.match_callbacks(service_info):
|
||||
|
Loading…
x
Reference in New Issue
Block a user