Avoid yalexs_ble delaying startup when the lock is not advertising (#111167)

This commit is contained in:
J. Nick Koston 2024-02-23 08:35:17 -10:00 committed by GitHub
parent b6b5b1f788
commit b9ed315cf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,7 @@ from yalexs_ble import (
from homeassistant.components import bluetooth
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ADDRESS, EVENT_HOMEASSISTANT_STOP, Platform
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
from homeassistant.core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from .const import (
@ -73,6 +73,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# We may already have the advertisement, so check for it.
if service_info := async_find_existing_service_info(hass, local_name, address):
push_lock.update_advertisement(service_info.device, service_info.advertisement)
elif hass.state is CoreState.starting:
# If we are starting and the advertisement is not found, do not delay
# the setup. We will wait for the advertisement to be found and then
# discovery will trigger setup retry.
raise ConfigEntryNotReady("{local_name} ({address}) not advertising yet")
entry.async_on_unload(
bluetooth.async_register_callback(