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:
Allen Porter 2022-05-23 11:16:21 -07:00 committed by GitHub
parent 90e5d69184
commit f6370d0522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 22 deletions

View File

@ -13,6 +13,10 @@ from aiolyric.objects.location import LyricLocation
import async_timeout
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
@ -36,10 +40,11 @@ from .api import (
LyricLocalOAuth2Implementation,
OAuth2SessionLyric,
)
from .config_flow import OAuth2FlowHandler
from .const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
from .const import DOMAIN
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
@ -48,6 +53,7 @@ CONFIG_SCHEMA = vol.Schema(
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
@ -63,20 +69,23 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if DOMAIN not in config:
return True
hass.data[DOMAIN][CONF_CLIENT_ID] = config[DOMAIN][CONF_CLIENT_ID]
OAuth2FlowHandler.async_register_implementation(
hass,
LyricLocalOAuth2Implementation(
await async_import_client_credential(
hass,
DOMAIN,
ClientCredential(
config[DOMAIN][CONF_CLIENT_ID],
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
@ -87,13 +96,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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)
oauth_session = OAuth2SessionLyric(hass, entry, implementation)
client = ConfigEntryLyricClient(session, oauth_session)
client_id = hass.data[DOMAIN][CONF_CLIENT_ID]
client_id = implementation.client_id
lyric = Lyric(client, client_id)
async def async_update_data(force_refresh_token: bool = False) -> Lyric:

View File

@ -4,6 +4,7 @@ from typing import cast
from aiohttp import BasicAuth, ClientSession
from aiolyric.client import LyricClient
from homeassistant.components.application_credentials import AuthImplementation
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -41,7 +42,7 @@ class ConfigEntryLyricClient(LyricClient):
class LyricLocalOAuth2Implementation(
config_entry_oauth2_flow.LocalOAuth2Implementation
AuthImplementation,
):
"""Lyric Local OAuth2 implementation."""

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

View File

@ -3,7 +3,7 @@
"name": "Honeywell Lyric",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lyric",
"dependencies": ["auth"],
"dependencies": ["application_credentials"],
"requirements": ["aiolyric==1.0.8"],
"codeowners": ["@timmo001"],
"quality_scale": "silver",

View File

@ -9,6 +9,7 @@ APPLICATION_CREDENTIALS = [
"geocaching",
"google",
"home_connect",
"lyric",
"neato",
"netatmo",
"senz",

View File

@ -41,7 +41,7 @@ async def test_abort_if_no_configuration(hass):
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "missing_configuration"
assert result["reason"] == "missing_credentials"
async def test_full_flow(