mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Fix delay setting up new Yale Access Bluetooth entries (#83683)
Entries took a while to setup because of the async_wait_init_flow_finish call in _async_setup_component The delay was so long that users thought the integration was broken We had a wait in place for advertisements to arrive during discovery in case the lock was not yet seen. Since integration discovery is deferred until after startup this wait it no longer needed
This commit is contained in:
parent
ea95f74d6d
commit
fec887420d
@ -1,7 +1,6 @@
|
|||||||
"""Config flow for Yale Access Bluetooth integration."""
|
"""Config flow for Yale Access Bluetooth integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||||
|
|
||||||
from .const import CONF_KEY, CONF_LOCAL_NAME, CONF_SLOT, DOMAIN
|
from .const import CONF_KEY, CONF_LOCAL_NAME, CONF_SLOT, DOMAIN
|
||||||
from .util import async_get_service_info, human_readable_name
|
from .util import async_find_existing_service_info, human_readable_name
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -110,11 +109,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
raise AbortFlow(reason="already_configured")
|
raise AbortFlow(reason="already_configured")
|
||||||
|
|
||||||
try:
|
self._discovery_info = async_find_existing_service_info(
|
||||||
self._discovery_info = await async_get_service_info(
|
hass, local_name, address
|
||||||
hass, local_name, address
|
)
|
||||||
)
|
if not self._discovery_info:
|
||||||
except asyncio.TimeoutError:
|
|
||||||
return self.async_abort(reason="no_devices_found")
|
return self.async_abort(reason="no_devices_found")
|
||||||
|
|
||||||
# Integration discovery should abort other flows unless they
|
# Integration discovery should abort other flows unless they
|
||||||
|
@ -6,10 +6,8 @@ import platform
|
|||||||
from yalexs_ble import local_name_is_unique
|
from yalexs_ble import local_name_is_unique
|
||||||
|
|
||||||
from homeassistant.components.bluetooth import (
|
from homeassistant.components.bluetooth import (
|
||||||
BluetoothScanningMode,
|
|
||||||
BluetoothServiceInfoBleak,
|
BluetoothServiceInfoBleak,
|
||||||
async_discovered_service_info,
|
async_discovered_service_info,
|
||||||
async_process_advertisements,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.bluetooth.match import (
|
from homeassistant.components.bluetooth.match import (
|
||||||
ADDRESS,
|
ADDRESS,
|
||||||
@ -18,8 +16,6 @@ from homeassistant.components.bluetooth.match import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
|
||||||
from .const import DEVICE_TIMEOUT
|
|
||||||
|
|
||||||
|
|
||||||
def bluetooth_callback_matcher(
|
def bluetooth_callback_matcher(
|
||||||
local_name: str, address: str
|
local_name: str, address: str
|
||||||
@ -51,21 +47,6 @@ def async_find_existing_service_info(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def async_get_service_info(
|
|
||||||
hass: HomeAssistant, local_name: str, address: str
|
|
||||||
) -> BluetoothServiceInfoBleak:
|
|
||||||
"""Wait for the service info for the given local_name and address."""
|
|
||||||
if service_info := async_find_existing_service_info(hass, local_name, address):
|
|
||||||
return service_info
|
|
||||||
return await async_process_advertisements(
|
|
||||||
hass,
|
|
||||||
lambda service_info: True,
|
|
||||||
bluetooth_callback_matcher(local_name, address),
|
|
||||||
BluetoothScanningMode.ACTIVE,
|
|
||||||
DEVICE_TIMEOUT,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def short_address(address: str) -> str:
|
def short_address(address: str) -> str:
|
||||||
"""Convert a Bluetooth address to a short address."""
|
"""Convert a Bluetooth address to a short address."""
|
||||||
split_address = address.replace("-", ":").split(":")
|
split_address = address.replace("-", ":").split(":")
|
||||||
|
@ -400,8 +400,8 @@ async def test_bluetooth_step_success(hass: HomeAssistant) -> None:
|
|||||||
async def test_integration_discovery_success(hass: HomeAssistant) -> None:
|
async def test_integration_discovery_success(hass: HomeAssistant) -> None:
|
||||||
"""Test integration discovery step success path."""
|
"""Test integration discovery step success path."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=YALE_ACCESS_LOCK_DISCOVERY_INFO,
|
return_value=[YALE_ACCESS_LOCK_DISCOVERY_INFO],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -443,8 +443,8 @@ async def test_integration_discovery_success(hass: HomeAssistant) -> None:
|
|||||||
async def test_integration_discovery_device_not_found(hass: HomeAssistant) -> None:
|
async def test_integration_discovery_device_not_found(hass: HomeAssistant) -> None:
|
||||||
"""Test integration discovery when the device is not found."""
|
"""Test integration discovery when the device is not found."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
side_effect=asyncio.TimeoutError,
|
return_value=[],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -483,8 +483,8 @@ async def test_integration_discovery_takes_precedence_over_bluetooth(
|
|||||||
assert flows[0]["context"]["local_name"] == YALE_ACCESS_LOCK_DISCOVERY_INFO.name
|
assert flows[0]["context"]["local_name"] == YALE_ACCESS_LOCK_DISCOVERY_INFO.name
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=YALE_ACCESS_LOCK_DISCOVERY_INFO,
|
return_value=[YALE_ACCESS_LOCK_DISCOVERY_INFO],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -558,8 +558,8 @@ async def test_integration_discovery_updates_key_unique_local_name(
|
|||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=LOCK_DISCOVERY_INFO_UUID_ADDRESS,
|
return_value=[LOCK_DISCOVERY_INFO_UUID_ADDRESS],
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.yalexs_ble.async_setup_entry",
|
"homeassistant.components.yalexs_ble.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -600,8 +600,8 @@ async def test_integration_discovery_updates_key_without_unique_local_name(
|
|||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=LOCK_DISCOVERY_INFO_UUID_ADDRESS,
|
return_value=[LOCK_DISCOVERY_INFO_UUID_ADDRESS],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -649,8 +649,8 @@ async def test_integration_discovery_updates_key_duplicate_local_name(
|
|||||||
entry2.add_to_hass(hass)
|
entry2.add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=LOCK_DISCOVERY_INFO_UUID_ADDRESS,
|
return_value=[LOCK_DISCOVERY_INFO_UUID_ADDRESS],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -695,8 +695,8 @@ async def test_integration_discovery_takes_precedence_over_bluetooth_uuid_addres
|
|||||||
assert flows[0]["context"]["local_name"] == LOCK_DISCOVERY_INFO_UUID_ADDRESS.name
|
assert flows[0]["context"]["local_name"] == LOCK_DISCOVERY_INFO_UUID_ADDRESS.name
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=LOCK_DISCOVERY_INFO_UUID_ADDRESS,
|
return_value=[LOCK_DISCOVERY_INFO_UUID_ADDRESS],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -775,8 +775,8 @@ async def test_integration_discovery_takes_precedence_over_bluetooth_non_unique_
|
|||||||
assert flows[0]["context"]["local_name"] == OLD_FIRMWARE_LOCK_DISCOVERY_INFO.name
|
assert flows[0]["context"]["local_name"] == OLD_FIRMWARE_LOCK_DISCOVERY_INFO.name
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=OLD_FIRMWARE_LOCK_DISCOVERY_INFO,
|
return_value=[OLD_FIRMWARE_LOCK_DISCOVERY_INFO],
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -851,8 +851,8 @@ async def test_user_is_setting_up_lock_and_discovery_happens_in_the_middle(
|
|||||||
await valdidate_started.wait()
|
await valdidate_started.wait()
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.yalexs_ble.util.async_process_advertisements",
|
"homeassistant.components.yalexs_ble.util.async_discovered_service_info",
|
||||||
return_value=LOCK_DISCOVERY_INFO_UUID_ADDRESS,
|
return_value=[LOCK_DISCOVERY_INFO_UUID_ADDRESS],
|
||||||
):
|
):
|
||||||
discovery_result = await hass.config_entries.flow.async_init(
|
discovery_result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user