Allow exposing entities not in the entity registry to assistants (#92363)

This commit is contained in:
Erik Montnemery 2023-05-02 22:08:09 +02:00 committed by GitHub
parent cc4e741cfa
commit e3c16e634b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 563 additions and 224 deletions

View file

@ -175,7 +175,7 @@ class AbstractConfig(ABC):
"""Get agent user ID from context."""
@abstractmethod
def should_expose(self, state) -> bool:
async def should_expose(self, state) -> bool:
"""Return if entity should be exposed."""
def should_2fa(self, state):
@ -535,16 +535,14 @@ class GoogleEntity:
]
return self._traits
@callback
def should_expose(self):
async def should_expose(self):
"""If entity should be exposed."""
return self.config.should_expose(self.state)
return await self.config.should_expose(self.state)
@callback
def should_expose_local(self) -> bool:
async def should_expose_local(self) -> bool:
"""Return if the entity should be exposed locally."""
return (
self.should_expose()
await self.should_expose()
and get_google_type(
self.state.domain, self.state.attributes.get(ATTR_DEVICE_CLASS)
)
@ -587,7 +585,7 @@ class GoogleEntity:
trait.might_2fa(domain, features, device_class) for trait in self.traits()
)
def sync_serialize(self, agent_user_id, instance_uuid):
async def sync_serialize(self, agent_user_id, instance_uuid):
"""Serialize entity for a SYNC response.
https://developers.google.com/actions/smarthome/create-app#actiondevicessync
@ -623,7 +621,7 @@ class GoogleEntity:
device["name"]["nicknames"].extend(entity_entry.aliases)
# Add local SDK info if enabled
if self.config.is_local_sdk_active and self.should_expose_local():
if self.config.is_local_sdk_active and await self.should_expose_local():
device["otherDeviceIds"] = [{"deviceId": self.entity_id}]
device["customData"] = {
"webhookId": self.config.get_local_webhook_id(agent_user_id),