Google assistant storage of connected agents (#29158)

* Make async_report_state take agent_user_id

* Attempt to store synced agents

* Drop now not needed initialization

* Make sure cloud uses the all sync on changed preferences

* Some more places to use all version of sync

* Get the agent_user_id from the request context if available

* Minor cleanup

* Remove the old fixed agent_user_id for cloud

Instead pass along cloud_user where appropriate.

* async_delay_save takes a function

* Adjust test for delayed store

* Remove unused save function

* Add login check.
This commit is contained in:
Joakim Plate authored and Paulus Schoutsen committed 2019-12-02 22:05:59 -08:00
1 parent 434b783b4c
commit 2569c4ae37
16 files changed
+260 -83

No files matched your search

+3 -6
View File
@@ -102,16 +102,13 @@ async def test_handler_google_actions(hass):
reqid = "5711642932632160983"
data = {"requestId": reqid, "inputs": [{"intent": "action.devices.SYNC"}]}
with patch(
"hass_nabucasa.Cloud._decode_claims",
return_value={"cognito:username": "myUserName"},
):
resp = await cloud.client.async_google_message(data)
config = await cloud.client.get_google_config()
resp = await cloud.client.async_google_message(data)
assert resp["requestId"] == reqid
payload = resp["payload"]
assert payload["agentUserId"] == "myUserName"
assert payload["agentUserId"] == config.cloud_user
devices = payload["devices"]
assert len(devices) == 1
@@ -19,6 +19,8 @@ async def test_google_update_report_state(hass, cloud_prefs):
cloud_prefs,
Mock(claims={"cognito:username": "abcdefghjkl"}),
)
await config.async_initialize()
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_sync_entities", side_effect=mock_coro
@@ -58,6 +60,8 @@ async def test_google_update_expose_trigger_sync(hass, cloud_prefs):
cloud_prefs,
Mock(claims={"cognito:username": "abcdefghjkl"}),
)
await config.async_initialize()
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_sync_entities", side_effect=mock_coro
@@ -95,6 +99,8 @@ async def test_google_entity_registry_sync(hass, mock_cloud_login, cloud_prefs):
config = CloudGoogleConfig(
hass, GACTIONS_SCHEMA({}), "mock-user-id", cloud_prefs, hass.data["cloud"]
)
await config.async_initialize()
await config.async_connect_agent_user("mock-user-id")
with patch.object(
config, "async_sync_entities", side_effect=mock_coro