mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove leftovers of Huawei LTE YAML config support (#68728)
This commit is contained in:
parent
33371bdd20
commit
066128a53c
@ -19,11 +19,10 @@ from huawei_lte_api.exceptions import (
|
|||||||
ResponseErrorNotSupportedException,
|
ResponseErrorNotSupportedException,
|
||||||
)
|
)
|
||||||
from requests.exceptions import Timeout
|
from requests.exceptions import Timeout
|
||||||
from url_normalize import url_normalize
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
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 (
|
from homeassistant.const import (
|
||||||
ATTR_HW_VERSION,
|
ATTR_HW_VERSION,
|
||||||
ATTR_MODEL,
|
ATTR_MODEL,
|
||||||
@ -300,50 +299,13 @@ class HuaweiLteData(NamedTuple):
|
|||||||
"""Shared state."""
|
"""Shared state."""
|
||||||
|
|
||||||
hass_config: ConfigType
|
hass_config: ConfigType
|
||||||
# Our YAML config, keyed by router URL
|
|
||||||
config: dict[str, dict[str, Any]]
|
|
||||||
routers: dict[str, Router]
|
routers: dict[str, Router]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry( # noqa: C901
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
|
||||||
) -> bool:
|
|
||||||
"""Set up Huawei LTE component from config entry."""
|
"""Set up Huawei LTE component from config entry."""
|
||||||
url = entry.data[CONF_URL]
|
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:
|
def get_connection() -> Connection:
|
||||||
"""Set up a connection."""
|
"""Set up a connection."""
|
||||||
if entry.options.get(CONF_UNAUTHENTICATED_MODE):
|
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
|
# https://github.com/quandyfactory/dicttoxml/issues/60
|
||||||
logging.getLogger("dicttoxml").setLevel(logging.WARNING)
|
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:
|
if DOMAIN not in hass.data:
|
||||||
hass.data[DOMAIN] = HuaweiLteData(
|
hass.data[DOMAIN] = HuaweiLteData(hass_config=config, routers={})
|
||||||
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
|
|
||||||
|
|
||||||
def service_handler(service: ServiceCall) -> None:
|
def service_handler(service: ServiceCall) -> None:
|
||||||
"""
|
"""
|
||||||
@ -580,19 +536,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
schema=SERVICE_SCHEMA,
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -612,6 +555,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
data[CONF_MAC] = []
|
data[CONF_MAC] = []
|
||||||
hass.config_entries.async_update_entry(config_entry, data=data)
|
hass.config_entries.async_update_entry(config_entry, data=data)
|
||||||
_LOGGER.info("Migrated config entry to version %d", config_entry.version)
|
_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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,12 +89,6 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors=errors or {},
|
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(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user