mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add Honeywell Lyric application credentials platform and deprecate configuration in yaml (#72335)
Add Honeywell Lyric application credentials platform and deprecate config yaml
This commit is contained in:
parent
90e5d69184
commit
f6370d0522
@ -13,6 +13,10 @@ from aiolyric.objects.location import LyricLocation
|
|||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import (
|
||||||
|
ClientCredential,
|
||||||
|
async_import_client_credential,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
|
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -36,10 +40,11 @@ from .api import (
|
|||||||
LyricLocalOAuth2Implementation,
|
LyricLocalOAuth2Implementation,
|
||||||
OAuth2SessionLyric,
|
OAuth2SessionLyric,
|
||||||
)
|
)
|
||||||
from .config_flow import OAuth2FlowHandler
|
from .const import DOMAIN
|
||||||
from .const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
|
vol.All(
|
||||||
|
cv.deprecated(DOMAIN),
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
{
|
{
|
||||||
@ -48,6 +53,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
),
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,20 +69,23 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
hass.data[DOMAIN][CONF_CLIENT_ID] = config[DOMAIN][CONF_CLIENT_ID]
|
await async_import_client_credential(
|
||||||
|
|
||||||
OAuth2FlowHandler.async_register_implementation(
|
|
||||||
hass,
|
|
||||||
LyricLocalOAuth2Implementation(
|
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
ClientCredential(
|
||||||
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 Honeywell Lyric 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
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -87,13 +96,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass, entry
|
hass, entry
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if not isinstance(implementation, LyricLocalOAuth2Implementation):
|
||||||
|
raise ValueError("Unexpected auth implementation; can't find oauth client id")
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
oauth_session = OAuth2SessionLyric(hass, entry, implementation)
|
oauth_session = OAuth2SessionLyric(hass, entry, implementation)
|
||||||
|
|
||||||
client = ConfigEntryLyricClient(session, oauth_session)
|
client = ConfigEntryLyricClient(session, oauth_session)
|
||||||
|
|
||||||
client_id = hass.data[DOMAIN][CONF_CLIENT_ID]
|
client_id = implementation.client_id
|
||||||
lyric = Lyric(client, client_id)
|
lyric = Lyric(client, client_id)
|
||||||
|
|
||||||
async def async_update_data(force_refresh_token: bool = False) -> Lyric:
|
async def async_update_data(force_refresh_token: bool = False) -> Lyric:
|
||||||
|
@ -4,6 +4,7 @@ from typing import cast
|
|||||||
from aiohttp import BasicAuth, ClientSession
|
from aiohttp import BasicAuth, ClientSession
|
||||||
from aiolyric.client import LyricClient
|
from aiolyric.client import LyricClient
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import AuthImplementation
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ class ConfigEntryLyricClient(LyricClient):
|
|||||||
|
|
||||||
|
|
||||||
class LyricLocalOAuth2Implementation(
|
class LyricLocalOAuth2Implementation(
|
||||||
config_entry_oauth2_flow.LocalOAuth2Implementation
|
AuthImplementation,
|
||||||
):
|
):
|
||||||
"""Lyric Local OAuth2 implementation."""
|
"""Lyric Local OAuth2 implementation."""
|
||||||
|
|
||||||
|
26
homeassistant/components/lyric/application_credentials.py
Normal file
26
homeassistant/components/lyric/application_credentials.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""Application credentials platform for the Honeywell Lyric integration."""
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import (
|
||||||
|
AuthorizationServer,
|
||||||
|
ClientCredential,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
|
from .api import LyricLocalOAuth2Implementation
|
||||||
|
from .const import OAUTH2_AUTHORIZE, OAUTH2_TOKEN
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_auth_implementation(
|
||||||
|
hass: HomeAssistant, auth_domain: str, credential: ClientCredential
|
||||||
|
) -> config_entry_oauth2_flow.AbstractOAuth2Implementation:
|
||||||
|
"""Return custom auth implementation."""
|
||||||
|
return LyricLocalOAuth2Implementation(
|
||||||
|
hass,
|
||||||
|
auth_domain,
|
||||||
|
credential,
|
||||||
|
AuthorizationServer(
|
||||||
|
authorize_url=OAUTH2_AUTHORIZE,
|
||||||
|
token_url=OAUTH2_TOKEN,
|
||||||
|
),
|
||||||
|
)
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Honeywell Lyric",
|
"name": "Honeywell Lyric",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/lyric",
|
"documentation": "https://www.home-assistant.io/integrations/lyric",
|
||||||
"dependencies": ["auth"],
|
"dependencies": ["application_credentials"],
|
||||||
"requirements": ["aiolyric==1.0.8"],
|
"requirements": ["aiolyric==1.0.8"],
|
||||||
"codeowners": ["@timmo001"],
|
"codeowners": ["@timmo001"],
|
||||||
"quality_scale": "silver",
|
"quality_scale": "silver",
|
||||||
|
@ -9,6 +9,7 @@ APPLICATION_CREDENTIALS = [
|
|||||||
"geocaching",
|
"geocaching",
|
||||||
"google",
|
"google",
|
||||||
"home_connect",
|
"home_connect",
|
||||||
|
"lyric",
|
||||||
"neato",
|
"neato",
|
||||||
"netatmo",
|
"netatmo",
|
||||||
"senz",
|
"senz",
|
||||||
|
@ -41,7 +41,7 @@ async def test_abort_if_no_configuration(hass):
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "missing_configuration"
|
assert result["reason"] == "missing_credentials"
|
||||||
|
|
||||||
|
|
||||||
async def test_full_flow(
|
async def test_full_flow(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user