Skip to content

Commit

Permalink
Use single_config_entry in google_assistant_sdk (home-assistant#130632)
Browse files Browse the repository at this point in the history
* Use single_config_entry in google_assistant_sdk

* Cleanup
  • Loading branch information
epenet authored Nov 15, 2024
1 parent e8b0b3e commit 5806304
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
4 changes: 0 additions & 4 deletions homeassistant/components/google_assistant_sdk/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResu
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,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/google_assistant_sdk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
34 changes: 0 additions & 34 deletions tests/components/google_assistant_sdk/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"

Expand Down

0 comments on commit 5806304

Please sign in to comment.