Home Assistant Unofficial Reference 2024.12.1
store.py
Go to the documentation of this file.
1 """Local storage for the Local Calendar integration."""
2 
3 import asyncio
4 from pathlib import Path
5 
6 from homeassistant.core import HomeAssistant
7 
8 STORAGE_PATH = ".storage/{key}.ics"
9 
10 
12  """Local calendar storage."""
13 
14  def __init__(self, hass: HomeAssistant, path: Path) -> None:
15  """Initialize LocalCalendarStore."""
16  self._hass_hass = hass
17  self._path_path = path
18  self._lock_lock = asyncio.Lock()
19 
20  async def async_load(self) -> str:
21  """Load the calendar from disk."""
22  async with self._lock_lock:
23  return await self._hass_hass.async_add_executor_job(self._load_load)
24 
25  def _load(self) -> str:
26  """Load the calendar from disk."""
27  if not self._path_path.exists():
28  return ""
29  return self._path_path.read_text()
30 
31  async def async_store(self, ics_content: str) -> None:
32  """Persist the calendar to storage."""
33  async with self._lock_lock:
34  await self._hass_hass.async_add_executor_job(self._store_store, ics_content)
35 
36  def _store(self, ics_content: str) -> None:
37  """Persist the calendar to storage."""
38  self._path_path.write_text(ics_content)
None __init__(self, HomeAssistant hass, Path path)
Definition: store.py:14