Restore homekit_controller BLE broadcast_key from disk (#81211)
* Restore homekit_controller BLE broadcast_key from disk Some accessories will sleep for a long time and only send broadcasted events which makes them have very long connection intervals to save battery. Since we need to connect to get a new broadcast key we now save the broadcast key between restarts to ensure we can decrypt the advertisments coming in even though we cannot make a connection to the device during startup. When we get a disconnected event later we will try again to connect and the device will be awake which will trigger a full sync * bump bump
This commit is contained in:
parent
770aefbd52
commit
208150c353
5 changed files with 16 additions and 20 deletions
|
@ -3,7 +3,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, TypedDict
|
||||
from typing import Any
|
||||
|
||||
from aiohomekit.characteristic_cache import Pairing, StorageLayout
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.storage import Store
|
||||
|
@ -16,19 +18,6 @@ ENTITY_MAP_SAVE_DELAY = 10
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Pairing(TypedDict):
|
||||
"""A versioned map of entity metadata as presented by aiohomekit."""
|
||||
|
||||
config_num: int
|
||||
accessories: list[Any]
|
||||
|
||||
|
||||
class StorageLayout(TypedDict):
|
||||
"""Cached pairing metadata needed by aiohomekit."""
|
||||
|
||||
pairings: dict[str, Pairing]
|
||||
|
||||
|
||||
class EntityMapStorage:
|
||||
"""
|
||||
Holds a cache of entity structure data from a paired HomeKit device.
|
||||
|
@ -67,11 +56,17 @@ class EntityMapStorage:
|
|||
|
||||
@callback
|
||||
def async_create_or_update_map(
|
||||
self, homekit_id: str, config_num: int, accessories: list[Any]
|
||||
self,
|
||||
homekit_id: str,
|
||||
config_num: int,
|
||||
accessories: list[Any],
|
||||
broadcast_key: str | None = None,
|
||||
) -> Pairing:
|
||||
"""Create a new pairing cache."""
|
||||
_LOGGER.debug("Creating or updating entity map for %s", homekit_id)
|
||||
data = Pairing(config_num=config_num, accessories=accessories)
|
||||
data = Pairing(
|
||||
config_num=config_num, accessories=accessories, broadcast_key=broadcast_key
|
||||
)
|
||||
self.storage_data[homekit_id] = data
|
||||
self._async_schedule_save()
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue