Add SENZ application credentials platform (#72338)

This commit is contained in:
Allen Porter 2022-05-23 05:44:45 -07:00 committed by GitHub
parent 9763b44357
commit dc76cce96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 18 deletions

View File

@ -4,10 +4,14 @@ from __future__ import annotations
from datetime import timedelta
import logging
from aiosenz import AUTHORIZATION_ENDPOINT, SENZAPI, TOKEN_ENDPOINT, Thermostat
from aiosenz import SENZAPI, Thermostat
from httpx import RequestError
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
@ -20,7 +24,6 @@ from homeassistant.helpers import (
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from . import config_flow
from .api import SENZConfigEntryAuth
from .const import DOMAIN
@ -29,14 +32,17 @@ UPDATE_INTERVAL = timedelta(seconds=30)
_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,
)
@ -52,17 +58,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],
AUTHORIZATION_ENDPOINT,
TOKEN_ENDPOINT,
),
)
_LOGGER.warning(
"Configuration of SENZ 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 senz."""
from aiosenz import AUTHORIZATION_ENDPOINT, TOKEN_ENDPOINT
from homeassistant.components.application_credentials import AuthorizationServer
from homeassistant.core import HomeAssistant
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
"""Return authorization server."""
return AuthorizationServer(
authorize_url=AUTHORIZATION_ENDPOINT,
token_url=TOKEN_ENDPOINT,
)

View File

@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/senz",
"requirements": ["aiosenz==1.0.0"],
"dependencies": ["auth"],
"dependencies": ["application_credentials"],
"codeowners": ["@milanmeu"],
"iot_class": "cloud_polling"
}

View File

@ -11,6 +11,7 @@ APPLICATION_CREDENTIALS = [
"home_connect",
"neato",
"netatmo",
"senz",
"spotify",
"withings",
"xbox",

View File

@ -24,7 +24,6 @@ async def test_full_flow(
"senz",
{
"senz": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
"http": {"base_url": "https://example.com"},
},
)