1 """Support for WebDav Calendar."""
3 from __future__
import annotations
5 from datetime
import datetime
9 import voluptuous
as vol
13 PLATFORM_SCHEMA
as CALENDAR_PLATFORM_SCHEMA,
32 from .
import CalDavConfigEntry
33 from .api
import async_get_calendars
34 from .coordinator
import CalDavUpdateCoordinator
36 _LOGGER = logging.getLogger(__name__)
38 CONF_CALENDARS =
"calendars"
39 CONF_CUSTOM_CALENDARS =
"custom_calendars"
40 CONF_CALENDAR =
"calendar"
41 CONF_SEARCH =
"search"
45 CONFIG_ENTRY_DEFAULT_DAYS = 7
48 SUPPORTED_COMPONENT =
"VEVENT"
50 PLATFORM_SCHEMA = CALENDAR_PLATFORM_SCHEMA.extend(
52 vol.Required(CONF_URL): vol.Url(),
53 vol.Optional(CONF_CALENDARS, default=[]): vol.All(cv.ensure_list, [cv.string]),
54 vol.Inclusive(CONF_USERNAME,
"authentication"): cv.string,
55 vol.Inclusive(CONF_PASSWORD,
"authentication"): cv.string,
56 vol.Optional(CONF_CUSTOM_CALENDARS, default=[]): vol.All(
61 vol.Required(CONF_CALENDAR): cv.string,
62 vol.Required(CONF_NAME): cv.string,
63 vol.Required(CONF_SEARCH): cv.string,
68 vol.Optional(CONF_VERIFY_SSL, default=
True): cv.boolean,
69 vol.Optional(CONF_DAYS, default=1): cv.positive_int,
77 async_add_entities: AddEntitiesCallback,
78 disc_info: DiscoveryInfoType |
None =
None,
80 """Set up the WebDav Calendar platform."""
81 url = config[CONF_URL]
82 username = config.get(CONF_USERNAME)
83 password = config.get(CONF_PASSWORD)
84 days = config[CONF_DAYS]
86 client = caldav.DAVClient(
87 url,
None, username, password, ssl_verify_cert=config[CONF_VERIFY_SSL]
94 for calendar
in list(calendars):
97 if config[CONF_CALENDARS]
and calendar.name
not in config[CONF_CALENDARS]:
98 _LOGGER.debug(
"Ignoring calendar '%s'", calendar.name)
102 for cust_calendar
in config[CONF_CUSTOM_CALENDARS]:
104 if cust_calendar[CONF_CALENDAR] != calendar.name:
107 name = cust_calendar[CONF_NAME]
108 device_id = f
"{cust_calendar[CONF_CALENDAR]} {cust_calendar[CONF_NAME]}"
115 include_all_day=
True,
116 search=cust_calendar[CONF_SEARCH],
124 if not config[CONF_CUSTOM_CALENDARS]:
126 device_id = calendar.name
133 include_all_day=
False,
145 entry: CalDavConfigEntry,
146 async_add_entities: AddEntitiesCallback,
148 """Set up the CalDav calendar platform for a config entry."""
159 days=CONFIG_ENTRY_DEFAULT_DAYS,
160 include_all_day=
True,
163 unique_id=f
"{entry.entry_id}-{calendar.id}",
165 for calendar
in calendars
173 """A device for getting the next Task from a WebDav Calendar."""
179 coordinator: CalDavUpdateCoordinator,
180 unique_id: str |
None =
None,
181 supports_offset: bool =
False,
183 """Create the WebDav Calendar Event Device."""
186 self.
_event_event: CalendarEvent |
None =
None
188 if unique_id
is not None:
193 def event(self) -> CalendarEvent | None:
194 """Return the next upcoming event."""
198 self, hass: HomeAssistant, start_date: datetime, end_date: datetime
199 ) -> list[CalendarEvent]:
200 """Get all events in a specific time frame."""
205 """Update event data."""
206 self.
_event_event = self.coordinator.data
210 self.
_event_event.start_datetime_local,
211 self.coordinator.offset,
219 """When entity is added to hass update state from existing coordinator data."""
None __init__(self, str name, str entity_id, CalDavUpdateCoordinator coordinator, str|None unique_id=None, bool supports_offset=False)
CalendarEvent|None event(self)
list[CalendarEvent] async_get_events(self, HomeAssistant hass, datetime start_date, datetime end_date)
None _handle_coordinator_update(self)
None async_added_to_hass(self)
_attr_extra_state_attributes
list[caldav.Calendar] async_get_calendars(HomeAssistant hass, caldav.DAVClient client, str component)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None disc_info=None)
None async_setup_entry(HomeAssistant hass, CalDavConfigEntry entry, AddEntitiesCallback async_add_entities)
bool is_offset_reached(datetime.datetime start, datetime.timedelta offset_time)
str async_generate_entity_id(str entity_id_format, str|None name, Iterable[str]|None current_ids=None, HomeAssistant|None hass=None)