mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Add application credentials description strings (#73014)
This commit is contained in:
parent
5987266e56
commit
e74c711ef3
@ -253,6 +253,11 @@ class ApplicationCredentialsProtocol(Protocol):
|
||||
) -> config_entry_oauth2_flow.AbstractOAuth2Implementation:
|
||||
"""Return a custom auth implementation."""
|
||||
|
||||
async def async_get_description_placeholders(
|
||||
self, hass: HomeAssistant
|
||||
) -> dict[str, str]:
|
||||
"""Return description placeholders for the credentials dialog."""
|
||||
|
||||
|
||||
async def _get_platform(
|
||||
hass: HomeAssistant, integration_domain: str
|
||||
@ -282,6 +287,14 @@ async def _get_platform(
|
||||
return platform
|
||||
|
||||
|
||||
async def _async_integration_config(hass: HomeAssistant, domain: str) -> dict[str, Any]:
|
||||
platform = await _get_platform(hass, domain)
|
||||
if platform and hasattr(platform, "async_get_description_placeholders"):
|
||||
placeholders = await platform.async_get_description_placeholders(hass)
|
||||
return {"description_placeholders": placeholders}
|
||||
return {}
|
||||
|
||||
|
||||
@websocket_api.websocket_command(
|
||||
{vol.Required("type"): "application_credentials/config"}
|
||||
)
|
||||
@ -290,6 +303,11 @@ async def handle_integration_list(
|
||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||
) -> None:
|
||||
"""Handle integrations command."""
|
||||
connection.send_result(
|
||||
msg["id"], {"domains": await async_get_application_credentials(hass)}
|
||||
)
|
||||
domains = await async_get_application_credentials(hass)
|
||||
result = {
|
||||
"domains": domains,
|
||||
"integrations": {
|
||||
domain: await _async_integration_config(hass, domain) for domain in domains
|
||||
},
|
||||
}
|
||||
connection.send_result(msg["id"], result)
|
||||
|
@ -21,3 +21,12 @@ async def async_get_auth_implementation(
|
||||
) -> config_entry_oauth2_flow.AbstractOAuth2Implementation:
|
||||
"""Return auth implementation."""
|
||||
return DeviceAuth(hass, auth_domain, credential, AUTHORIZATION_SERVER)
|
||||
|
||||
|
||||
async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, str]:
|
||||
"""Return description placeholders for the credentials dialog."""
|
||||
return {
|
||||
"oauth_consent_url": "https://console.cloud.google.com/apis/credentials/consent",
|
||||
"more_info_url": "https://www.home-assistant.io/integrations/google/",
|
||||
"oauth_creds_url": "https://console.cloud.google.com/apis/credentials",
|
||||
}
|
||||
|
@ -36,5 +36,8 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"application_credentials": {
|
||||
"description": "Follow the [instructions]({more_info_url}) for [OAuth consent screen]({oauth_consent_url}) to give Home Assistant access to your Google Calendar. You also need to create Application Credentials linked to your Calendar:\n1. Go to [Credentials]({oauth_creds_url}) and click **Create Credentials**.\n1. From the drop-down list select **OAuth client ID**.\n1. Select **TV and Limited Input devices** for the Application Type.\n\n"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
{
|
||||
"application_credentials": {
|
||||
"description": "Follow the [instructions]({more_info_url}) for [OAuth consent screen]({oauth_consent_url}) to give Home Assistant access to your Google Calendar. You also need to create Application Credentials linked to your Calendar:\n1. Go to [Credentials]({oauth_creds_url}) page and click **Create Credentials**.\n1. From the drop-down list select **OAuth client ID**.\n1. Select **TV and Limited Input devices** for the Application Type.\n\n"
|
||||
},
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "Account is already configured",
|
||||
|
@ -224,6 +224,9 @@ def gen_strings_schema(config: Config, integration: Integration):
|
||||
),
|
||||
slug_validator=vol.Any("_", cv.slug),
|
||||
),
|
||||
vol.Optional("application_credentials"): {
|
||||
vol.Optional("description"): cv.string_with_no_html,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -701,7 +701,11 @@ async def test_websocket_integration_list(ws_client: ClientFixture):
|
||||
"homeassistant.loader.APPLICATION_CREDENTIALS", ["example1", "example2"]
|
||||
):
|
||||
assert await client.cmd_result("config") == {
|
||||
"domains": ["example1", "example2"]
|
||||
"domains": ["example1", "example2"],
|
||||
"integrations": {
|
||||
"example1": {},
|
||||
"example2": {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user