Fix history API (#13214)
parent
ef7ce5eb1b
commit
a9917e7a56
|
@ -239,15 +239,16 @@ def get_state(hass, utc_point_in_time, entity_id, run=None):
|
|||
def async_setup(hass, config):
|
||||
"""Set up the history hooks."""
|
||||
filters = Filters()
|
||||
exclude = config[DOMAIN].get(CONF_EXCLUDE)
|
||||
conf = config.get(DOMAIN, {})
|
||||
exclude = conf.get(CONF_EXCLUDE)
|
||||
if exclude:
|
||||
filters.excluded_entities = exclude.get(CONF_ENTITIES, [])
|
||||
filters.excluded_domains = exclude.get(CONF_DOMAINS, [])
|
||||
include = config[DOMAIN].get(CONF_INCLUDE)
|
||||
include = conf.get(CONF_INCLUDE)
|
||||
if include:
|
||||
filters.included_entities = include.get(CONF_ENTITIES, [])
|
||||
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))
|
||||
yield from hass.components.frontend.async_register_built_in_panel(
|
||||
|
@ -308,7 +309,7 @@ class HistoryPeriodView(HomeAssistantView):
|
|||
result = yield from hass.async_add_job(
|
||||
get_significant_states, hass, start_time, end_time,
|
||||
entity_ids, self.filters, include_start_time_state)
|
||||
result = result.values()
|
||||
result = list(result.values())
|
||||
if _LOGGER.isEnabledFor(logging.DEBUG):
|
||||
elapsed = time.perf_counter() - timer_start
|
||||
_LOGGER.debug(
|
||||
|
@ -318,7 +319,6 @@ class HistoryPeriodView(HomeAssistantView):
|
|||
# by any entities explicitly included in the configuration.
|
||||
|
||||
if self.use_include_order:
|
||||
result = list(result)
|
||||
sorted_result = []
|
||||
for order_entity in self.filters.included_entities:
|
||||
for state_list in result:
|
||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||
import unittest
|
||||
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.util.dt as dt_util
|
||||
from homeassistant.components import history, recorder
|
||||
|
@ -481,3 +481,13 @@ class TestComponentHistory(unittest.TestCase):
|
|||
set_state(therm, 22, attributes={'current_temperature': 21,
|
||||
'hidden': True})
|
||||
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…
Reference in New Issue