mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Avoid call to hass.helpers.store
in LabelRegistry (#111555)
* Avoid call to `hass.helpers.store` in LabelRegistry * Change type annotation
This commit is contained in:
parent
773543b617
commit
070b411820
@ -10,6 +10,7 @@ from typing import Literal, TypedDict, cast
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
|
from .storage import Store
|
||||||
from .typing import UNDEFINED, EventType, UndefinedType
|
from .typing import UNDEFINED, EventType, UndefinedType
|
||||||
|
|
||||||
DATA_REGISTRY = "label_registry"
|
DATA_REGISTRY = "label_registry"
|
||||||
@ -96,7 +97,8 @@ class LabelRegistry:
|
|||||||
def __init__(self, hass: HomeAssistant) -> None:
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
"""Initialize the label registry."""
|
"""Initialize the label registry."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._store = hass.helpers.storage.Store(
|
self._store: Store[dict[str, list[dict[str, str | None]]]] = Store(
|
||||||
|
hass,
|
||||||
STORAGE_VERSION_MAJOR,
|
STORAGE_VERSION_MAJOR,
|
||||||
STORAGE_KEY,
|
STORAGE_KEY,
|
||||||
atomic_writes=True,
|
atomic_writes=True,
|
||||||
@ -230,6 +232,10 @@ class LabelRegistry:
|
|||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
for label in data["labels"]:
|
for label in data["labels"]:
|
||||||
|
# Check if the necessary keys are present
|
||||||
|
if label["label_id"] is None or label["name"] is None:
|
||||||
|
continue
|
||||||
|
|
||||||
normalized_name = _normalize_label_name(label["name"])
|
normalized_name = _normalize_label_name(label["name"])
|
||||||
labels[label["label_id"]] = LabelEntry(
|
labels[label["label_id"]] = LabelEntry(
|
||||||
color=label["color"],
|
color=label["color"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user