From ddecf76f6f301f0240c012ed73adf3699ec2d6a5 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 16 May 2022 21:09:48 -0700 Subject: [PATCH] Add application_credentials platform for netatmo (#71884) --- homeassistant/components/netatmo/__init__.py | 43 +++++++++++-------- .../netatmo/application_credentials.py | 14 ++++++ .../components/netatmo/manifest.json | 2 +- .../generated/application_credentials.py | 1 + 4 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 homeassistant/components/netatmo/application_credentials.py diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py index f6e43b29653..a3a9d22e017 100644 --- a/homeassistant/components/netatmo/__init__.py +++ b/homeassistant/components/netatmo/__init__.py @@ -11,6 +11,10 @@ import pyatmo import voluptuous as vol from homeassistant.components import cloud +from homeassistant.components.application_credentials import ( + ClientCredential, + async_import_client_credential, +) from homeassistant.components.webhook import ( async_generate_url as webhook_generate_url, async_register as webhook_register, @@ -35,7 +39,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later from homeassistant.helpers.typing import ConfigType -from . import api, config_flow +from . import api from .const import ( AUTH, CONF_CLOUDHOOK_URL, @@ -48,8 +52,6 @@ from .const import ( DATA_SCHEDULES, DOMAIN, NETATMO_SCOPES, - OAUTH2_AUTHORIZE, - OAUTH2_TOKEN, PLATFORMS, WEBHOOK_DEACTIVATION, WEBHOOK_PUSH_TYPE, @@ -60,14 +62,17 @@ from .webhook import async_handle_webhook _LOGGER = logging.getLogger(__name__) 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, ) @@ -88,17 +93,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if DOMAIN not in config: return True - config_flow.NetatmoFlowHandler.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 Netatmo integration in YAML is deprecated and " + "will be removed in a future release; Your existing configuration " + "(including OAuth Application Credentials) have been imported into " + "the UI automatically and can be safely removed from your " + "configuration.yaml file" + ) return True diff --git a/homeassistant/components/netatmo/application_credentials.py b/homeassistant/components/netatmo/application_credentials.py new file mode 100644 index 00000000000..5536343ebe6 --- /dev/null +++ b/homeassistant/components/netatmo/application_credentials.py @@ -0,0 +1,14 @@ +"""Application credentials platform for Netatmo.""" + +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, + ) diff --git a/homeassistant/components/netatmo/manifest.json b/homeassistant/components/netatmo/manifest.json index 565bd42594a..2081f9bd274 100644 --- a/homeassistant/components/netatmo/manifest.json +++ b/homeassistant/components/netatmo/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://www.home-assistant.io/integrations/netatmo", "requirements": ["pyatmo==6.2.4"], "after_dependencies": ["cloud", "media_source"], - "dependencies": ["auth", "webhook"], + "dependencies": ["application_credentials", "webhook"], "codeowners": ["@cgtobi"], "config_flow": true, "homekit": { diff --git a/homeassistant/generated/application_credentials.py b/homeassistant/generated/application_credentials.py index 56340ccc44e..40f451de153 100644 --- a/homeassistant/generated/application_credentials.py +++ b/homeassistant/generated/application_credentials.py @@ -8,6 +8,7 @@ To update, run python3 -m script.hassfest APPLICATION_CREDENTIALS = [ "geocaching", "google", + "netatmo", "spotify", "xbox" ]