Use local timezone for log and history dates (#2622)

* Use local timezone for log and history dates

* home-assistant-js fix

* Submodule updates not included so travis can build

* Separate Date and DateTime http validators

* Include submodule reference

* Update frontend
pull/2642/head
Paulus Schoutsen 2016-07-27 20:43:46 -07:00 committed by GitHub
parent 4f89230251
commit 1620680127
25 changed files with 42 additions and 34 deletions

View File

@ -1,16 +1,16 @@
"""DO NOT MODIFY. Auto-generated by script/fingerprint_frontend."""
FINGERPRINTS = {
"core.js": "9f8d95cc1ccda7134a035e6e48b08681",
"frontend.html": "1706c78b93bd9c0452c1aa4b565629bf",
"mdi.html": "a7fa9237b7da93951076b4fe26cb8cd2",
"core.js": "bc78f21f5280217aa2c78dfc5848134f",
"frontend.html": "844d9aafa012657fadd9e7b4beb46f47",
"mdi.html": "f6c6cc64c2ec38a80e91f801b41119b3",
"panels/ha-panel-dev-event.html": "20327fbd4fb0370aec9be4db26fd723f",
"panels/ha-panel-dev-info.html": "28e0a19ceb95aa714fd53228d9983a49",
"panels/ha-panel-dev-service.html": "85fd5b48600418bb5a6187539a623c38",
"panels/ha-panel-dev-state.html": "25d84d7b7aea779bb3bb3cd6c155f8d9",
"panels/ha-panel-dev-template.html": "d079abf61cff9690f828cafb0d29b7e7",
"panels/ha-panel-history.html": "8bb29ae608b747b6db97b8f730f4bd45",
"panels/ha-panel-history.html": "7e051b5babf5653b689e0107ea608acb",
"panels/ha-panel-iframe.html": "7bdb564a8f37971d7b89b718935810a1",
"panels/ha-panel-logbook.html": "51a7bfd8bc7d8b6b81f737ff7bee01b5",
"panels/ha-panel-logbook.html": "9b285357b0b2d82ee282e634f4e1cab2",
"panels/ha-panel-map.html": "dfe141a3fa5fd403be554def1dd039a9"
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit d7a6282ba6d9dc2f56cfaea66836aef9f86e8c9d
Subproject commit 67446892e86fc5b26bb5928fee81d536584ad88c

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,6 @@ Provide pre-made queries on top of the recorder component.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/history/
"""
import re
from collections import defaultdict
from datetime import timedelta
from itertools import groupby
@ -20,9 +19,6 @@ DEPENDENCIES = ['recorder', 'http']
SIGNIFICANT_DOMAINS = ('thermostat',)
IGNORE_DOMAINS = ('zone', 'scene',)
URL_HISTORY_PERIOD = re.compile(
r'/api/history/period(?:/(?P<date>\d{4}-\d{1,2}-\d{1,2})|)')
def last_5_states(entity_id):
"""Return the last 5 states for entity_id."""
@ -175,14 +171,14 @@ class HistoryPeriodView(HomeAssistantView):
url = '/api/history/period'
name = 'api:history:view-period'
extra_urls = ['/api/history/period/<date:date>']
extra_urls = ['/api/history/period/<datetime:datetime>']
def get(self, request, date=None):
def get(self, request, datetime=None):
"""Return history over a period of time."""
one_day = timedelta(days=1)
if date:
start_time = dt_util.as_utc(dt_util.start_of_local_day(date))
if datetime:
start_time = dt_util.as_utc(datetime)
else:
start_time = dt_util.utcnow() - one_day

View File

@ -216,9 +216,29 @@ def routing_map(hass):
"""Convert date to url value."""
return value.isoformat()
class DateTimeValidator(BaseConverter):
"""Validate datetimes in urls formatted per ISO 8601."""
regex = r'\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d' \
r'\.\d+([+-][0-2]\d:[0-5]\d|Z)'
def to_python(self, value):
"""Validate and convert date."""
parsed = dt_util.parse_datetime(value)
if parsed is None:
raise ValidationError()
return parsed
def to_url(self, value):
"""Convert date to url value."""
return value.isoformat()
return Map(converters={
'entity': EntityValidator,
'date': DateValidator,
'datetime': DateTimeValidator,
})

View File

@ -5,7 +5,6 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/logbook/
"""
import logging
import re
from datetime import timedelta
from itertools import groupby
@ -27,8 +26,6 @@ from homeassistant.helpers.entity import split_entity_id
DOMAIN = "logbook"
DEPENDENCIES = ['recorder', 'frontend']
URL_LOGBOOK = re.compile(r'/api/logbook(?:/(?P<date>\d{4}-\d{1,2}-\d{1,2})|)')
_LOGGER = logging.getLogger(__name__)
EVENT_LOGBOOK_ENTRY = 'logbook_entry'
@ -89,16 +86,11 @@ class LogbookView(HomeAssistantView):
url = '/api/logbook'
name = 'api:logbook'
extra_urls = ['/api/logbook/<date:date>']
extra_urls = ['/api/logbook/<datetime:datetime>']
def get(self, request, date=None):
def get(self, request, datetime=None):
"""Retrieve logbook entries."""
if date:
start_day = dt_util.start_of_local_day(date)
else:
start_day = dt_util.start_of_local_day()
start_day = dt_util.as_utc(start_day)
start_day = dt_util.as_utc(datetime or dt_util.start_of_local_day())
end_day = start_day + timedelta(days=1)
events = recorder.get_model('Events')