Remove deprecated Lyric YAML configuration (#75418)

This commit is contained in:
Franck Nijhof 2022-07-19 06:13:53 +02:00 committed by GitHub
parent a9e9d7b112
commit d05160a402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 112 deletions

View file

@ -11,14 +11,9 @@ from aiolyric.exceptions import LyricAuthenticationException, LyricException
from aiolyric.objects.device import LyricDevice
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.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import (
@ -28,7 +23,6 @@ from homeassistant.helpers import (
device_registry as dr,
)
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -42,53 +36,13 @@ from .api import (
)
from .const import DOMAIN
CONFIG_SCHEMA = vol.Schema(
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,
)
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
_LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Honeywell Lyric component."""
hass.data[DOMAIN] = {}
if DOMAIN not in config:
return True
await async_import_client_credential(
hass,
DOMAIN,
ClientCredential(
config[DOMAIN][CONF_CLIENT_ID],
config[DOMAIN][CONF_CLIENT_SECRET],
),
)
_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
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Honeywell Lyric from a config entry."""
implementation = (
@ -143,10 +97,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
update_interval=timedelta(seconds=300),
)
hass.data[DOMAIN][entry.entry_id] = coordinator
# Fetch initial data so we have data when entities subscribe
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View file

@ -1,16 +1,17 @@
"""Test the Honeywell Lyric config flow."""
import asyncio
from http import HTTPStatus
from unittest.mock import patch
import pytest
from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.components.http import CONF_BASE_URL, DOMAIN as DOMAIN_HTTP
from homeassistant.components.lyric import config_flow
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.application_credentials import (
ClientCredential,
async_import_client_credential,
)
from homeassistant.components.lyric.const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@ -21,18 +22,12 @@ CLIENT_SECRET = "5678"
@pytest.fixture()
async def mock_impl(hass):
"""Mock implementation."""
await setup.async_setup_component(hass, "http", {})
await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
impl = config_entry_oauth2_flow.LocalOAuth2Implementation(
hass,
DOMAIN,
CLIENT_ID,
CLIENT_SECRET,
OAUTH2_AUTHORIZE,
OAUTH2_TOKEN,
await async_import_client_credential(
hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET), "cred"
)
config_flow.OAuth2FlowHandler.async_register_implementation(hass, impl)
return impl
async def test_abort_if_no_configuration(hass):
@ -45,21 +40,9 @@ async def test_abort_if_no_configuration(hass):
async def test_full_flow(
hass, hass_client_no_auth, aioclient_mock, current_request_with_host
hass, hass_client_no_auth, aioclient_mock, current_request_with_host, mock_impl
):
"""Check full flow."""
assert await setup.async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_CLIENT_ID: CLIENT_ID,
CONF_CLIENT_SECRET: CLIENT_SECRET,
},
DOMAIN_HTTP: {CONF_BASE_URL: "https://example.com"},
},
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
@ -98,7 +81,7 @@ async def test_full_flow(
) as mock_setup:
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["data"]["auth_implementation"] == DOMAIN
assert result["data"]["auth_implementation"] == "cred"
result["data"]["token"].pop("expires_at")
assert result["data"]["token"] == {
@ -116,42 +99,10 @@ async def test_full_flow(
assert len(mock_setup.mock_calls) == 1
async def test_abort_if_authorization_timeout(
hass, mock_impl, current_request_with_host
):
"""Check Somfy authorization timeout."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
flow = config_flow.OAuth2FlowHandler()
flow.hass = hass
with patch.object(
mock_impl, "async_generate_authorize_url", side_effect=asyncio.TimeoutError
):
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "authorize_url_timeout"
async def test_reauthentication_flow(
hass, hass_client_no_auth, aioclient_mock, current_request_with_host
hass, hass_client_no_auth, aioclient_mock, current_request_with_host, mock_impl
):
"""Test reauthentication flow."""
await setup.async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_CLIENT_ID: CLIENT_ID,
CONF_CLIENT_SECRET: CLIENT_SECRET,
},
DOMAIN_HTTP: {CONF_BASE_URL: "https://example.com"},
},
)
old_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=DOMAIN,