Add application_credentials platform for netatmo (#71884)

This commit is contained in:
Allen Porter 2022-05-16 21:09:48 -07:00 committed by GitHub
parent 99f68ab858
commit ddecf76f6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 18 deletions

View File

@ -11,6 +11,10 @@ import pyatmo
import voluptuous as vol import voluptuous as vol
from homeassistant.components import cloud from homeassistant.components import cloud
from homeassistant.components.application_credentials import (
ClientCredential,
async_import_client_credential,
)
from homeassistant.components.webhook import ( from homeassistant.components.webhook import (
async_generate_url as webhook_generate_url, async_generate_url as webhook_generate_url,
async_register as webhook_register, 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.event import async_call_later
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from . import api, config_flow from . import api
from .const import ( from .const import (
AUTH, AUTH,
CONF_CLOUDHOOK_URL, CONF_CLOUDHOOK_URL,
@ -48,8 +52,6 @@ from .const import (
DATA_SCHEDULES, DATA_SCHEDULES,
DOMAIN, DOMAIN,
NETATMO_SCOPES, NETATMO_SCOPES,
OAUTH2_AUTHORIZE,
OAUTH2_TOKEN,
PLATFORMS, PLATFORMS,
WEBHOOK_DEACTIVATION, WEBHOOK_DEACTIVATION,
WEBHOOK_PUSH_TYPE, WEBHOOK_PUSH_TYPE,
@ -60,14 +62,17 @@ from .webhook import async_handle_webhook
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(
{ vol.All(
DOMAIN: vol.Schema( cv.deprecated(DOMAIN),
{ {
vol.Required(CONF_CLIENT_ID): cv.string, DOMAIN: vol.Schema(
vol.Required(CONF_CLIENT_SECRET): cv.string, {
} vol.Required(CONF_CLIENT_ID): cv.string,
) vol.Required(CONF_CLIENT_SECRET): cv.string,
}, }
)
},
),
extra=vol.ALLOW_EXTRA, extra=vol.ALLOW_EXTRA,
) )
@ -88,17 +93,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if DOMAIN not in config: if DOMAIN not in config:
return True return True
config_flow.NetatmoFlowHandler.async_register_implementation( await async_import_client_credential(
hass, hass,
config_entry_oauth2_flow.LocalOAuth2Implementation( DOMAIN,
hass, ClientCredential(
DOMAIN,
config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_ID],
config[DOMAIN][CONF_CLIENT_SECRET], 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 return True

View File

@ -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,
)

View File

@ -4,7 +4,7 @@
"documentation": "https://www.home-assistant.io/integrations/netatmo", "documentation": "https://www.home-assistant.io/integrations/netatmo",
"requirements": ["pyatmo==6.2.4"], "requirements": ["pyatmo==6.2.4"],
"after_dependencies": ["cloud", "media_source"], "after_dependencies": ["cloud", "media_source"],
"dependencies": ["auth", "webhook"], "dependencies": ["application_credentials", "webhook"],
"codeowners": ["@cgtobi"], "codeowners": ["@cgtobi"],
"config_flow": true, "config_flow": true,
"homekit": { "homekit": {

View File

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