mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Optimize bluetooth base scanners for python3.11+ (#96165)
This commit is contained in:
parent
7390e3a997
commit
e8397063d3
@ -303,7 +303,19 @@ class BaseHaRemoteScanner(BaseHaScanner):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Call the registered callback."""
|
"""Call the registered callback."""
|
||||||
self._last_detection = advertisement_monotonic_time
|
self._last_detection = advertisement_monotonic_time
|
||||||
if prev_discovery := self._discovered_device_advertisement_datas.get(address):
|
try:
|
||||||
|
prev_discovery = self._discovered_device_advertisement_datas[address]
|
||||||
|
except KeyError:
|
||||||
|
# We expect this is the rare case and since py3.11+ has
|
||||||
|
# near zero cost try on success, and we can avoid .get()
|
||||||
|
# which is slower than [] we use the try/except pattern.
|
||||||
|
device = BLEDevice(
|
||||||
|
address=address,
|
||||||
|
name=local_name,
|
||||||
|
details=self._details | details,
|
||||||
|
rssi=rssi, # deprecated, will be removed in newer bleak
|
||||||
|
)
|
||||||
|
else:
|
||||||
# Merge the new data with the old data
|
# Merge the new data with the old data
|
||||||
# to function the same as BlueZ which
|
# to function the same as BlueZ which
|
||||||
# merges the dicts on PropertiesChanged
|
# merges the dicts on PropertiesChanged
|
||||||
@ -344,13 +356,6 @@ class BaseHaRemoteScanner(BaseHaScanner):
|
|||||||
device.details = self._details | details
|
device.details = self._details | details
|
||||||
# pylint: disable-next=protected-access
|
# pylint: disable-next=protected-access
|
||||||
device._rssi = rssi # deprecated, will be removed in newer bleak
|
device._rssi = rssi # deprecated, will be removed in newer bleak
|
||||||
else:
|
|
||||||
device = BLEDevice(
|
|
||||||
address=address,
|
|
||||||
name=local_name,
|
|
||||||
details=self._details | details,
|
|
||||||
rssi=rssi, # deprecated, will be removed in newer bleak
|
|
||||||
)
|
|
||||||
|
|
||||||
advertisement_data = AdvertisementData(
|
advertisement_data = AdvertisementData(
|
||||||
local_name=None if local_name == "" else local_name,
|
local_name=None if local_name == "" else local_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user