diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 4c30457b62c..0a7c52f7059 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -270,9 +270,15 @@ class EntityComponent: async def async_remove_entity(self, entity_id: str) -> None: """Remove an entity managed by one of the platforms.""" + found = None + for platform in self._platforms.values(): if entity_id in platform.entities: - await platform.async_remove_entity(entity_id) + found = platform + break + + if found: + await found.async_remove_entity(entity_id) async def async_prepare_reload(self, *, skip_reset: bool = False) -> Optional[dict]: """Prepare reloading this entity component. diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index a75f862467e..ce52d188540 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -545,19 +545,25 @@ def verify_domain_control(hass: HomeAssistantType, domain: str) -> Callable: reg = await hass.helpers.entity_registry.async_get_registry() + authorized = False + for entity in reg.entities.values(): if entity.platform != domain: continue if user.permissions.check_entity(entity.entity_id, POLICY_CONTROL): - return await service_handler(call) + authorized = True + break - raise Unauthorized( - context=call.context, - permission=POLICY_CONTROL, - user_id=call.context.user_id, - perm_category=CAT_ENTITIES, - ) + if not authorized: + raise Unauthorized( + context=call.context, + permission=POLICY_CONTROL, + user_id=call.context.user_id, + perm_category=CAT_ENTITIES, + ) + + return await service_handler(call) return check_permissions