Home Assistant Unofficial Reference 2024.12.1
api.py
Go to the documentation of this file.
1 """Library for working with CalDAV api."""
2 
3 import caldav
4 
5 from homeassistant.core import HomeAssistant
6 
7 
9  hass: HomeAssistant, client: caldav.DAVClient, component: str
10 ) -> list[caldav.Calendar]:
11  """Get all calendars that support the specified component."""
12 
13  def _get_calendars() -> list[caldav.Calendar]:
14  return [
15  calendar
16  for calendar in client.principal().calendars()
17  if component in calendar.get_supported_components()
18  ]
19 
20  return await hass.async_add_executor_job(_get_calendars)
21 
22 
23 def get_attr_value(obj: caldav.CalendarObjectResource, attribute: str) -> str | None:
24  """Return the value of the CalDav object attribute if defined."""
25  if hasattr(obj, attribute):
26  return getattr(obj, attribute).value
27  return None
list[caldav.Calendar] async_get_calendars(HomeAssistant hass, caldav.DAVClient client, str component)
Definition: api.py:10
str|None get_attr_value(caldav.CalendarObjectResource obj, str attribute)
Definition: api.py:23