Avoid call to hass.helpers.store in FloorRegistry (#111554)

* Avoid call to `hass.helpers.store` in FloorRegistry

* Change type annotation
This commit is contained in:
Jan-Philipp Benecke 2024-02-27 23:03:28 +01:00 committed by GitHub
parent cf849664ba
commit c8b7f098e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,11 +5,12 @@ from collections import UserDict
from collections.abc import Iterable, ValuesView
import dataclasses
from dataclasses import dataclass
from typing import Literal, TypedDict, cast
from typing import TYPE_CHECKING, Literal, TypedDict, cast
from homeassistant.core import HomeAssistant, callback
from homeassistant.util import slugify
from .storage import Store
from .typing import UNDEFINED, EventType, UndefinedType
DATA_REGISTRY = "floor_registry"
@ -96,7 +97,10 @@ class FloorRegistry:
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize the floor registry."""
self.hass = hass
self._store = hass.helpers.storage.Store(
self._store: Store[
dict[str, list[dict[str, str | int | list[str] | None]]]
] = Store(
hass,
STORAGE_VERSION_MAJOR,
STORAGE_KEY,
atomic_writes=True,
@ -229,6 +233,13 @@ class FloorRegistry:
if data is not None:
for floor in data["floors"]:
if TYPE_CHECKING:
assert isinstance(floor["aliases"], list)
assert isinstance(floor["icon"], str)
assert isinstance(floor["level"], int)
assert isinstance(floor["name"], str)
assert isinstance(floor["floor_id"], str)
normalized_name = _normalize_floor_name(floor["name"])
floors[floor["floor_id"]] = FloorEntry(
aliases=set(floor["aliases"]),