From 7dffc9f51521d2e9c6f2d019d42e29b51ea63153 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 16 Jan 2024 22:17:18 +0100 Subject: [PATCH] Remove config import from netatmo (#107972) * Remove config import from netatmo * Fix tests --- homeassistant/components/netatmo/__init__.py | 63 +------------------- tests/components/netatmo/conftest.py | 20 +++++++ tests/components/netatmo/test_config_flow.py | 24 +------- 3 files changed, 26 insertions(+), 81 deletions(-) diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py index 4535805915b..c514e7b890d 100644 --- a/homeassistant/components/netatmo/__init__.py +++ b/homeassistant/components/netatmo/__init__.py @@ -8,26 +8,16 @@ from typing import Any import aiohttp import pyatmo -import voluptuous as vol from homeassistant.components import cloud -from homeassistant.components.application_credentials import ( - ClientCredential, - async_import_client_credential, -) from homeassistant.components.webhook import ( async_generate_url as webhook_generate_url, async_register as webhook_register, async_unregister as webhook_unregister, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - CONF_CLIENT_ID, - CONF_CLIENT_SECRET, - CONF_WEBHOOK_ID, - EVENT_HOMEASSISTANT_STOP, -) -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant +from homeassistant.const import CONF_WEBHOOK_ID, EVENT_HOMEASSISTANT_STOP +from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import ( aiohttp_client, @@ -36,7 +26,6 @@ from homeassistant.helpers import ( ) from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.start import async_at_started from homeassistant.helpers.typing import ConfigType @@ -61,20 +50,7 @@ from .webhook import async_handle_webhook _LOGGER = logging.getLogger(__name__) -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.config_entry_only_config_schema(DOMAIN) MAX_WEBHOOK_RETRIES = 3 @@ -90,39 +66,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: DATA_CAMERAS: {}, } - 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 Netatmo integration in YAML is deprecated and " - "will be removed in a future release; Your existing configuration " - "(including OAuth Application Credentials) have been imported into " - "the UI automatically and can be safely removed from your " - "configuration.yaml file" - ) - async_create_issue( - hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.2.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": "Netatmo", - }, - ) - return True diff --git a/tests/components/netatmo/conftest.py b/tests/components/netatmo/conftest.py index bfd7fa6a072..a21bb8aebe7 100644 --- a/tests/components/netatmo/conftest.py +++ b/tests/components/netatmo/conftest.py @@ -5,12 +5,32 @@ from unittest.mock import AsyncMock, patch from pyatmo.const import ALL_SCOPES import pytest +from homeassistant.components.application_credentials import ( + ClientCredential, + async_import_client_credential, +) +from homeassistant.components.netatmo.const import DOMAIN from homeassistant.core import HomeAssistant +from homeassistant.setup import async_setup_component from .common import fake_get_image, fake_post_request from tests.common import MockConfigEntry +CLIENT_ID = "1234" +CLIENT_SECRET = "5678" + + +@pytest.fixture(autouse=True) +async def setup_credentials(hass: HomeAssistant) -> None: + """Fixture to setup credentials.""" + assert await async_setup_component(hass, "application_credentials", {}) + await async_import_client_credential( + hass, + DOMAIN, + ClientCredential(CLIENT_ID, CLIENT_SECRET), + ) + @pytest.fixture(name="config_entry") def mock_config_entry_fixture(hass: HomeAssistant) -> MockConfigEntry: diff --git a/tests/components/netatmo/test_config_flow.py b/tests/components/netatmo/test_config_flow.py index 56d319b1631..afa9ed02645 100644 --- a/tests/components/netatmo/test_config_flow.py +++ b/tests/components/netatmo/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import patch from pyatmo.const import ALL_SCOPES -from homeassistant import config_entries, data_entry_flow, setup +from homeassistant import config_entries, data_entry_flow from homeassistant.components import zeroconf from homeassistant.components.netatmo import config_flow from homeassistant.components.netatmo.const import ( @@ -14,17 +14,15 @@ from homeassistant.components.netatmo.const import ( OAUTH2_AUTHORIZE, OAUTH2_TOKEN, ) -from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.core import HomeAssistant from homeassistant.helpers import config_entry_oauth2_flow +from .conftest import CLIENT_ID + from tests.common import MockConfigEntry from tests.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator -CLIENT_ID = "1234" -CLIENT_SECRET = "5678" - VALID_CONFIG = {} @@ -65,14 +63,6 @@ async def test_full_flow( current_request_with_host: None, ) -> None: """Check full flow.""" - assert await setup.async_setup_component( - hass, - "netatmo", - { - "netatmo": {CONF_CLIENT_ID: CLIENT_ID, CONF_CLIENT_SECRET: CLIENT_SECRET}, - "http": {"base_url": "https://example.com"}, - }, - ) result = await hass.config_entries.flow.async_init( "netatmo", context={"source": config_entries.SOURCE_USER} @@ -240,14 +230,6 @@ async def test_reauth( current_request_with_host: None, ) -> None: """Test initialization of the reauth flow.""" - assert await setup.async_setup_component( - hass, - "netatmo", - { - "netatmo": {CONF_CLIENT_ID: CLIENT_ID, CONF_CLIENT_SECRET: CLIENT_SECRET}, - "http": {"base_url": "https://example.com"}, - }, - ) result = await hass.config_entries.flow.async_init( "netatmo", context={"source": config_entries.SOURCE_USER}