Bugfixes for urls with dates
This commit is contained in:
parent
e10b00f341
commit
bfdb51a558
4 changed files with 7 additions and 20 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 0be98873d7044f387645f3a694e41660be663b66
|
Subproject commit 4f8e2d568755fdb7c4eb61ca13533665202dbd23
|
|
@ -177,26 +177,19 @@ class HistoryPeriodView(HomeAssistantView):
|
||||||
"""Handle history period requests."""
|
"""Handle history period requests."""
|
||||||
|
|
||||||
url = '/api/history/period'
|
url = '/api/history/period'
|
||||||
name = 'api:history:entity-recent-states'
|
name = 'api:history:view-period'
|
||||||
extra_urls = ['/api/history/period/<date:date>']
|
extra_urls = ['/api/history/period/<date:date>']
|
||||||
|
|
||||||
def get(self, request, date=None):
|
def get(self, request, date=None):
|
||||||
"""Return history over a period of time."""
|
"""Return history over a period of time."""
|
||||||
one_day = timedelta(seconds=86400)
|
one_day = timedelta(days=1)
|
||||||
|
|
||||||
if date:
|
if date:
|
||||||
start_date = dt_util.parse_date(date)
|
start_time = dt_util.as_utc(dt_util.start_of_local_day(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))
|
|
||||||
else:
|
else:
|
||||||
start_time = dt_util.utcnow() - one_day
|
start_time = dt_util.utcnow() - one_day
|
||||||
|
|
||||||
end_time = start_time + one_day
|
end_time = start_time + one_day
|
||||||
|
|
||||||
entity_id = request.args.get('filter_entity_id')
|
entity_id = request.args.get('filter_entity_id')
|
||||||
|
|
||||||
return self.json(
|
return self.json(
|
||||||
|
|
|
@ -148,13 +148,13 @@ def routing_map(hass):
|
||||||
class DateValidator(BaseConverter):
|
class DateValidator(BaseConverter):
|
||||||
"""Validate dates in urls."""
|
"""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):
|
def to_python(self, value):
|
||||||
"""Validate and convert date."""
|
"""Validate and convert date."""
|
||||||
parsed = dt_util.parse_date(value)
|
parsed = dt_util.parse_date(value)
|
||||||
|
|
||||||
if value is None:
|
if parsed is None:
|
||||||
raise ValidationError()
|
raise ValidationError()
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
|
|
|
@ -94,13 +94,7 @@ class LogbookView(HomeAssistantView):
|
||||||
def get(self, request, date=None):
|
def get(self, request, date=None):
|
||||||
"""Retrieve logbook entries."""
|
"""Retrieve logbook entries."""
|
||||||
if date:
|
if date:
|
||||||
start_date = dt_util.parse_date(date)
|
start_day = dt_util.start_of_local_day(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)
|
|
||||||
else:
|
else:
|
||||||
start_day = dt_util.start_of_local_day()
|
start_day = dt_util.start_of_local_day()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue