mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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
e8081c6159
commit
65c8895bf7
@ -216,13 +216,7 @@ class BluetoothManager:
|
|||||||
if address in seen:
|
if address in seen:
|
||||||
continue
|
continue
|
||||||
seen.add(address)
|
seen.add(address)
|
||||||
for domain in self._integration_matcher.match_domains(service_info):
|
self._async_trigger_matching_discovery(service_info)
|
||||||
discovery_flow.async_create_flow(
|
|
||||||
self.hass,
|
|
||||||
domain,
|
|
||||||
{"source": config_entries.SOURCE_BLUETOOTH},
|
|
||||||
service_info,
|
|
||||||
)
|
|
||||||
|
|
||||||
@hass_callback
|
@hass_callback
|
||||||
def async_stop(self, event: Event) -> None:
|
def async_stop(self, event: Event) -> None:
|
||||||
@ -649,10 +643,27 @@ class BluetoothManager:
|
|||||||
"""Return the last service info for an address."""
|
"""Return the last service info for an address."""
|
||||||
return self._get_history_by_type(connectable).get(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
|
@hass_callback
|
||||||
def async_rediscover_address(self, address: str) -> None:
|
def async_rediscover_address(self, address: str) -> None:
|
||||||
"""Trigger discovery of devices which have already been seen."""
|
"""Trigger discovery of devices which have already been seen."""
|
||||||
self._integration_matcher.async_clear_address(address)
|
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]:
|
def _get_scanners_by_type(self, connectable: bool) -> list[BaseHaScanner]:
|
||||||
"""Return the scanners by type."""
|
"""Return the scanners by type."""
|
||||||
|
@ -980,7 +980,7 @@ async def test_rediscovery(hass, mock_bleak_scanner_start, enable_bluetooth):
|
|||||||
inject_advertisement(hass, switchbot_device, switchbot_adv_2)
|
inject_advertisement(hass, switchbot_device, switchbot_adv_2)
|
||||||
await hass.async_block_till_done()
|
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"
|
assert mock_config_flow.mock_calls[1][1][0] == "switchbot"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user