Skip to content

Commit a69de13

Browse files
authored
feat: improve performance by cimporting base_scanner (#119)
* feat: imporve performance by cimporting base_scanner * feat: imporve performance by cimporting base_scanner * chore: pin habluetooth to avoid breaking changes * chore: pin habluetooth to avoid breaking changes
1 parent 70e2986 commit a69de13

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ python = ">=3.11,<3.14"
3636
aioesphomeapi = ">=29.3.1"
3737
bleak = ">=0.21.1"
3838
bluetooth-data-tools = ">=1.18.0"
39-
habluetooth = ">=3.24.1"
39+
habluetooth = ">=3.24.1,<4"
4040
lru-dict = ">=1.2.0"
4141
bleak-retry-connector = ">=3.8.0"
4242

@@ -160,5 +160,5 @@ module = "docs.*"
160160
ignore_errors = true
161161

162162
[build-system]
163-
requires = ['setuptools>=75.8.2', 'Cython>=3', "poetry-core>=2.0.0"]
163+
requires = ['setuptools>=75.8.2', 'Cython>=3', "poetry-core>=2.0.0", "habluetooth"]
164164
build-backend = "poetry.core.masonry.api"

src/bleak_esphome/backend/scanner.pxd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
from habluetooth.base_scanner cimport BaseHaRemoteScanner
3+
24
cdef object MONOTONIC_TIME
35
cdef object int_to_bluetooth_address
46
cdef object parse_advertisement_data_tuple
7+
8+
cdef class ESPHomeScanner(BaseHaRemoteScanner):
9+
pass

src/bleak_esphome/backend/scanner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bluetooth_data_tools import (
1111
monotonic_time_coarse as MONOTONIC_TIME,
1212
)
13-
from habluetooth import BaseHaRemoteScanner
13+
from habluetooth.base_scanner import BaseHaRemoteScanner
1414

1515

1616
class ESPHomeScanner(BaseHaRemoteScanner):
@@ -39,7 +39,6 @@ def async_on_raw_advertisements(
3939
"""Call the registered callback."""
4040
now = MONOTONIC_TIME()
4141
advertisements = raw.advertisements
42-
async_on_advertisement = self._async_on_advertisement
4342
# We avoid __iter__ on the protobuf object because
4443
# the the protobuf library has an expensive internal
4544
# debug logging when it reaches the end of a repeated field.
@@ -50,7 +49,7 @@ def async_on_raw_advertisements(
5049
for i in range(len(advertisements)):
5150
adv = advertisements[i]
5251
parsed: tuple = parse_advertisement_data_tuple((adv.data,)) # type: ignore[type-arg]
53-
async_on_advertisement(
52+
self._async_on_advertisement(
5453
int_to_bluetooth_address(adv.address),
5554
adv.rssi,
5655
parsed[0],

0 commit comments

Comments
 (0)