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))