Refactor the core config store (#80457)
* Add helper for config Store * Use internal class
This commit is contained in:
parent
d49a223a02
commit
bbb0b2a0e1
1 changed files with 19 additions and 22 deletions
|
@ -1962,17 +1962,7 @@ class Config:
|
||||||
|
|
||||||
async def async_load(self) -> None:
|
async def async_load(self) -> None:
|
||||||
"""Load [homeassistant] core config."""
|
"""Load [homeassistant] core config."""
|
||||||
# Circular dep
|
store = self._ConfigStore(self.hass)
|
||||||
# pylint: disable=import-outside-toplevel
|
|
||||||
from .helpers.storage import Store
|
|
||||||
|
|
||||||
store = Store[dict[str, Any]](
|
|
||||||
self.hass,
|
|
||||||
CORE_STORAGE_VERSION,
|
|
||||||
CORE_STORAGE_KEY,
|
|
||||||
private=True,
|
|
||||||
atomic_writes=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not (data := await store.async_load()):
|
if not (data := await store.async_load()):
|
||||||
return
|
return
|
||||||
|
@ -2006,10 +1996,6 @@ class Config:
|
||||||
|
|
||||||
async def async_store(self) -> None:
|
async def async_store(self) -> None:
|
||||||
"""Store [homeassistant] core config."""
|
"""Store [homeassistant] core config."""
|
||||||
# Circular dep
|
|
||||||
# pylint: disable=import-outside-toplevel
|
|
||||||
from .helpers.storage import Store
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"latitude": self.latitude,
|
"latitude": self.latitude,
|
||||||
"longitude": self.longitude,
|
"longitude": self.longitude,
|
||||||
|
@ -2024,11 +2010,22 @@ class Config:
|
||||||
"currency": self.currency,
|
"currency": self.currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
store: Store[dict[str, Any]] = Store(
|
store = self._ConfigStore(self.hass)
|
||||||
self.hass,
|
|
||||||
CORE_STORAGE_VERSION,
|
|
||||||
CORE_STORAGE_KEY,
|
|
||||||
private=True,
|
|
||||||
atomic_writes=True,
|
|
||||||
)
|
|
||||||
await store.async_save(data)
|
await store.async_save(data)
|
||||||
|
|
||||||
|
# Circular dependency prevents us from generating the class at top level
|
||||||
|
# pylint: disable-next=import-outside-toplevel
|
||||||
|
from .helpers.storage import Store
|
||||||
|
|
||||||
|
class _ConfigStore(Store[dict[str, Any]]):
|
||||||
|
"""Class to help storing Config data."""
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
|
"""Initialize storage class."""
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
CORE_STORAGE_VERSION,
|
||||||
|
CORE_STORAGE_KEY,
|
||||||
|
private=True,
|
||||||
|
atomic_writes=True,
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue