mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add google calendar max_results config option (#21874)
* Added max_results config capability to google calendar (people are creating custom components just to override that) * Dummy commit * Dummy commit 2 * Changed to positive_int * Removed double imports
This commit is contained in:
parent
01052f516b
commit
e14dbfb006
@ -36,6 +36,7 @@ CONF_TRACK = 'track'
|
||||
CONF_SEARCH = 'search'
|
||||
CONF_OFFSET = 'offset'
|
||||
CONF_IGNORE_AVAILABILITY = 'ignore_availability'
|
||||
CONF_MAX_RESULTS = 'max_results'
|
||||
|
||||
DEFAULT_CONF_TRACK_NEW = True
|
||||
DEFAULT_CONF_OFFSET = '!!'
|
||||
@ -69,6 +70,7 @@ _SINGLE_CALSEARCH_CONFIG = vol.Schema({
|
||||
vol.Optional(CONF_OFFSET): cv.string,
|
||||
vol.Optional(CONF_SEARCH): cv.string,
|
||||
vol.Optional(CONF_TRACK): cv.boolean,
|
||||
vol.Optional(CONF_MAX_RESULTS): cv.positive_int,
|
||||
})
|
||||
|
||||
DEVICE_SCHEMA = vol.Schema({
|
||||
|
@ -7,7 +7,7 @@ from homeassistant.util import Throttle, dt
|
||||
|
||||
from . import (
|
||||
CONF_CAL_ID, CONF_ENTITIES, CONF_IGNORE_AVAILABILITY, CONF_SEARCH,
|
||||
CONF_TRACK, TOKEN_FILE, GoogleCalendarService)
|
||||
CONF_TRACK, TOKEN_FILE, CONF_MAX_RESULTS, GoogleCalendarService)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -41,7 +41,8 @@ class GoogleCalendarEventDevice(CalendarEventDevice):
|
||||
"""Create the Calendar event device."""
|
||||
self.data = GoogleCalendarData(calendar_service, calendar,
|
||||
data.get(CONF_SEARCH),
|
||||
data.get(CONF_IGNORE_AVAILABILITY))
|
||||
data.get(CONF_IGNORE_AVAILABILITY),
|
||||
data.get(CONF_MAX_RESULTS))
|
||||
|
||||
super().__init__(hass, data)
|
||||
|
||||
@ -54,12 +55,13 @@ class GoogleCalendarData:
|
||||
"""Class to utilize calendar service object to get next event."""
|
||||
|
||||
def __init__(self, calendar_service, calendar_id, search,
|
||||
ignore_availability):
|
||||
ignore_availability, max_results):
|
||||
"""Set up how we are going to search the google calendar."""
|
||||
self.calendar_service = calendar_service
|
||||
self.calendar_id = calendar_id
|
||||
self.search = search
|
||||
self.ignore_availability = ignore_availability
|
||||
self.max_results = max_results
|
||||
self.event = None
|
||||
|
||||
def _prepare_query(self):
|
||||
@ -73,6 +75,8 @@ class GoogleCalendarData:
|
||||
return False
|
||||
params = dict(DEFAULT_GOOGLE_SEARCH_PARAMS)
|
||||
params['calendarId'] = self.calendar_id
|
||||
if self.max_results:
|
||||
params['max_results'] = self.max_results
|
||||
if self.search:
|
||||
params['q'] = self.search
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user