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