From 4ffac3e7ed67948867c7e9863f688f427483f905 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 26 Sep 2023 13:16:37 +0200 Subject: [PATCH] Cleanup Withings const import (#100914) --- homeassistant/components/withings/__init__.py | 14 ++++++-------- tests/components/withings/test_init.py | 17 +++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 2e9ff462936..47c90e2b4d1 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -34,18 +34,16 @@ from homeassistant.helpers import config_entry_oauth2_flow, config_validation as from homeassistant.helpers.event import async_call_later from homeassistant.helpers.typing import ConfigType -from . import const from .api import ConfigEntryWithingsApi -from .const import CONF_USE_WEBHOOK, CONFIG, LOGGER +from .const import CONF_PROFILES, CONF_USE_WEBHOOK, CONFIG, DOMAIN, LOGGER from .coordinator import WithingsDataUpdateCoordinator -DOMAIN = const.DOMAIN PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR] CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.All( - cv.deprecated(const.CONF_PROFILES), + cv.deprecated(CONF_PROFILES), cv.deprecated(CONF_CLIENT_ID), cv.deprecated(CONF_CLIENT_SECRET), vol.Schema( @@ -54,8 +52,8 @@ CONFIG_SCHEMA = vol.Schema( vol.Optional(CONF_CLIENT_SECRET): vol.All( cv.string, vol.Length(min=1) ), - vol.Optional(const.CONF_USE_WEBHOOK): cv.boolean, - vol.Optional(const.CONF_PROFILES): vol.All( + vol.Optional(CONF_USE_WEBHOOK): cv.boolean, + vol.Optional(CONF_PROFILES): vol.All( cv.ensure_list, vol.Unique(), vol.Length(min=1), @@ -74,10 +72,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if not (conf := config.get(DOMAIN)): # Apply the defaults. conf = CONFIG_SCHEMA({DOMAIN: {}})[DOMAIN] - hass.data[DOMAIN] = {const.CONFIG: conf} + hass.data[DOMAIN] = {CONFIG: conf} return True - hass.data[DOMAIN] = {const.CONFIG: conf} + hass.data[DOMAIN] = {CONFIG: conf} # Setup the oauth2 config flow. if CONF_CLIENT_ID in conf: diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index bae6df37126..6e5c10390ff 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -11,7 +11,8 @@ from withings_api.common import AuthFailedException, NotifyAppli, UnauthorizedEx from homeassistant import config_entries from homeassistant.components.webhook import async_generate_url -from homeassistant.components.withings import CONFIG_SCHEMA, DOMAIN, async_setup, const +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.core import HomeAssistant from homeassistant.util import dt as dt_util @@ -25,7 +26,7 @@ from tests.typing import ClientSessionGenerator def config_schema_validate(withings_config) -> dict: """Assert a schema config succeeds.""" - hass_config = {const.DOMAIN: withings_config} + hass_config = {DOMAIN: withings_config} return CONFIG_SCHEMA(hass_config) @@ -42,7 +43,7 @@ def test_config_schema_basic_config() -> None: { CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: "my_client_secret", - const.CONF_USE_WEBHOOK: True, + CONF_USE_WEBHOOK: True, } ) @@ -74,23 +75,23 @@ def test_config_schema_use_webhook() -> None: { CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: "my_client_secret", - const.CONF_USE_WEBHOOK: True, + CONF_USE_WEBHOOK: True, } ) - assert config[const.DOMAIN][const.CONF_USE_WEBHOOK] is 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", - const.CONF_USE_WEBHOOK: False, + CONF_USE_WEBHOOK: False, } ) - assert config[const.DOMAIN][const.CONF_USE_WEBHOOK] is 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", - const.CONF_USE_WEBHOOK: "A", + CONF_USE_WEBHOOK: "A", } )