Fix yale access bluetooth locks delaying startup when key changes (#83024)
If the keys changed for the yale locks, the locks would be slow to setup. Because august had yalexs_ble as an after dep, it would be waiting with the new keys but not able to setup because it was waiting for the locks to setup which would be trying over and over until they failed because the key had changed out from under it. This change moves some more code into the lib to avoid the dep and allows both to startup at the same time so the cloud service can feed the new keys in if needed without waiting for the lock to fail to setup changelog: https://github.com/bdraco/yalexs-ble/compare/v1.9.8...v1.10.0
This commit is contained in:
parent
4bef6ac191
commit
c91417e71f
7 changed files with 22 additions and 37 deletions
|
@ -12,9 +12,9 @@ from yalexs.exceptions import AugustApiAIOHTTPError
|
|||
from yalexs.lock import Lock, LockDetail
|
||||
from yalexs.pubnub_activity import activities_from_pubnub_message
|
||||
from yalexs.pubnub_async import AugustPubNub, async_create_pubnub
|
||||
from yalexs_ble import YaleXSBLEDiscovery
|
||||
|
||||
from homeassistant.components import yalexs_ble
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import (
|
||||
|
@ -22,7 +22,7 @@ from homeassistant.exceptions import (
|
|||
ConfigEntryNotReady,
|
||||
HomeAssistantError,
|
||||
)
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, discovery_flow
|
||||
|
||||
from .activity import ActivityStream
|
||||
from .const import DOMAIN, MIN_TIME_BETWEEN_DETAIL_UPDATES, PLATFORMS
|
||||
|
@ -38,6 +38,7 @@ API_CACHED_ATTRS = {
|
|||
"lock_status",
|
||||
"lock_status_datetime",
|
||||
}
|
||||
YALEXS_BLE_DOMAIN = "yalexs_ble"
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
@ -100,9 +101,11 @@ def _async_trigger_ble_lock_discovery(
|
|||
):
|
||||
"""Update keys for the yalexs-ble integration if available."""
|
||||
for lock_detail in locks_with_offline_keys:
|
||||
yalexs_ble.async_discovery(
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
yalexs_ble.YaleXSBLEDiscovery(
|
||||
YALEXS_BLE_DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=YaleXSBLEDiscovery(
|
||||
{
|
||||
"name": lock_detail.device_name,
|
||||
"address": lock_detail.mac_address,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"domain": "august",
|
||||
"name": "August",
|
||||
"documentation": "https://www.home-assistant.io/integrations/august",
|
||||
"requirements": ["yalexs==1.2.6"],
|
||||
"requirements": ["yalexs==1.2.6", "yalexs_ble==1.10.0"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"dhcp": [
|
||||
{
|
||||
|
@ -24,6 +24,5 @@
|
|||
],
|
||||
"config_flow": true,
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["pubnub", "yalexs"],
|
||||
"after_dependencies": ["yalexs_ble"]
|
||||
"loggers": ["pubnub", "yalexs"]
|
||||
}
|
||||
|
|
|
@ -2,17 +2,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import TypedDict
|
||||
|
||||
import async_timeout
|
||||
from yalexs_ble import PushLock, local_name_is_unique
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ADDRESS, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import discovery_flow
|
||||
|
||||
from .const import CONF_KEY, CONF_LOCAL_NAME, CONF_SLOT, DEVICE_TIMEOUT, DOMAIN
|
||||
from .models import YaleXSBLEData
|
||||
|
@ -21,27 +19,6 @@ from .util import async_find_existing_service_info, bluetooth_callback_matcher
|
|||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.LOCK, Platform.SENSOR]
|
||||
|
||||
|
||||
class YaleXSBLEDiscovery(TypedDict):
|
||||
"""A validated discovery of a Yale XS BLE device."""
|
||||
|
||||
name: str
|
||||
address: str
|
||||
serial: str
|
||||
key: str
|
||||
slot: int
|
||||
|
||||
|
||||
@callback
|
||||
def async_discovery(hass: HomeAssistant, discovery: YaleXSBLEDiscovery) -> None:
|
||||
"""Update keys for the yalexs-ble integration if available."""
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_INTEGRATION_DISCOVERY},
|
||||
data=discovery,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Yale Access Bluetooth from a config entry."""
|
||||
local_name = entry.data[CONF_LOCAL_NAME]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Yale Access Bluetooth",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/yalexs_ble",
|
||||
"requirements": ["yalexs-ble==1.9.8"],
|
||||
"requirements": ["yalexs-ble==1.10.0"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"bluetooth": [
|
||||
|
|
|
@ -2603,11 +2603,14 @@ xs1-api-client==3.0.0
|
|||
yalesmartalarmclient==0.3.9
|
||||
|
||||
# homeassistant.components.yalexs_ble
|
||||
yalexs-ble==1.9.8
|
||||
yalexs-ble==1.10.0
|
||||
|
||||
# homeassistant.components.august
|
||||
yalexs==1.2.6
|
||||
|
||||
# homeassistant.components.august
|
||||
yalexs_ble==1.10.0
|
||||
|
||||
# homeassistant.components.yeelight
|
||||
yeelight==0.7.10
|
||||
|
||||
|
|
|
@ -1813,11 +1813,14 @@ xmltodict==0.13.0
|
|||
yalesmartalarmclient==0.3.9
|
||||
|
||||
# homeassistant.components.yalexs_ble
|
||||
yalexs-ble==1.9.8
|
||||
yalexs-ble==1.10.0
|
||||
|
||||
# homeassistant.components.august
|
||||
yalexs==1.2.6
|
||||
|
||||
# homeassistant.components.august
|
||||
yalexs_ble==1.10.0
|
||||
|
||||
# homeassistant.components.yeelight
|
||||
yeelight==0.7.10
|
||||
|
||||
|
|
|
@ -332,7 +332,7 @@ async def test_load_triggers_ble_discovery(hass):
|
|||
august_lock_without_key = await _mock_operative_august_lock_detail(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.august.yalexs_ble.async_discovery"
|
||||
"homeassistant.components.august.discovery_flow.async_create_flow"
|
||||
) as mock_discovery:
|
||||
config_entry = await _create_august_with_devices(
|
||||
hass, [august_lock_with_key, august_lock_without_key]
|
||||
|
@ -341,7 +341,7 @@ async def test_load_triggers_ble_discovery(hass):
|
|||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert len(mock_discovery.mock_calls) == 1
|
||||
assert mock_discovery.mock_calls[0][1][1] == {
|
||||
assert mock_discovery.mock_calls[0].kwargs["data"] == {
|
||||
"name": "Front Door Lock",
|
||||
"address": None,
|
||||
"serial": "X2FSW05DGA",
|
||||
|
|
Loading…
Add table
Reference in a new issue