From 4fb7c04ba366a2199d5bbd06a9d4d81431829885 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 31 Aug 2026 11:36:38 +0200 Subject: [PATCH] Use NEWEST_FIRST replay for Matter BLE commissioning (#176822) Co-authored-by: J. Nick Koston --- homeassistant/components/matter/ble_proxy.py | 2 ++ tests/components/matter/test_ble_proxy.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/matter/ble_proxy.py b/homeassistant/components/matter/ble_proxy.py index f25f4e3ebaa6..4eca8f124121 100644 --- a/homeassistant/components/matter/ble_proxy.py +++ b/homeassistant/components/matter/ble_proxy.py @@ -25,6 +25,7 @@ from matter_ble_proxy import ( from homeassistant.components.bluetooth import ( MONOTONIC_TIME, + BluetoothCallbackReplay, BluetoothScanningMode, async_ble_device_from_address, async_register_callback, @@ -77,6 +78,7 @@ class HaBluetoothScanSource(BleScanSource): _on_advertisement, None, BluetoothScanningMode.PASSIVE, + replay=BluetoothCallbackReplay.NEWEST_FIRST, ) @override diff --git a/tests/components/matter/test_ble_proxy.py b/tests/components/matter/test_ble_proxy.py index cd7c774dde84..7a100da18e97 100644 --- a/tests/components/matter/test_ble_proxy.py +++ b/tests/components/matter/test_ble_proxy.py @@ -10,6 +10,7 @@ from matter_ble_proxy import AdvertisementData import pytest from homeassistant.components.bluetooth import ( + BluetoothCallbackReplay, BluetoothScanningMode, BluetoothServiceInfoBleak, ) @@ -92,10 +93,11 @@ async def test_scan_source_start_registers_passive_callback( await source.start(MagicMock()) register.assert_called_once() - args, _ = register.call_args + args, kwargs = register.call_args assert args[0] is hass assert args[2] is None assert args[3] is BluetoothScanningMode.PASSIVE + assert kwargs["replay"] is BluetoothCallbackReplay.NEWEST_FIRST assert source._cancel is cancel @@ -135,7 +137,7 @@ async def test_scan_source_callback_forwards_advertisement( forwarded: list[AdvertisementData] = [] captured: dict[str, object] = {} - def fake_register(hass_, cb, _matcher, _mode): + def fake_register(hass_, cb, _matcher, _mode, **_kwargs): captured["cb"] = cb return MagicMock() @@ -168,7 +170,7 @@ async def test_scan_source_drops_replayed_history( forwarded: list[AdvertisementData] = [] captured: dict[str, object] = {} - def fake_register(hass_, cb, _matcher, _mode): + def fake_register(hass_, cb, _matcher, _mode, **_kwargs): captured["cb"] = cb return MagicMock() @@ -196,7 +198,7 @@ async def test_scan_source_callback_swallows_exceptions( """A raising user callback is logged but does not bubble out of HA.""" captured: dict[str, object] = {} - def fake_register(hass_, cb, _matcher, _mode): + def fake_register(hass_, cb, _matcher, _mode, **_kwargs): captured["cb"] = cb return MagicMock()