Make Store a generic class (#74617)
This commit is contained in:
parent
d37ad20894
commit
16900dcef1
27 changed files with 106 additions and 97 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, TypedDict, cast
|
||||
from typing import Any, TypedDict
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.storage import Store
|
||||
|
@ -46,7 +46,9 @@ class EntityMapStorage:
|
|||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
"""Create a new entity map store."""
|
||||
self.hass = hass
|
||||
self.store = Store(hass, ENTITY_MAP_STORAGE_VERSION, ENTITY_MAP_STORAGE_KEY)
|
||||
self.store = Store[StorageLayout](
|
||||
hass, ENTITY_MAP_STORAGE_VERSION, ENTITY_MAP_STORAGE_KEY
|
||||
)
|
||||
self.storage_data: dict[str, Pairing] = {}
|
||||
|
||||
async def async_initialize(self) -> None:
|
||||
|
@ -55,8 +57,7 @@ class EntityMapStorage:
|
|||
# There is no cached data about HomeKit devices yet
|
||||
return
|
||||
|
||||
storage = cast(StorageLayout, raw_storage)
|
||||
self.storage_data = storage.get("pairings", {})
|
||||
self.storage_data = raw_storage.get("pairings", {})
|
||||
|
||||
def get_map(self, homekit_id: str) -> Pairing | None:
|
||||
"""Get a pairing cache item."""
|
||||
|
@ -87,6 +88,6 @@ class EntityMapStorage:
|
|||
self.store.async_delay_save(self._data_to_save, ENTITY_MAP_SAVE_DELAY)
|
||||
|
||||
@callback
|
||||
def _data_to_save(self) -> dict[str, Any]:
|
||||
def _data_to_save(self) -> StorageLayout:
|
||||
"""Return data of entity map to store in a file."""
|
||||
return {"pairings": self.storage_data}
|
||||
return StorageLayout(pairings=self.storage_data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue