1 """Support for esphome domain data."""
3 from __future__
import annotations
5 from dataclasses
import dataclass, field
6 from functools
import cache
7 from typing
import Self
9 from bleak_esphome.backend.cache
import ESPHomeBluetoothCache
14 from .const
import DOMAIN
15 from .entry_data
import ESPHomeConfigEntry, ESPHomeStorage, RuntimeEntryData
20 @dataclass(slots=True)
22 """Define a class that stores global esphome data in hass.data[DOMAIN]."""
24 _stores: dict[str, ESPHomeStorage] = field(default_factory=dict)
25 bluetooth_cache: ESPHomeBluetoothCache = field(
26 default_factory=ESPHomeBluetoothCache
30 """Return the runtime entry data associated with this config entry.
32 Raises KeyError if the entry isn't loaded yet.
34 return entry.runtime_data
37 self, hass: HomeAssistant, entry: ESPHomeConfigEntry
39 """Get or create a Store instance for the given config entry."""
40 return self._stores.setdefault(
43 hass, STORAGE_VERSION, f
"esphome.{entry.entry_id}", encoder=JSONEncoder
49 def get(cls, hass: HomeAssistant) -> Self:
50 """Get the global DomainData instance stored in hass.data."""
51 ret = hass.data[DOMAIN] = cls()
ESPHomeStorage get_or_create_store(self, HomeAssistant hass, ESPHomeConfigEntry entry)
RuntimeEntryData get_entry_data(self, ESPHomeConfigEntry entry)
Self get(cls, HomeAssistant hass)