mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Control ordering of display in history component (#11340)
* Make the order shown in the history component match the ordering given in the configuration of included entities (if any) * return the sorted result * optimize sorting. since entities only appear once, we can break from a search on first find, and no copy of the list is needed
This commit is contained in:
parent
1235dae5b8
commit
6af42b4372
@ -304,7 +304,20 @@ class HistoryPeriodView(HomeAssistantView):
|
||||
elapsed = time.perf_counter() - timer_start
|
||||
_LOGGER.debug(
|
||||
'Extracted %d states in %fs', sum(map(len, result)), elapsed)
|
||||
return self.json(result)
|
||||
|
||||
# Reorder the result to respect the ordering given by any
|
||||
# entities explicitly included in the configuration.
|
||||
|
||||
sorted_result = []
|
||||
for order_entity in self.filters.included_entities:
|
||||
for state_list in result:
|
||||
if state_list[0].entity_id == order_entity:
|
||||
sorted_result.append(state_list)
|
||||
result.remove(state_list)
|
||||
break
|
||||
sorted_result.extend(result)
|
||||
|
||||
return self.json(sorted_result)
|
||||
|
||||
|
||||
class Filters(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user