Add a Local To-do component (#102627)
Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
35d18a9a3e
commit
476e867fe8
20 changed files with 962 additions and 0 deletions
36
homeassistant/components/local_todo/store.py
Normal file
36
homeassistant/components/local_todo/store.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
"""Local storage for the Local To-do integration."""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
class LocalTodoListStore:
|
||||
"""Local storage for a single To-do list."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, path: Path) -> None:
|
||||
"""Initialize LocalTodoListStore."""
|
||||
self._hass = hass
|
||||
self._path = path
|
||||
self._lock = asyncio.Lock()
|
||||
|
||||
async def async_load(self) -> str:
|
||||
"""Load the calendar from disk."""
|
||||
async with self._lock:
|
||||
return await self._hass.async_add_executor_job(self._load)
|
||||
|
||||
def _load(self) -> str:
|
||||
"""Load the calendar from disk."""
|
||||
if not self._path.exists():
|
||||
return ""
|
||||
return self._path.read_text()
|
||||
|
||||
async def async_store(self, ics_content: str) -> None:
|
||||
"""Persist the calendar to storage."""
|
||||
async with self._lock:
|
||||
await self._hass.async_add_executor_job(self._store, ics_content)
|
||||
|
||||
def _store(self, ics_content: str) -> None:
|
||||
"""Persist the calendar to storage."""
|
||||
self._path.write_text(ics_content)
|
Loading…
Add table
Add a link
Reference in a new issue