Rename google_assistant.AbstractConfig.get_local_agent_user_id (#109798)

* Rename google_assistant.AbstractConfig get_local_agent_user_id to get_local_user_id

* Fix
This commit is contained in:
Erik Montnemery 2024-02-06 15:40:12 +01:00 committed by GitHub
parent cf188eabdf
commit 0cb913370f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 8 deletions

View File

@ -173,8 +173,12 @@ class CloudGoogleConfig(AbstractConfig):
"""Return the webhook ID to be used for actions for a given agent user id via the local SDK."""
return self._prefs.google_local_webhook_id
def get_local_agent_user_id(self, webhook_id: Any) -> str:
"""Return the user ID to be used for actions received via the local SDK."""
def get_local_user_id(self, webhook_id: Any) -> str:
"""Map webhook ID to a Home Assistant user ID.
Any action inititated by Google Assistant via the local SDK will be attributed
to the returned user ID.
"""
return self._user
@property

View File

@ -167,11 +167,16 @@ class AbstractConfig(ABC):
and self._local_last_active > utcnow() - timedelta(seconds=70)
)
def get_local_agent_user_id(self, webhook_id):
"""Return the user ID to be used for actions received via the local SDK.
def get_local_user_id(self, webhook_id):
"""Map webhook ID to a Home Assistant user ID.
Return None is no agent user id is found.
Any action inititated by Google Assistant via the local SDK will be attributed
to the returned user ID.
Return None if no user id is found for the webhook_id.
"""
# Note: The manually setup Google Assistant currently returns the Google agent
# user ID instead of a valid Home Assistant user ID
found_agent_user_id = None
for agent_user_id, agent_user_data in self._store.agent_user_ids.items():
if agent_user_data[STORE_GOOGLE_LOCAL_WEBHOOK_ID] == webhook_id:
@ -423,7 +428,7 @@ class AbstractConfig(ABC):
pprint.pformat(async_redact_request_msg(payload)),
)
if (agent_user_id := self.get_local_agent_user_id(webhook_id)) is None:
if (agent_user_id := self.get_local_user_id(webhook_id)) is None:
# No agent user linked to this webhook, means that the user has somehow unregistered
# removing webhook and stopping processing of this request.
_LOGGER.error(

View File

@ -258,8 +258,8 @@ async def test_google_config_local_fulfillment(
await hass.async_block_till_done()
assert config.get_local_webhook_id(agent_user_id) == local_webhook_id
assert config.get_local_agent_user_id(local_webhook_id) == agent_user_id
assert config.get_local_agent_user_id("INCORRECT") is None
assert config.get_local_user_id(local_webhook_id) == agent_user_id
assert config.get_local_user_id("INCORRECT") is None
async def test_secure_device_pin_config(hass: HomeAssistant) -> None: