Retrigger Bluetooth discovery when calling async_rediscover_address (#87884)
* Retrigger Bluetooth discovery when calling async_rediscover_address * Retrigger Bluetooth discovery when calling async_rediscover_address * tweak
This commit is contained in:
parent
7aa79415c1
commit
34e2751f14
2 changed files with 19 additions and 8 deletions
|
@ -216,13 +216,7 @@ class BluetoothManager:
|
|||
if address in seen:
|
||||
continue
|
||||
seen.add(address)
|
||||
for domain in self._integration_matcher.match_domains(service_info):
|
||||
discovery_flow.async_create_flow(
|
||||
self.hass,
|
||||
domain,
|
||||
{"source": config_entries.SOURCE_BLUETOOTH},
|
||||
service_info,
|
||||
)
|
||||
self._async_trigger_matching_discovery(service_info)
|
||||
|
||||
@hass_callback
|
||||
def async_stop(self, event: Event) -> None:
|
||||
|
@ -649,10 +643,27 @@ class BluetoothManager:
|
|||
"""Return the last service info for an address."""
|
||||
return self._get_history_by_type(connectable).get(address)
|
||||
|
||||
def _async_trigger_matching_discovery(
|
||||
self, service_info: BluetoothServiceInfoBleak
|
||||
) -> None:
|
||||
"""Trigger discovery for matching domains."""
|
||||
for domain in self._integration_matcher.match_domains(service_info):
|
||||
discovery_flow.async_create_flow(
|
||||
self.hass,
|
||||
domain,
|
||||
{"source": config_entries.SOURCE_BLUETOOTH},
|
||||
service_info,
|
||||
)
|
||||
|
||||
@hass_callback
|
||||
def async_rediscover_address(self, address: str) -> None:
|
||||
"""Trigger discovery of devices which have already been seen."""
|
||||
self._integration_matcher.async_clear_address(address)
|
||||
if service_info := self._connectable_history.get(address):
|
||||
self._async_trigger_matching_discovery(service_info)
|
||||
return
|
||||
if service_info := self._all_history.get(address):
|
||||
self._async_trigger_matching_discovery(service_info)
|
||||
|
||||
def _get_scanners_by_type(self, connectable: bool) -> list[BaseHaScanner]:
|
||||
"""Return the scanners by type."""
|
||||
|
|
|
@ -998,7 +998,7 @@ async def test_rediscovery(
|
|||
inject_advertisement(hass, switchbot_device, switchbot_adv_2)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_config_flow.mock_calls) == 2
|
||||
assert len(mock_config_flow.mock_calls) == 3
|
||||
assert mock_config_flow.mock_calls[1][1][0] == "switchbot"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue