From bfdb51a55861df96c9760ddb3b1074d74870428c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 28 May 2016 10:37:22 -0700 Subject: [PATCH] Bugfixes for urls with dates --- .../frontend/www_static/home-assistant-polymer | 2 +- homeassistant/components/history.py | 13 +++---------- homeassistant/components/http.py | 4 ++-- homeassistant/components/logbook.py | 8 +------- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index 0be98873d70..4f8e2d56875 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit 0be98873d7044f387645f3a694e41660be663b66 +Subproject commit 4f8e2d568755fdb7c4eb61ca13533665202dbd23 diff --git a/homeassistant/components/history.py b/homeassistant/components/history.py index 7ede33f9e15..849204e947d 100644 --- a/homeassistant/components/history.py +++ b/homeassistant/components/history.py @@ -177,26 +177,19 @@ class HistoryPeriodView(HomeAssistantView): """Handle history period requests.""" url = '/api/history/period' - name = 'api:history:entity-recent-states' + name = 'api:history:view-period' extra_urls = ['/api/history/period/'] def get(self, request, date=None): """Return history over a period of time.""" - one_day = timedelta(seconds=86400) + one_day = timedelta(days=1) if date: - start_date = dt_util.parse_date(date) - - if start_date is None: - return self.json_message('Error parsing JSON', - HTTP_BAD_REQUEST) - - start_time = dt_util.as_utc(dt_util.start_of_local_day(start_date)) + start_time = dt_util.as_utc(dt_util.start_of_local_day(date)) else: start_time = dt_util.utcnow() - one_day end_time = start_time + one_day - entity_id = request.args.get('filter_entity_id') return self.json( diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index b431cef22bf..ae7fa238069 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -148,13 +148,13 @@ def routing_map(hass): class DateValidator(BaseConverter): """Validate dates in urls.""" - regex = r'\d{4}-(0[1-9])|(1[012])-((0[1-9])|([12]\d)|(3[01]))' + regex = r'\d{4}-\d{1,2}-\d{1,2}' def to_python(self, value): """Validate and convert date.""" parsed = dt_util.parse_date(value) - if value is None: + if parsed is None: raise ValidationError() return parsed diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index 6bf5c8207fe..ac2468dd9a1 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -94,13 +94,7 @@ class LogbookView(HomeAssistantView): def get(self, request, date=None): """Retrieve logbook entries.""" if date: - start_date = dt_util.parse_date(date) - - if start_date is None: - return self.json_message('Error parsing JSON', - HTTP_BAD_REQUEST) - - start_day = dt_util.start_of_local_day(start_date) + start_day = dt_util.start_of_local_day(date) else: start_day = dt_util.start_of_local_day()