mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Period of history now returns a spanning result
This commit is contained in:
parent
772df97bc1
commit
45dd8cbc3f
@ -49,8 +49,22 @@ def state_changes_during_period(start_time, end_time=None, entity_id=None):
|
|||||||
|
|
||||||
states = recorder.query_states(query, data)
|
states = recorder.query_states(query, data)
|
||||||
|
|
||||||
return [list(group) for _, group in
|
result = []
|
||||||
groupby(states, lambda state: state.entity_id)]
|
|
||||||
|
for entity_id, group in groupby(states, lambda state: state.entity_id):
|
||||||
|
# Query the state of the entity ID before `start_time` so the returned
|
||||||
|
# set will cover everything between `start_time` and `end_time`.
|
||||||
|
old_state = list(recorder.query_states(
|
||||||
|
"SELECT * FROM states WHERE entity_id = ? AND last_changed <= ? "
|
||||||
|
"AND last_changed=last_updated ORDER BY last_changed DESC "
|
||||||
|
"LIMIT 0, 1", (entity_id, start_time)))
|
||||||
|
|
||||||
|
if old_state:
|
||||||
|
old_state[0].last_changed = start_time
|
||||||
|
|
||||||
|
result.append(old_state + list(group))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user