mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Allow printing the number of states returned by history and time it took to extract. (#5973)
This commit is contained in:
parent
36c196f9e8
commit
e70b7ab509
@ -8,6 +8,9 @@ import asyncio
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -19,6 +22,8 @@ from homeassistant.components.frontend import register_built_in_panel
|
|||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.const import ATTR_HIDDEN
|
from homeassistant.const import ATTR_HIDDEN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = 'history'
|
DOMAIN = 'history'
|
||||||
DEPENDENCIES = ['recorder', 'http']
|
DEPENDENCIES = ['recorder', 'http']
|
||||||
|
|
||||||
@ -215,6 +220,7 @@ class HistoryPeriodView(HomeAssistantView):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def get(self, request, datetime=None):
|
def get(self, request, datetime=None):
|
||||||
"""Return history over a period of time."""
|
"""Return history over a period of time."""
|
||||||
|
timer_start = time.perf_counter()
|
||||||
if datetime:
|
if datetime:
|
||||||
datetime = dt_util.parse_datetime(datetime)
|
datetime = dt_util.parse_datetime(datetime)
|
||||||
|
|
||||||
@ -239,8 +245,12 @@ class HistoryPeriodView(HomeAssistantView):
|
|||||||
result = yield from request.app['hass'].loop.run_in_executor(
|
result = yield from request.app['hass'].loop.run_in_executor(
|
||||||
None, get_significant_states, start_time, end_time, entity_id,
|
None, get_significant_states, start_time, end_time, entity_id,
|
||||||
self.filters)
|
self.filters)
|
||||||
|
result = result.values()
|
||||||
return self.json(result.values())
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
|
elapsed = time.perf_counter() - timer_start
|
||||||
|
_LOGGER.debug(
|
||||||
|
'Extracted %d states in %fs', sum(map(len, result)), elapsed)
|
||||||
|
return self.json(result)
|
||||||
|
|
||||||
|
|
||||||
class Filters(object):
|
class Filters(object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user