mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Return history for entities in the order they were requested (#25560)
* Return history for entities in the order they were requested * Fix problems. Add tests * Update __init__.py
This commit is contained in:
parent
fcdd66b33b
commit
671cb0d092
@ -211,6 +211,9 @@ def states_to_json(
|
|||||||
axis correctly.
|
axis correctly.
|
||||||
"""
|
"""
|
||||||
result = defaultdict(list)
|
result = defaultdict(list)
|
||||||
|
if entity_ids is not None:
|
||||||
|
for ent_id in entity_ids:
|
||||||
|
result[ent_id] = []
|
||||||
|
|
||||||
# Get the states at the start time
|
# Get the states at the start time
|
||||||
timer_start = time.perf_counter()
|
timer_start = time.perf_counter()
|
||||||
|
@ -428,6 +428,22 @@ class TestComponentHistory(unittest.TestCase):
|
|||||||
history.CONF_ENTITIES: ['media_player.test']}}})
|
history.CONF_ENTITIES: ['media_player.test']}}})
|
||||||
self.check_significant_states(zero, four, states, config)
|
self.check_significant_states(zero, four, states, config)
|
||||||
|
|
||||||
|
def test_get_significant_states_are_ordered(self):
|
||||||
|
"""Test order of results from get_significant_states
|
||||||
|
|
||||||
|
When entity ids are given, the results should be returned with the data
|
||||||
|
in the same order.
|
||||||
|
"""
|
||||||
|
zero, four, states = self.record_states()
|
||||||
|
entity_ids = ['media_player.test', 'media_player.test2']
|
||||||
|
hist = history.get_significant_states(
|
||||||
|
self.hass, zero, four, entity_ids, filters=history.Filters())
|
||||||
|
assert list(hist.keys()) == entity_ids
|
||||||
|
entity_ids = ['media_player.test2', 'media_player.test']
|
||||||
|
hist = history.get_significant_states(
|
||||||
|
self.hass, zero, four, entity_ids, filters=history.Filters())
|
||||||
|
assert list(hist.keys()) == entity_ids
|
||||||
|
|
||||||
def check_significant_states(self, zero, four, states, config):
|
def check_significant_states(self, zero, four, states, config):
|
||||||
"""Check if significant states are retrieved."""
|
"""Check if significant states are retrieved."""
|
||||||
filters = history.Filters()
|
filters = history.Filters()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user