Restore accessory state into pairing using new HKC methods (#75276)

This commit is contained in:
J. Nick Koston 2022-07-16 12:49:15 -05:00 committed by GitHub
parent ecc219fbc1
commit b9c8d65940
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 130 additions and 91 deletions

View file

@ -7,7 +7,7 @@ from typing import Any, TypedDict
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.storage import Store
from .const import DOMAIN
from .const import DOMAIN, ENTITY_MAP
ENTITY_MAP_STORAGE_KEY = f"{DOMAIN}-entity-map"
ENTITY_MAP_STORAGE_VERSION = 1
@ -91,3 +91,13 @@ class EntityMapStorage:
def _data_to_save(self) -> StorageLayout:
"""Return data of entity map to store in a file."""
return StorageLayout(pairings=self.storage_data)
async def async_get_entity_storage(hass: HomeAssistant) -> EntityMapStorage:
"""Get entity storage."""
if ENTITY_MAP in hass.data:
map_storage: EntityMapStorage = hass.data[ENTITY_MAP]
return map_storage
map_storage = hass.data[ENTITY_MAP] = EntityMapStorage(hass)
await map_storage.async_initialize()
return map_storage