1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-12 17:18:04 +01:00

Migrate esphome to use HassKey (#168873)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
epenet
2026-04-27 14:16:29 +02:00
committed by GitHub
parent 54727a6f20
commit 5d98f467fb
2 changed files with 14 additions and 8 deletions
+10 -1
View File
@@ -1,11 +1,20 @@
"""ESPHome constants."""
from typing import Final
from __future__ import annotations
from typing import TYPE_CHECKING, Final
from awesomeversion import AwesomeVersion
from homeassistant.util.hass_dict import HassKey
if TYPE_CHECKING:
from .domain_data import DomainData
DOMAIN = "esphome"
ESPHOME_DATA: HassKey[DomainData] = HassKey(DOMAIN)
CONF_ALLOW_SERVICE_CALLS = "allow_service_calls"
CONF_SUBSCRIBE_LOGS = "subscribe_logs"
CONF_DEVICE_NAME = "device_name"
@@ -4,12 +4,11 @@ from __future__ import annotations
from dataclasses import dataclass, field
from functools import cache
from typing import Self
from homeassistant.core import HomeAssistant
from homeassistant.helpers.json import JSONEncoder
from .const import DOMAIN
from .const import ESPHOME_DATA
from .entry_data import ESPHomeConfigEntry, ESPHomeStorage, RuntimeEntryData
STORAGE_VERSION = 1
@@ -36,11 +35,9 @@ class DomainData:
),
)
@classmethod
@staticmethod
@cache
def get(cls, hass: HomeAssistant) -> Self:
def get(hass: HomeAssistant) -> DomainData:
"""Get the global DomainData instance stored in hass.data."""
# Uses legacy hass.data[DOMAIN] pattern
# pylint: disable-next=hass-use-runtime-data
ret = hass.data[DOMAIN] = cls()
ret = hass.data[ESPHOME_DATA] = DomainData()
return ret