From e14dbfb006a96cdac47495a7c866a1fbb2d014ee Mon Sep 17 00:00:00 2001 From: yosilevy <37745463+yosilevy@users.noreply.github.com> Date: Fri, 29 Mar 2019 05:56:12 +0300 Subject: [PATCH] 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 --- homeassistant/components/google/__init__.py | 2 ++ homeassistant/components/google/calendar.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index 8fba016df57..37ee5efbd93 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -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({ diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index 9f71e7c4f20..36ab3459d5c 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -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