mirror of https://github.com/home-assistant/core
Add SENZ application credentials platform (#72338)
This commit is contained in:
parent
9763b44357
commit
dc76cce96b
|
@ -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,6 +32,8 @@ UPDATE_INTERVAL = timedelta(seconds=30)
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
|
@ -37,6 +42,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
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(
|
||||
hass,
|
||||
config_entry_oauth2_flow.LocalOAuth2Implementation(
|
||||
await async_import_client_credential(
|
||||
hass,
|
||||
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
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ APPLICATION_CREDENTIALS = [
|
|||
"home_connect",
|
||||
"neato",
|
||||
"netatmo",
|
||||
"senz",
|
||||
"spotify",
|
||||
"withings",
|
||||
"xbox",
|
||||
|
|
|
@ -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"},
|
||||
},
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue