mirror of
https://github.com/home-assistant/core
synced 2024-10-13 14:52:10 +02:00
Add Spotify application_credentials platform (#71871)
This commit is contained in:
parent
a70e2a33dc
commit
2613c865f7
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import aiohttp
|
||||
@ -10,6 +11,10 @@ import requests
|
||||
from spotipy import Spotify, SpotifyException
|
||||
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 (
|
||||
ATTR_CREDENTIALS,
|
||||
@ -19,7 +24,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
OAuth2Session,
|
||||
async_get_config_entry_implementation,
|
||||
@ -27,7 +32,6 @@ from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from . import config_flow
|
||||
from .browse_media import async_browse_media
|
||||
from .const import DOMAIN, LOGGER, SPOTIFY_SCOPES
|
||||
from .util import (
|
||||
@ -36,15 +40,20 @@ from .util import (
|
||||
spotify_uri_from_media_browser_url,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Inclusive(CONF_CLIENT_ID, ATTR_CREDENTIALS): cv.string,
|
||||
vol.Inclusive(CONF_CLIENT_SECRET, ATTR_CREDENTIALS): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Inclusive(CONF_CLIENT_ID, ATTR_CREDENTIALS): cv.string,
|
||||
vol.Inclusive(CONF_CLIENT_SECRET, ATTR_CREDENTIALS): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
@ -76,17 +85,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
return True
|
||||
|
||||
if CONF_CLIENT_ID in config[DOMAIN]:
|
||||
config_flow.SpotifyFlowHandler.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],
|
||||
"https://accounts.spotify.com/authorize",
|
||||
"https://accounts.spotify.com/api/token",
|
||||
),
|
||||
)
|
||||
_LOGGER.warning(
|
||||
"Configuration of Spotify 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
|
||||
|
||||
|
12
homeassistant/components/spotify/application_credentials.py
Normal file
12
homeassistant/components/spotify/application_credentials.py
Normal file
@ -0,0 +1,12 @@
|
||||
"""Application credentials platform for spotify."""
|
||||
|
||||
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="https://accounts.spotify.com/authorize",
|
||||
token_url="https://accounts.spotify.com/api/token",
|
||||
)
|
@ -4,7 +4,7 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/spotify",
|
||||
"requirements": ["spotipy==2.19.0"],
|
||||
"zeroconf": ["_spotify-connect._tcp.local."],
|
||||
"dependencies": ["auth"],
|
||||
"dependencies": ["application_credentials"],
|
||||
"codeowners": ["@frenck"],
|
||||
"config_flow": true,
|
||||
"quality_scale": "silver",
|
||||
|
@ -7,5 +7,6 @@ To update, run python3 -m script.hassfest
|
||||
|
||||
APPLICATION_CREDENTIALS = [
|
||||
"google",
|
||||
"spotify",
|
||||
"xbox"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user