mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Refactor restore state saving to avoid a dict lookup of ATTR_RESTORED (#106854)
This commit is contained in:
parent
41646a6514
commit
bbdccede85
@ -178,8 +178,8 @@ class RestoreStateData:
|
|||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
all_states = self.hass.states.async_all()
|
all_states = self.hass.states.async_all()
|
||||||
# Entities currently backed by an entity object
|
# Entities currently backed by an entity object
|
||||||
current_entity_ids = {
|
current_states_by_entity_id = {
|
||||||
state.entity_id
|
state.entity_id: state
|
||||||
for state in all_states
|
for state in all_states
|
||||||
if not state.attributes.get(ATTR_RESTORED)
|
if not state.attributes.get(ATTR_RESTORED)
|
||||||
}
|
}
|
||||||
@ -187,13 +187,12 @@ class RestoreStateData:
|
|||||||
# Start with the currently registered states
|
# Start with the currently registered states
|
||||||
stored_states = [
|
stored_states = [
|
||||||
StoredState(
|
StoredState(
|
||||||
state, self.entities[state.entity_id].extra_restore_state_data, now
|
current_states_by_entity_id[entity_id],
|
||||||
|
entity.extra_restore_state_data,
|
||||||
|
now,
|
||||||
)
|
)
|
||||||
for state in all_states
|
for entity_id, entity in self.entities.items()
|
||||||
if state.entity_id in self.entities
|
if entity_id in current_states_by_entity_id
|
||||||
and
|
|
||||||
# Ignore all states that are entity registry placeholders
|
|
||||||
not state.attributes.get(ATTR_RESTORED)
|
|
||||||
]
|
]
|
||||||
expiration_time = now - STATE_EXPIRATION
|
expiration_time = now - STATE_EXPIRATION
|
||||||
|
|
||||||
@ -201,7 +200,7 @@ class RestoreStateData:
|
|||||||
# Don't save old states that have entities in the current run
|
# Don't save old states that have entities in the current run
|
||||||
# They are either registered and already part of stored_states,
|
# They are either registered and already part of stored_states,
|
||||||
# or no longer care about restoring.
|
# or no longer care about restoring.
|
||||||
if entity_id in current_entity_ids:
|
if entity_id in current_states_by_entity_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Don't save old states that have expired
|
# Don't save old states that have expired
|
||||||
|
Loading…
x
Reference in New Issue
Block a user