Skip to content

Commit

Permalink
feat: imporve performance of processing async_on_raw_advertisements
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 22, 2024
1 parent 9dbf03c commit 5df9ca2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bleak_esphome/backend/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def async_on_raw_advertisements(
) -> None:
"""Call the registered callback."""
now = MONOTONIC_TIME()
for adv in raw.advertisements:
# Avoid enumeration of raw.advertisements in the loop
# because protobuf will always have an internal exception
# when the list is exhausted.
for i in range(len(raw.advertisements)):
adv = raw.advertisements[i]
self._async_on_advertisement(
int_to_bluetooth_address(adv.address),
adv.rssi,
Expand Down

0 comments on commit 5df9ca2

Please sign in to comment.