Minor helpers cleanup (#34786)

This commit is contained in:
Paulus Schoutsen 2020-04-28 14:31:25 -07:00 committed by GitHub
parent 28f6e79385
commit 87801d8aca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -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.

View File

@ -545,13 +545,17 @@ 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
if not authorized:
raise Unauthorized(
context=call.context,
permission=POLICY_CONTROL,
@ -559,6 +563,8 @@ def verify_domain_control(hass: HomeAssistantType, domain: str) -> Callable:
perm_category=CAT_ENTITIES,
)
return await service_handler(call)
return check_permissions
return decorator