Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add google calendar max_results config option #21874

Merged
2 changes: 2 additions & 0 deletions homeassistant/components/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CONF_SEARCH = 'search'
CONF_OFFSET = 'offset'
CONF_IGNORE_AVAILABILITY = 'ignore_availability'
CONF_MAX_RESULTS = 'max_results'

DEFAULT_CONF_TRACK_NEW = True
DEFAULT_CONF_OFFSET = '!!'
Expand Down Expand Up @@ -69,6 +70,7 @@
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({
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/google/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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__)

Expand Down Expand Up @@ -41,7 +41,8 @@ def __init__(self, hass, calendar_service, calendar, data):
"""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)

Expand All @@ -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
rohankapoorcom marked this conversation as resolved.
Show resolved Hide resolved
self.event = None

def _prepare_query(self):
Expand All @@ -73,6 +75,8 @@ def _prepare_query(self):
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

Expand Down