Fix history API (#13214)
This commit is contained in:
parent
ef7ce5eb1b
commit
a9917e7a56
2 changed files with 16 additions and 6 deletions
|
@ -239,15 +239,16 @@ def get_state(hass, utc_point_in_time, entity_id, run=None):
|
||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Set up the history hooks."""
|
"""Set up the history hooks."""
|
||||||
filters = Filters()
|
filters = Filters()
|
||||||
exclude = config[DOMAIN].get(CONF_EXCLUDE)
|
conf = config.get(DOMAIN, {})
|
||||||
|
exclude = conf.get(CONF_EXCLUDE)
|
||||||
if exclude:
|
if exclude:
|
||||||
filters.excluded_entities = exclude.get(CONF_ENTITIES, [])
|
filters.excluded_entities = exclude.get(CONF_ENTITIES, [])
|
||||||
filters.excluded_domains = exclude.get(CONF_DOMAINS, [])
|
filters.excluded_domains = exclude.get(CONF_DOMAINS, [])
|
||||||
include = config[DOMAIN].get(CONF_INCLUDE)
|
include = conf.get(CONF_INCLUDE)
|
||||||
if include:
|
if include:
|
||||||
filters.included_entities = include.get(CONF_ENTITIES, [])
|
filters.included_entities = include.get(CONF_ENTITIES, [])
|
||||||
filters.included_domains = include.get(CONF_DOMAINS, [])
|
filters.included_domains = include.get(CONF_DOMAINS, [])
|
||||||
use_include_order = config[DOMAIN].get(CONF_ORDER)
|
use_include_order = conf.get(CONF_ORDER)
|
||||||
|
|
||||||
hass.http.register_view(HistoryPeriodView(filters, use_include_order))
|
hass.http.register_view(HistoryPeriodView(filters, use_include_order))
|
||||||
yield from hass.components.frontend.async_register_built_in_panel(
|
yield from hass.components.frontend.async_register_built_in_panel(
|
||||||
|
@ -308,7 +309,7 @@ class HistoryPeriodView(HomeAssistantView):
|
||||||
result = yield from hass.async_add_job(
|
result = yield from hass.async_add_job(
|
||||||
get_significant_states, hass, start_time, end_time,
|
get_significant_states, hass, start_time, end_time,
|
||||||
entity_ids, self.filters, include_start_time_state)
|
entity_ids, self.filters, include_start_time_state)
|
||||||
result = result.values()
|
result = list(result.values())
|
||||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
elapsed = time.perf_counter() - timer_start
|
elapsed = time.perf_counter() - timer_start
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
@ -318,7 +319,6 @@ class HistoryPeriodView(HomeAssistantView):
|
||||||
# by any entities explicitly included in the configuration.
|
# by any entities explicitly included in the configuration.
|
||||||
|
|
||||||
if self.use_include_order:
|
if self.use_include_order:
|
||||||
result = list(result)
|
|
||||||
sorted_result = []
|
sorted_result = []
|
||||||
for order_entity in self.filters.included_entities:
|
for order_entity in self.filters.included_entities:
|
||||||
for state_list in result:
|
for state_list in result:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch, sentinel
|
from unittest.mock import patch, sentinel
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component, async_setup_component
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.components import history, recorder
|
from homeassistant.components import history, recorder
|
||||||
|
@ -481,3 +481,13 @@ class TestComponentHistory(unittest.TestCase):
|
||||||
set_state(therm, 22, attributes={'current_temperature': 21,
|
set_state(therm, 22, attributes={'current_temperature': 21,
|
||||||
'hidden': True})
|
'hidden': True})
|
||||||
return zero, four, states
|
return zero, four, states
|
||||||
|
|
||||||
|
|
||||||
|
async def test_fetch_period_api(hass, test_client):
|
||||||
|
"""Test the fetch period view for history."""
|
||||||
|
await hass.async_add_job(init_recorder_component, hass)
|
||||||
|
await async_setup_component(hass, 'history', {})
|
||||||
|
client = await test_client(hass.http.app)
|
||||||
|
response = await client.get(
|
||||||
|
'/api/history/period/{}'.format(dt_util.utcnow().isoformat()))
|
||||||
|
assert response.status == 200
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue