diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index c14fb465731..1fe85f180da 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -16,14 +16,9 @@ from aiohttp.hdrs import METH_POST from aiohttp.web import Request, Response from aiowithings import NotificationCategory, WithingsClient from aiowithings.util import to_enum -import voluptuous as vol from yarl import URL from homeassistant.components import cloud -from homeassistant.components.application_credentials import ( - ClientCredential, - async_import_client_credential, -) from homeassistant.components.http import HomeAssistantView from homeassistant.components.webhook import ( async_generate_id as webhook_generate_id, @@ -34,25 +29,20 @@ from homeassistant.components.webhook import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_ACCESS_TOKEN, - CONF_CLIENT_ID, - CONF_CLIENT_SECRET, CONF_TOKEN, CONF_WEBHOOK_ID, EVENT_HOMEASSISTANT_STOP, Platform, ) -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant -from homeassistant.helpers import config_validation as cv +from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.config_entry_oauth2_flow import ( OAuth2Session, async_get_config_entry_implementation, ) from homeassistant.helpers.event import async_call_later -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from homeassistant.helpers.typing import ConfigType -from .const import CONF_PROFILES, CONF_USE_WEBHOOK, DEFAULT_TITLE, DOMAIN, LOGGER +from .const import DEFAULT_TITLE, DOMAIN, LOGGER from .coordinator import ( WithingsActivityDataUpdateCoordinator, WithingsBedPresenceDataUpdateCoordinator, @@ -65,67 +55,11 @@ from .coordinator import ( PLATFORMS = [Platform.BINARY_SENSOR, Platform.CALENDAR, Platform.SENSOR] -CONFIG_SCHEMA = vol.Schema( - { - DOMAIN: vol.All( - cv.deprecated(CONF_PROFILES), - cv.deprecated(CONF_CLIENT_ID), - cv.deprecated(CONF_CLIENT_SECRET), - vol.Schema( - { - vol.Optional(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(min=1)), - vol.Optional(CONF_CLIENT_SECRET): vol.All( - cv.string, vol.Length(min=1) - ), - vol.Optional(CONF_USE_WEBHOOK): cv.boolean, - vol.Optional(CONF_PROFILES): vol.All( - cv.ensure_list, - vol.Unique(), - vol.Length(min=1), - [vol.All(cv.string, vol.Length(min=1))], - ), - } - ), - ) - }, - extra=vol.ALLOW_EXTRA, -) SUBSCRIBE_DELAY = timedelta(seconds=5) UNSUBSCRIBE_DELAY = timedelta(seconds=1) CONF_CLOUDHOOK_URL = "cloudhook_url" -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the Withings component.""" - - if conf := config.get(DOMAIN): - async_create_issue( - hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.4.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": "Withings", - }, - ) - if CONF_CLIENT_ID in conf: - await async_import_client_credential( - hass, - DOMAIN, - ClientCredential( - conf[CONF_CLIENT_ID], - conf[CONF_CLIENT_SECRET], - ), - ) - - return True - - @dataclass(slots=True) class WithingsData: """Dataclass to hold withings domain data.""" diff --git a/homeassistant/components/withings/config_flow.py b/homeassistant/components/withings/config_flow.py index 1b92f23685f..aee25da507c 100644 --- a/homeassistant/components/withings/config_flow.py +++ b/homeassistant/components/withings/config_flow.py @@ -13,7 +13,7 @@ from homeassistant.config_entries import ConfigEntry, ConfigFlowResult from homeassistant.const import CONF_TOKEN, CONF_WEBHOOK_ID from homeassistant.helpers import config_entry_oauth2_flow -from .const import CONF_USE_WEBHOOK, DEFAULT_TITLE, DOMAIN +from .const import DEFAULT_TITLE, DOMAIN class WithingsFlowHandler( @@ -71,7 +71,6 @@ class WithingsFlowHandler( return self.async_create_entry( title=DEFAULT_TITLE, data={**data, CONF_WEBHOOK_ID: async_generate_id()}, - options={CONF_USE_WEBHOOK: False}, ) if self.reauth_entry.unique_id == user_id: diff --git a/homeassistant/components/withings/const.py b/homeassistant/components/withings/const.py index a87fc8bfe83..91a7b9d9450 100644 --- a/homeassistant/components/withings/const.py +++ b/homeassistant/components/withings/const.py @@ -5,8 +5,6 @@ import logging LOGGER = logging.getLogger(__package__) DEFAULT_TITLE = "Withings" -CONF_PROFILES = "profiles" -CONF_USE_WEBHOOK = "use_webhook" DOMAIN = "withings" diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index eb089f44216..ff0a098a7cb 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -2,7 +2,7 @@ from datetime import timedelta from typing import Any -from unittest.mock import AsyncMock, MagicMock, patch +from unittest.mock import AsyncMock, patch from urllib.parse import urlparse from aiohttp.hdrs import METH_HEAD @@ -13,15 +13,13 @@ from aiowithings import ( ) from freezegun.api import FrozenDateTimeFactory import pytest -import voluptuous as vol from homeassistant import config_entries from homeassistant.components import cloud from homeassistant.components.cloud import CloudNotAvailable from homeassistant.components.webhook import async_generate_url -from homeassistant.components.withings import CONFIG_SCHEMA, async_setup -from homeassistant.components.withings.const import CONF_USE_WEBHOOK, DOMAIN -from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_WEBHOOK_ID +from homeassistant.components.withings.const import DOMAIN +from homeassistant.const import CONF_WEBHOOK_ID from homeassistant.core import HomeAssistant from homeassistant.util import dt as dt_util @@ -37,87 +35,6 @@ from tests.components.cloud import mock_cloud from tests.typing import ClientSessionGenerator -def config_schema_validate(withings_config) -> dict: - """Assert a schema config succeeds.""" - hass_config = {DOMAIN: withings_config} - - return CONFIG_SCHEMA(hass_config) - - -def config_schema_assert_fail(withings_config) -> None: - """Assert a schema config will fail.""" - with pytest.raises(vol.MultipleInvalid): - config_schema_validate(withings_config) - - -def test_config_schema_basic_config() -> None: - """Test schema.""" - config_schema_validate( - { - CONF_CLIENT_ID: "my_client_id", - CONF_CLIENT_SECRET: "my_client_secret", - CONF_USE_WEBHOOK: True, - } - ) - - -def test_config_schema_client_id() -> None: - """Test schema.""" - config_schema_assert_fail( - {CONF_CLIENT_SECRET: "my_client_secret", CONF_CLIENT_ID: ""} - ) - config_schema_validate( - {CONF_CLIENT_SECRET: "my_client_secret", CONF_CLIENT_ID: "my_client_id"} - ) - - -def test_config_schema_client_secret() -> None: - """Test schema.""" - config_schema_assert_fail({CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: ""}) - config_schema_validate( - {CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: "my_client_secret"} - ) - - -def test_config_schema_use_webhook() -> None: - """Test schema.""" - config_schema_validate( - {CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: "my_client_secret"} - ) - config = config_schema_validate( - { - CONF_CLIENT_ID: "my_client_id", - CONF_CLIENT_SECRET: "my_client_secret", - CONF_USE_WEBHOOK: True, - } - ) - assert config[DOMAIN][CONF_USE_WEBHOOK] is True - config = config_schema_validate( - { - CONF_CLIENT_ID: "my_client_id", - CONF_CLIENT_SECRET: "my_client_secret", - CONF_USE_WEBHOOK: False, - } - ) - assert config[DOMAIN][CONF_USE_WEBHOOK] is False - config_schema_assert_fail( - { - CONF_CLIENT_ID: "my_client_id", - CONF_CLIENT_SECRET: "my_client_secret", - CONF_USE_WEBHOOK: "A", - } - ) - - -async def test_async_setup_no_config(hass: HomeAssistant) -> None: - """Test method.""" - hass.async_create_task = MagicMock() - - await async_setup(hass, {}) - - hass.async_create_task.assert_not_called() - - async def test_data_manager_webhook_subscription( hass: HomeAssistant, withings: AsyncMock,