Add a guard against selecting all entities in state_changes_during_period (#91585)

Add a guard against selecting all entities in state_changes_during_period

This cannot happen in `dev` because we require entity ids
This commit is contained in:
J. Nick Koston 2023-04-18 03:26:41 -10:00 committed by GitHub
parent 940861e2be
commit 03c517b066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -374,6 +374,8 @@ def state_changes_during_period(
if entity_id:
instance = recorder.get_instance(hass)
metadata_id = instance.states_meta_manager.get(entity_id, session, False)
if metadata_id is None:
return {}
entity_id_to_metadata_id = {entity_id: metadata_id}
stmt = _state_changed_during_period_stmt(
start_time,
@ -394,7 +396,7 @@ def state_changes_during_period(
states,
start_time,
entity_ids,
entity_id_to_metadata_id,
entity_id_to_metadata_id, # type: ignore[arg-type]
include_start_time_state=include_start_time_state,
),
)