diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index 8fba016df57a4..37ee5efbd93b8 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -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 = '!!' @@ -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({ diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index 9f71e7c4f2036..36ab3459d5cbd 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -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__) @@ -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) @@ -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 @@ 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