mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Use single_config_entry in google_assistant_sdk (#130632)
* Use single_config_entry in google_assistant_sdk * Cleanup
This commit is contained in:
parent
e8b0b3e05c
commit
5806304d79
@ -66,10 +66,6 @@ class OAuth2FlowHandler(
|
|||||||
self._get_reauth_entry(), data=data
|
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(
|
return self.async_create_entry(
|
||||||
title=DEFAULT_NAME,
|
title=DEFAULT_NAME,
|
||||||
data=data,
|
data=data,
|
||||||
|
@ -8,5 +8,6 @@
|
|||||||
"integration_type": "service",
|
"integration_type": "service",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["gassist-text==0.0.11"]
|
"requirements": ["gassist-text==0.0.11"],
|
||||||
|
"single_config_entry": true
|
||||||
}
|
}
|
||||||
|
@ -157,10 +157,6 @@ async def test_reauth(
|
|||||||
assert config_entry.data["token"].get("refresh_token") == "mock-refresh-token"
|
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")
|
@pytest.mark.usefixtures("current_request_with_host")
|
||||||
async def test_single_instance_allowed(
|
async def test_single_instance_allowed(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -182,37 +178,7 @@ async def test_single_instance_allowed(
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"google_assistant_sdk", context={"source": config_entries.SOURCE_USER}
|
"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("type") is FlowResultType.ABORT
|
||||||
assert result.get("reason") == "single_instance_allowed"
|
assert result.get("reason") == "single_instance_allowed"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user