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:
Allen Porter 2023-10-25 04:21:10 -07:00 committed by GitHub
parent 35d18a9a3e
commit 476e867fe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 962 additions and 0 deletions

View 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)