From 909df675e0ffe25ecfb2405ac442762bfdb0deae Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 9 Jun 2024 11:32:33 -0500 Subject: [PATCH] Use a listcomp for history results (#119188) --- .../components/recorder/history/modern.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/recorder/history/modern.py b/homeassistant/components/recorder/history/modern.py index 96347a1f57b..b6acb6601ff 100644 --- a/homeassistant/components/recorder/history/modern.py +++ b/homeassistant/components/recorder/history/modern.py @@ -782,24 +782,30 @@ def _sorted_states_to_dict( if compressed_state_format: # Compressed state format uses the timestamp directly ent_results.extend( - { - attr_state: (prev_state := state), - attr_time: row[last_updated_ts_idx], - } - for row in group - if (state := row[state_idx]) != prev_state + [ + { + attr_state: (prev_state := state), + attr_time: row[last_updated_ts_idx], + } + for row in group + if (state := row[state_idx]) != prev_state + ] ) continue # Non-compressed state format returns an ISO formatted string _utc_from_timestamp = dt_util.utc_from_timestamp ent_results.extend( - { - attr_state: (prev_state := state), - attr_time: _utc_from_timestamp(row[last_updated_ts_idx]).isoformat(), - } - for row in group - if (state := row[state_idx]) != prev_state + [ + { + attr_state: (prev_state := state), + attr_time: _utc_from_timestamp( + row[last_updated_ts_idx] + ).isoformat(), + } + for row in group + if (state := row[state_idx]) != prev_state + ] ) if descending: