Use single_config_entry in google_assistant_sdk (#130632)

* Use single_config_entry in google_assistant_sdk

* Cleanup
This commit is contained in:
epenet 2024-11-15 04:43:13 +01:00 committed by GitHub
parent e8b0b3e05c
commit 5806304d79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 39 deletions

View File

@ -66,10 +66,6 @@ class OAuth2FlowHandler(
self._get_reauth_entry(), data=data
)
if self._async_current_entries():
# Config entry already exists, only one allowed.
return self.async_abort(reason="single_instance_allowed")
return self.async_create_entry(
title=DEFAULT_NAME,
data=data,

View File

@ -8,5 +8,6 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"quality_scale": "platinum",
"requirements": ["gassist-text==0.0.11"]
"requirements": ["gassist-text==0.0.11"],
"single_config_entry": true
}

View File

@ -157,10 +157,6 @@ async def test_reauth(
assert config_entry.data["token"].get("refresh_token") == "mock-refresh-token"
@pytest.mark.parametrize( # Remove when translations fixed
"ignore_translations",
["component.google_assistant_sdk.config.abort.single_instance_allowed"],
)
@pytest.mark.usefixtures("current_request_with_host")
async def test_single_instance_allowed(
hass: HomeAssistant,
@ -182,37 +178,7 @@ async def test_single_instance_allowed(
result = await hass.config_entries.flow.async_init(
"google_assistant_sdk", context={"source": config_entries.SOURCE_USER}
)
state = config_entry_oauth2_flow._encode_jwt(
hass,
{
"flow_id": result["flow_id"],
"redirect_uri": "https://example.com/auth/external/callback",
},
)
assert result["url"] == (
f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/assistant-sdk-prototype"
"&access_type=offline&prompt=consent"
)
client = await hass_client_no_auth()
resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
assert resp.status == 200
assert resp.headers["content-type"] == "text/html; charset=utf-8"
aioclient_mock.post(
GOOGLE_TOKEN_URI,
json={
"refresh_token": "mock-refresh-token",
"access_token": "mock-access-token",
"type": "Bearer",
"expires_in": 60,
},
)
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result.get("type") is FlowResultType.ABORT
assert result.get("reason") == "single_instance_allowed"