From 066128a53cf5301e9d8fe069334251d38502d41a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Date: Mon, 28 Mar 2022 18:24:13 +0300
Subject: [PATCH] Remove leftovers of Huawei LTE YAML config support (#68728)

---
 .../components/huawei_lte/__init__.py         | 66 ++-----------------
 .../components/huawei_lte/config_flow.py      |  6 --
 2 files changed, 6 insertions(+), 66 deletions(-)

diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py
index 6f1eb6c7a60..ca15731641d 100644
--- a/homeassistant/components/huawei_lte/__init__.py
+++ b/homeassistant/components/huawei_lte/__init__.py
@@ -19,11 +19,10 @@ from huawei_lte_api.exceptions import (
     ResponseErrorNotSupportedException,
 )
 from requests.exceptions import Timeout
-from url_normalize import url_normalize
 import voluptuous as vol
 
 from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
-from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
+from homeassistant.config_entries import ConfigEntry
 from homeassistant.const import (
     ATTR_HW_VERSION,
     ATTR_MODEL,
@@ -300,50 +299,13 @@ class HuaweiLteData(NamedTuple):
     """Shared state."""
 
     hass_config: ConfigType
-    # Our YAML config, keyed by router URL
-    config: dict[str, dict[str, Any]]
     routers: dict[str, Router]
 
 
-async def async_setup_entry(  # noqa: C901
-    hass: HomeAssistant, entry: ConfigEntry
-) -> bool:
+async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
     """Set up Huawei LTE component from config entry."""
     url = entry.data[CONF_URL]
 
-    # Override settings from YAML config, but only if they're changed in it
-    # Old values are stored as *_from_yaml in the config entry
-    if yaml_config := hass.data[DOMAIN].config.get(url):
-        # Config values
-        new_data = {}
-        for key in CONF_USERNAME, CONF_PASSWORD:
-            if key in yaml_config:
-                value = yaml_config[key]
-                if value != entry.data.get(f"{key}_from_yaml"):
-                    new_data[f"{key}_from_yaml"] = value
-                    new_data[key] = value
-        # Options
-        new_options = {}
-        yaml_recipient = yaml_config.get(NOTIFY_DOMAIN, {}).get(CONF_RECIPIENT)
-        if yaml_recipient is not None and yaml_recipient != entry.options.get(
-            f"{CONF_RECIPIENT}_from_yaml"
-        ):
-            new_options[f"{CONF_RECIPIENT}_from_yaml"] = yaml_recipient
-            new_options[CONF_RECIPIENT] = yaml_recipient
-        yaml_notify_name = yaml_config.get(NOTIFY_DOMAIN, {}).get(CONF_NAME)
-        if yaml_notify_name is not None and yaml_notify_name != entry.options.get(
-            f"{CONF_NAME}_from_yaml"
-        ):
-            new_options[f"{CONF_NAME}_from_yaml"] = yaml_notify_name
-            new_options[CONF_NAME] = yaml_notify_name
-        # Update entry if overrides were found
-        if new_data or new_options:
-            hass.config_entries.async_update_entry(
-                entry,
-                data={**entry.data, **new_data},
-                options={**entry.options, **new_options},
-            )
-
     def get_connection() -> Connection:
         """Set up a connection."""
         if entry.options.get(CONF_UNAUTHENTICATED_MODE):
@@ -512,14 +474,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
     # https://github.com/quandyfactory/dicttoxml/issues/60
     logging.getLogger("dicttoxml").setLevel(logging.WARNING)
 
-    # Arrange our YAML config to dict with normalized URLs as keys
-    domain_config: dict[str, dict[str, Any]] = {}
     if DOMAIN not in hass.data:
-        hass.data[DOMAIN] = HuaweiLteData(
-            hass_config=config, config=domain_config, routers={}
-        )
-    for router_config in config.get(DOMAIN, []):
-        domain_config[url_normalize(router_config.pop(CONF_URL))] = router_config
+        hass.data[DOMAIN] = HuaweiLteData(hass_config=config, routers={})
 
     def service_handler(service: ServiceCall) -> None:
         """
@@ -580,19 +536,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
             schema=SERVICE_SCHEMA,
         )
 
-    for url, router_config in domain_config.items():
-        hass.async_create_task(
-            hass.config_entries.flow.async_init(
-                DOMAIN,
-                context={"source": SOURCE_IMPORT},
-                data={
-                    CONF_URL: url,
-                    CONF_USERNAME: router_config.get(CONF_USERNAME),
-                    CONF_PASSWORD: router_config.get(CONF_PASSWORD),
-                },
-            )
-        )
-
     return True
 
 
@@ -612,6 +555,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
         data[CONF_MAC] = []
         hass.config_entries.async_update_entry(config_entry, data=data)
         _LOGGER.info("Migrated config entry to version %d", config_entry.version)
+    # There can be no longer needed *_from_yaml data and options things left behind
+    # from pre-2022.4ish; they can be removed while at it when/if we eventually bump and
+    # migrate to version > 3 for some other reason.
     return True
 
 
diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py
index e8a02db4f1c..f4ea7cd86f7 100644
--- a/homeassistant/components/huawei_lte/config_flow.py
+++ b/homeassistant/components/huawei_lte/config_flow.py
@@ -89,12 +89,6 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
             errors=errors or {},
         )
 
-    async def async_step_import(
-        self, user_input: dict[str, Any] | None = None
-    ) -> FlowResult:
-        """Handle import initiated config flow."""
-        return await self.async_step_user(user_input)
-
     async def async_step_user(
         self, user_input: dict[str, Any] | None = None
     ) -> FlowResult: