* Add Caldav todo enttiy for VTODO components * Use new shared apis for todos * Update homeassistant/components/caldav/todo.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update todo item conversion checks * Iterate over results once * Add 15 minute poll interval for caldav todo --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
32 lines
993 B
Python
32 lines
993 B
Python
"""Library for working with CalDAV api."""
|
|
|
|
import asyncio
|
|
|
|
import caldav
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
async def async_get_calendars(
|
|
hass: HomeAssistant, client: caldav.DAVClient, component: str
|
|
) -> list[caldav.Calendar]:
|
|
"""Get all calendars that support the specified component."""
|
|
calendars = await hass.async_add_executor_job(client.principal().calendars)
|
|
components_results = await asyncio.gather(
|
|
*[
|
|
hass.async_add_executor_job(calendar.get_supported_components)
|
|
for calendar in calendars
|
|
]
|
|
)
|
|
return [
|
|
calendar
|
|
for calendar, supported_components in zip(calendars, components_results)
|
|
if component in supported_components
|
|
]
|
|
|
|
|
|
def get_attr_value(obj: caldav.CalendarObjectResource, attribute: str) -> str | None:
|
|
"""Return the value of the CalDav object attribute if defined."""
|
|
if hasattr(obj, attribute):
|
|
return getattr(obj, attribute).value
|
|
return None
|