From 6a7968593d8e024fc6c4c2f7535a6a18b0f2f34a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 24 May 2021 09:27:13 -0700 Subject: [PATCH] Make camera source check faster (#51035) --- homeassistant/components/camera/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index d9ccb0490c6..4791a963048 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -696,10 +696,13 @@ async def async_handle_play_stream_service( # It is required to send a different payload for cast media players entity_ids = service_call.data[ATTR_MEDIA_PLAYER] + sources = entity_sources(hass) cast_entity_ids = [ entity - for entity, source in entity_sources(hass).items() - if entity in entity_ids and source["domain"] == "cast" + for entity in entity_ids + # All entities should be in sources. This extra guard is to + # avoid people writing to the state machine and breaking it. + if entity in sources and sources[entity]["domain"] == "cast" ] other_entity_ids = list(set(entity_ids) - set(cast_entity_ids))