From 0a83160f25ebaba116a4146bd2a84aa200cc0d98 Mon Sep 17 00:00:00 2001 From: Yosi Levy Date: Sat, 9 Mar 2019 20:18:59 +0200 Subject: [PATCH 1/5] Added max_results config capability to google calendar (people are creating custom components just to override that) --- 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 8fba016df57a4a..1bdc3edb7497aa 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.string, }) DEVICE_SCHEMA = vol.Schema({ diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index cc65c6d655d3ed..0db08e71b54d66 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -5,7 +5,7 @@ from homeassistant.components.calendar import CalendarEventDevice from homeassistant.components.google import ( CONF_CAL_ID, CONF_ENTITIES, CONF_TRACK, TOKEN_FILE, - CONF_IGNORE_AVAILABILITY, CONF_SEARCH, + CONF_IGNORE_AVAILABILITY, CONF_SEARCH, CONF_MAX_RESULTS, GoogleCalendarService) from homeassistant.util import Throttle, dt @@ -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 From f4c11cd57933ac6708a1474e49315bb5ab03d462 Mon Sep 17 00:00:00 2001 From: Yosi Levy Date: Mon, 11 Mar 2019 14:39:43 +0200 Subject: [PATCH 2/5] Dummy commit --- homeassistant/components/google/calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index 0db08e71b54d66..6764b649677461 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -51,7 +51,7 @@ async def async_get_events(self, hass, start_date, end_date): return await self.data.async_get_events(hass, start_date, end_date) -class GoogleCalendarData: +class GoogleCalendarData: """Class to utilize calendar service object to get next event.""" def __init__(self, calendar_service, calendar_id, search, From 9afeee61d7d19b0c27c25015359c3f5c2f8535df Mon Sep 17 00:00:00 2001 From: Yosi Levy Date: Mon, 11 Mar 2019 14:40:06 +0200 Subject: [PATCH 3/5] Dummy commit 2 --- homeassistant/components/google/calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index 6764b649677461..0db08e71b54d66 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -51,7 +51,7 @@ async def async_get_events(self, hass, start_date, end_date): return await self.data.async_get_events(hass, start_date, end_date) -class GoogleCalendarData: +class GoogleCalendarData: """Class to utilize calendar service object to get next event.""" def __init__(self, calendar_service, calendar_id, search, From d54efd31e1c41908bf40f3542134eefbe5e1897c Mon Sep 17 00:00:00 2001 From: Yosi Levy Date: Wed, 13 Mar 2019 06:32:40 +0200 Subject: [PATCH 4/5] Changed to positive_int --- homeassistant/components/google/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index 1bdc3edb7497aa..37ee5efbd93b81 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -70,7 +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.string, + vol.Optional(CONF_MAX_RESULTS): cv.positive_int, }) DEVICE_SCHEMA = vol.Schema({ From 7bd9a2e9bfc604ed448c8dcf332101535a2f9fd1 Mon Sep 17 00:00:00 2001 From: Yosi Levy Date: Thu, 28 Mar 2019 05:08:32 +0200 Subject: [PATCH 5/5] Removed double imports --- homeassistant/components/google/calendar.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index a7e4a08fd91a52..36ab3459d5cbd8 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -3,15 +3,11 @@ import logging from homeassistant.components.calendar import CalendarEventDevice -from homeassistant.components.google import ( - CONF_CAL_ID, CONF_ENTITIES, CONF_TRACK, TOKEN_FILE, - CONF_IGNORE_AVAILABILITY, CONF_SEARCH, CONF_MAX_RESULTS, - GoogleCalendarService) 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__)