2023-11-05 00:36:00 +00:00
|
|
|
"""Library for working with CalDAV api."""
|
|
|
|
|
|
|
|
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."""
|
2023-11-30 12:50:58 +00:00
|
|
|
|
|
|
|
def _get_calendars() -> list[caldav.Calendar]:
|
2024-03-03 02:53:51 +00:00
|
|
|
return [
|
|
|
|
calendar
|
|
|
|
for calendar in client.principal().calendars()
|
|
|
|
if component in calendar.get_supported_components()
|
2023-11-05 00:36:00 +00:00
|
|
|
]
|
2024-03-03 02:53:51 +00:00
|
|
|
|
|
|
|
return await hass.async_add_executor_job(_get_calendars)
|
2023-11-07 08:11:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|