Add Home Connect application_credentials platform and deprecate configuration.yaml (#71988)

Add Home Connect application_credentials platform
This commit is contained in:
Allen Porter 2022-05-17 01:48:31 -07:00 committed by GitHub
parent e0154d6fb1
commit 7d26be2d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 17 deletions

View File

@ -6,6 +6,10 @@ import logging
from requests import HTTPError
import voluptuous as vol
from homeassistant.components.application_credentials import (
ClientCredential,
async_import_client_credential,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
from homeassistant.core import HomeAssistant
@ -13,22 +17,25 @@ from homeassistant.helpers import config_entry_oauth2_flow, config_validation as
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import Throttle
from . import api, config_flow
from .const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
from . import api
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(minutes=1)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
}
)
},
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
@ -42,17 +49,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if DOMAIN not in config:
return True
config_flow.OAuth2FlowHandler.async_register_implementation(
await async_import_client_credential(
hass,
config_entry_oauth2_flow.LocalOAuth2Implementation(
hass,
DOMAIN,
DOMAIN,
ClientCredential(
config[DOMAIN][CONF_CLIENT_ID],
config[DOMAIN][CONF_CLIENT_SECRET],
OAUTH2_AUTHORIZE,
OAUTH2_TOKEN,
),
)
_LOGGER.warning(
"Configuration of Home Connect integration in YAML is deprecated and "
"will be removed in a future release; Your existing OAuth "
"Application Credentials have been imported into the UI "
"automatically and can be safely removed from your "
"configuration.yaml file"
)
return True

View File

@ -0,0 +1,14 @@
"""Application credentials platform for Home Connect."""
from homeassistant.components.application_credentials import AuthorizationServer
from homeassistant.core import HomeAssistant
from .const import OAUTH2_AUTHORIZE, OAUTH2_TOKEN
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
"""Return authorization server."""
return AuthorizationServer(
authorize_url=OAUTH2_AUTHORIZE,
token_url=OAUTH2_TOKEN,
)

View File

@ -2,7 +2,7 @@
"domain": "home_connect",
"name": "Home Connect",
"documentation": "https://www.home-assistant.io/integrations/home_connect",
"dependencies": ["auth"],
"dependencies": ["application_credentials"],
"codeowners": ["@DavidMStraub"],
"requirements": ["homeconnect==0.7.0"],
"config_flow": true,

View File

@ -8,6 +8,7 @@ To update, run python3 -m script.hassfest
APPLICATION_CREDENTIALS = [
"geocaching",
"google",
"home_connect",
"netatmo",
"spotify",
"xbox",