mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add CalDAV upcoming appointments period option (#34584)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
2b5bb8dac0
commit
9871efd52f
@ -32,6 +32,7 @@ CONF_CALENDARS = "calendars"
|
||||
CONF_CUSTOM_CALENDARS = "custom_calendars"
|
||||
CONF_CALENDAR = "calendar"
|
||||
CONF_SEARCH = "search"
|
||||
CONF_DAYS = "days"
|
||||
|
||||
OFFSET = "!!"
|
||||
|
||||
@ -55,6 +56,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
],
|
||||
),
|
||||
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
|
||||
vol.Optional(CONF_DAYS, default=1): cv.positive_int,
|
||||
}
|
||||
)
|
||||
|
||||
@ -66,6 +68,7 @@ def setup_platform(hass, config, add_entities, disc_info=None):
|
||||
url = config[CONF_URL]
|
||||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
days = config[CONF_DAYS]
|
||||
|
||||
client = caldav.DAVClient(
|
||||
url, None, username, password, ssl_verify_cert=config[CONF_VERIFY_SSL]
|
||||
@ -92,7 +95,7 @@ def setup_platform(hass, config, add_entities, disc_info=None):
|
||||
entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
||||
calendar_devices.append(
|
||||
WebDavCalendarEventDevice(
|
||||
name, calendar, entity_id, True, cust_calendar[CONF_SEARCH]
|
||||
name, calendar, entity_id, days, True, cust_calendar[CONF_SEARCH]
|
||||
)
|
||||
)
|
||||
|
||||
@ -102,7 +105,7 @@ def setup_platform(hass, config, add_entities, disc_info=None):
|
||||
device_id = calendar.name
|
||||
entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
|
||||
calendar_devices.append(
|
||||
WebDavCalendarEventDevice(name, calendar, entity_id)
|
||||
WebDavCalendarEventDevice(name, calendar, entity_id, days)
|
||||
)
|
||||
|
||||
add_entities(calendar_devices, True)
|
||||
@ -111,9 +114,9 @@ def setup_platform(hass, config, add_entities, disc_info=None):
|
||||
class WebDavCalendarEventDevice(CalendarEventDevice):
|
||||
"""A device for getting the next Task from a WebDav Calendar."""
|
||||
|
||||
def __init__(self, name, calendar, entity_id, all_day=False, search=None):
|
||||
def __init__(self, name, calendar, entity_id, days, all_day=False, search=None):
|
||||
"""Create the WebDav Calendar Event Device."""
|
||||
self.data = WebDavCalendarData(calendar, all_day, search)
|
||||
self.data = WebDavCalendarData(calendar, days, all_day, search)
|
||||
self.entity_id = entity_id
|
||||
self._event = None
|
||||
self._name = name
|
||||
@ -153,9 +156,10 @@ class WebDavCalendarEventDevice(CalendarEventDevice):
|
||||
class WebDavCalendarData:
|
||||
"""Class to utilize the calendar dav client object to get next event."""
|
||||
|
||||
def __init__(self, calendar, include_all_day, search):
|
||||
def __init__(self, calendar, days, include_all_day, search):
|
||||
"""Set up how we are going to search the WebDav calendar."""
|
||||
self.calendar = calendar
|
||||
self.days = days
|
||||
self.include_all_day = include_all_day
|
||||
self.search = search
|
||||
self.event = None
|
||||
@ -192,7 +196,7 @@ class WebDavCalendarData:
|
||||
def update(self):
|
||||
"""Get the latest data."""
|
||||
start_of_today = dt.start_of_local_day()
|
||||
start_of_tomorrow = dt.start_of_local_day() + timedelta(days=1)
|
||||
start_of_tomorrow = dt.start_of_local_day() + timedelta(days=self.days)
|
||||
|
||||
# We have to retrieve the results for the whole day as the server
|
||||
# won't return events that have already started
|
||||
|
Loading…
x
Reference in New Issue
Block a user