Standardize import step variable name (part 1) (#124674)

This commit is contained in:
epenet 2024-08-27 10:34:47 +02:00 committed by GitHub
parent 715f4bd2c3
commit 831a1d7ad1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 81 additions and 83 deletions

View file

@ -37,12 +37,12 @@ class DemoConfigFlow(ConfigFlow, domain=DOMAIN):
"""Get the options flow for this handler."""
return OptionsFlowHandler(config_entry)
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Set the config entry up from yaml."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
return self.async_create_entry(title="Demo", data=import_info)
return self.async_create_entry(title="Demo", data=import_data)
class OptionsFlowHandler(OptionsFlow):

View file

@ -43,13 +43,13 @@ class DownloaderConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle a flow initiated by configuration file."""
try:
await self._validate_input(user_input)
await self._validate_input(import_data)
except DirectoryDoesNotExist:
return self.async_abort(reason="directory_does_not_exist")
return self.async_create_entry(title=DEFAULT_NAME, data=user_input)
return self.async_create_entry(title=DEFAULT_NAME, data=import_data)
async def _validate_input(self, user_input: dict[str, Any]) -> None:
"""Validate the user input if the directory exists."""

View file

@ -26,9 +26,9 @@ class DynaliteFlowHandler(ConfigFlow, domain=DOMAIN):
"""Initialize the Dynalite flow."""
self.host = None
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import a new bridge as a config entry."""
LOGGER.debug("Starting async_step_import (deprecated) - %s", import_info)
LOGGER.debug("Starting async_step_import (deprecated) - %s", import_data)
# Raise an issue that this is deprecated and has been imported
async_create_issue(
self.hass,
@ -46,17 +46,17 @@ class DynaliteFlowHandler(ConfigFlow, domain=DOMAIN):
},
)
host = import_info[CONF_HOST]
host = import_data[CONF_HOST]
# Check if host already exists
for entry in self._async_current_entries():
if entry.data[CONF_HOST] == host:
self.hass.config_entries.async_update_entry(
entry, data=dict(import_info)
entry, data=dict(import_data)
)
return self.async_abort(reason="already_configured")
# New entry
return await self._try_create(import_info)
return await self._try_create(import_data)
async def async_step_user(
self, user_input: dict[str, Any] | None = None

View file

@ -335,10 +335,10 @@ class Elkm1ConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle import."""
_LOGGER.debug("Elk is importing from yaml")
url = _make_url_from_data(user_input)
url = _make_url_from_data(import_data)
if self._url_already_configured(url):
return self.async_abort(reason="address_already_configured")
@ -357,7 +357,7 @@ class Elkm1ConfigFlow(ConfigFlow, domain=DOMAIN):
)
self._abort_if_unique_id_configured()
errors, result = await self._async_create_or_error(user_input, True)
errors, result = await self._async_create_or_error(import_data, True)
if errors:
return self.async_abort(reason=list(errors.values())[0])
assert result is not None

View file

@ -152,20 +152,20 @@ class Enigma2ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
)
return self.async_create_entry(data=user_input, title=user_input[CONF_HOST])
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle the import step."""
if CONF_PORT not in user_input:
user_input[CONF_PORT] = DEFAULT_PORT
if CONF_SSL not in user_input:
user_input[CONF_SSL] = DEFAULT_SSL
user_input[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL
if CONF_PORT not in import_data:
import_data[CONF_PORT] = DEFAULT_PORT
if CONF_SSL not in import_data:
import_data[CONF_SSL] = DEFAULT_SSL
import_data[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL
data = {key: user_input[key] for key in user_input if key in self.DATA_KEYS}
data = {key: import_data[key] for key in import_data if key in self.DATA_KEYS}
options = {
key: user_input[key] for key in user_input if key in self.OPTIONS_KEYS
key: import_data[key] for key in import_data if key in self.OPTIONS_KEYS
}
if errors := await self.validate_user_input(user_input):
if errors := await self.validate_user_input(import_data):
async_create_issue(
self.hass,
DOMAIN,

View file

@ -115,10 +115,10 @@ class FeedReaderConfigFlow(ConfigFlow, domain=DOMAIN):
options={CONF_MAX_ENTRIES: self._max_entries or DEFAULT_MAX_ENTRIES},
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle an import flow."""
self._max_entries = user_input[CONF_MAX_ENTRIES]
return await self.async_step_user({CONF_URL: user_input[CONF_URL]})
self._max_entries = import_data[CONF_MAX_ENTRIES]
return await self.async_step_user({CONF_URL: import_data[CONF_URL]})
async def async_step_reconfigure(
self, _: dict[str, Any] | None = None

View file

@ -93,6 +93,6 @@ class OAuth2FlowHandler(
self._abort_if_unique_id_configured()
return self.async_create_entry(title=profile.display_name, data=data)
async def async_step_import(self, data: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle import from YAML."""
return await self.async_oauth_create_entry(data)
return await self.async_oauth_create_entry(import_data)

View file

@ -124,12 +124,12 @@ class GeniusHubConfigFlow(ConfigFlow, domain=DOMAIN):
step_id="cloud_api", errors=errors, data_schema=CLOUD_API_SCHEMA
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import the yaml config."""
if CONF_HOST in user_input:
result = await self.async_step_local_api(user_input)
if CONF_HOST in import_data:
result = await self.async_step_local_api(import_data)
else:
result = await self.async_step_cloud_api(user_input)
result = await self.async_step_cloud_api(import_data)
if result["type"] is FlowResultType.FORM:
assert result["errors"]
return self.async_abort(reason=result["errors"]["base"])

View file

@ -94,7 +94,7 @@ class OAuth2FlowHandler(
"prompt": "consent",
}
async def async_step_import(self, info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import existing auth into a new config entry."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
@ -103,8 +103,8 @@ class OAuth2FlowHandler(
)
assert len(implementations) == 1
self.flow_impl = list(implementations.values())[0]
self.external_data = info
return await super().async_step_creation(info)
self.external_data = import_data
return await super().async_step_creation(import_data)
async def async_step_auth(
self, user_input: dict[str, Any] | None = None

View file

@ -311,12 +311,12 @@ class HomeKitConfigFlow(ConfigFlow, domain=DOMAIN):
title=f"{name}:{entry_data[CONF_PORT]}", data=entry_data
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle import from yaml."""
if not self._async_is_unique_name_port(user_input):
if not self._async_is_unique_name_port(import_data):
return self.async_abort(reason="port_name_in_use")
return self.async_create_entry(
title=f"{user_input[CONF_NAME]}:{user_input[CONF_PORT]}", data=user_input
title=f"{import_data[CONF_NAME]}:{import_data[CONF_PORT]}", data=import_data
)
@callback

View file

@ -83,11 +83,11 @@ class HomematicipCloudFlowHandler(ConfigFlow, domain=DOMAIN):
return self.async_show_form(step_id="link", errors=errors)
async def async_step_import(self, import_info: dict[str, str]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, str]) -> ConfigFlowResult:
"""Import a new access point as a config entry."""
hapid = import_info[HMIPC_HAPID].replace("-", "").upper()
authtoken = import_info[HMIPC_AUTHTOKEN]
name = import_info[HMIPC_NAME]
hapid = import_data[HMIPC_HAPID].replace("-", "").upper()
authtoken = import_data[HMIPC_AUTHTOKEN]
name = import_data[HMIPC_NAME]
await self.async_set_unique_id(hapid)
self._abort_if_unique_id_configured()

View file

@ -258,7 +258,7 @@ class HueFlowHandler(ConfigFlow, domain=DOMAIN):
await self._async_handle_discovery_without_unique_id()
return await self.async_step_link()
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import a new bridge as a config entry.
This flow is triggered by `async_setup` for both configured and
@ -268,9 +268,9 @@ class HueFlowHandler(ConfigFlow, domain=DOMAIN):
This flow is also triggered by `async_step_discovery`.
"""
# Check if host exists, abort if so.
self._async_abort_entries_match({"host": import_info["host"]})
self._async_abort_entries_match({"host": import_data["host"]})
bridge = await self._get_bridge(import_info["host"])
bridge = await self._get_bridge(import_data["host"])
if bridge is None:
return self.async_abort(reason="cannot_connect")
self.bridge = bridge

View file

@ -34,12 +34,12 @@ class KitchenSinkConfigFlow(ConfigFlow, domain=DOMAIN):
"""Get the options flow for this handler."""
return OptionsFlowHandler(config_entry)
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Set the config entry up from yaml."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
return self.async_create_entry(title="Kitchen Sink", data=import_info)
return self.async_create_entry(title="Kitchen Sink", data=import_data)
async def async_step_reauth(self, data):
"""Reauth step."""

View file

@ -68,11 +68,11 @@ class LGNetCast(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, config: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import configuration from yaml."""
self.device_config = {
CONF_HOST: config[CONF_HOST],
CONF_NAME: config[CONF_NAME],
CONF_HOST: import_data[CONF_HOST],
CONF_NAME: import_data[CONF_NAME],
}
def _create_issue():
@ -92,7 +92,7 @@ class LGNetCast(config_entries.ConfigFlow, domain=DOMAIN):
)
try:
result: ConfigFlowResult = await self.async_step_authorize(config)
result: ConfigFlowResult = await self.async_step_authorize(import_data)
except AbortFlow as err:
if err.reason != "already_configured":
async_create_issue(

View file

@ -19,7 +19,6 @@ from homeassistant.helpers.selector import (
TextSelectorConfig,
TextSelectorType,
)
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import slugify
from .const import CONF_BASE_URL, DEFAULT_URL, DOMAIN, LOGGER
@ -126,17 +125,17 @@ class MastodonConfigFlow(ConfigFlow, domain=DOMAIN):
return self.show_user_form(user_input, errors)
async def async_step_import(self, import_config: ConfigType) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import a config entry from configuration.yaml."""
errors: dict[str, str] | None = None
LOGGER.debug("Importing Mastodon from configuration.yaml")
base_url = str(import_config.get(CONF_BASE_URL, DEFAULT_URL))
client_id = str(import_config.get(CONF_CLIENT_ID))
client_secret = str(import_config.get(CONF_CLIENT_SECRET))
access_token = str(import_config.get(CONF_ACCESS_TOKEN))
name = import_config.get(CONF_NAME, None)
base_url = str(import_data.get(CONF_BASE_URL, DEFAULT_URL))
client_id = str(import_data.get(CONF_CLIENT_ID))
client_secret = str(import_data.get(CONF_CLIENT_SECRET))
access_token = str(import_data.get(CONF_ACCESS_TOKEN))
name = import_data.get(CONF_NAME)
instance, account, errors = await self.hass.async_add_executor_job(
self.check_connection,

View file

@ -82,15 +82,15 @@ class TOTPConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import config from yaml."""
await self.async_set_unique_id(import_info[CONF_TOKEN])
await self.async_set_unique_id(import_data[CONF_TOKEN])
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=import_info.get(CONF_NAME, DEFAULT_NAME),
data=import_info,
title=import_data.get(CONF_NAME, DEFAULT_NAME),
data=import_data,
)
async def async_step_confirm(

View file

@ -133,16 +133,16 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, import_info: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import config from yaml."""
config = {
CONF_NAME: import_info.get(CONF_NAME),
CONF_HOST: import_info.get(CONF_HOST, DEFAULT_HOST),
CONF_PASSWORD: import_info.get(CONF_PASSWORD, ""),
CONF_PORT: import_info.get(CONF_PORT, DEFAULT_PORT),
CONF_SSL: import_info.get(CONF_SSL, False),
CONF_USERNAME: import_info.get(CONF_USERNAME, ""),
CONF_NAME: import_data.get(CONF_NAME),
CONF_HOST: import_data.get(CONF_HOST, DEFAULT_HOST),
CONF_PASSWORD: import_data.get(CONF_PASSWORD, ""),
CONF_PORT: import_data.get(CONF_PORT, DEFAULT_PORT),
CONF_SSL: import_data.get(CONF_SSL, False),
CONF_USERNAME: import_data.get(CONF_USERNAME, ""),
CONF_VERIFY_SSL: False,
}

View file

@ -60,11 +60,11 @@ class RovaConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import the yaml config."""
zip_code = user_input[CONF_ZIP_CODE]
number = user_input[CONF_HOUSE_NUMBER]
suffix = user_input[CONF_HOUSE_NUMBER_SUFFIX]
zip_code = import_data[CONF_ZIP_CODE]
number = import_data[CONF_HOUSE_NUMBER]
suffix = import_data[CONF_HOUSE_NUMBER_SUFFIX]
await self.async_set_unique_id(f"{zip_code}{number}{suffix}".strip())
self._abort_if_unique_id_configured()

View file

@ -101,14 +101,14 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
errors=self._errors,
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import a config entry."""
user_input = {
CONF_HOST: DEFAULT_HOST,
CONF_NAME: DEFAULT_NAME,
"extended_data": False,
**user_input,
**import_data,
}
user_input[CONF_HOST] = self._parse_url(user_input[CONF_HOST])

View file

@ -23,6 +23,6 @@ class SunConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_show_form(step_id="user")
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle import from configuration.yaml."""
return await self.async_step_user(user_input)
return await self.async_step_user(import_data)

View file

@ -15,7 +15,6 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.typing import ConfigType
from .const import _LOGGER, DOMAIN, VENSTAR_TIMEOUT
@ -85,7 +84,7 @@ class VenstarConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, import_data: ConfigType) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import entry from configuration.yaml."""
self._async_abort_entries_match({CONF_HOST: import_data[CONF_HOST]})
return await self.async_step_user(

View file

@ -127,7 +127,7 @@ class VeraFlowHandler(ConfigFlow, domain=DOMAIN):
),
)
async def async_step_import(self, config: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle a flow initialized by import."""
# If there are entities with the legacy unique_id, then this imported config
@ -146,7 +146,7 @@ class VeraFlowHandler(ConfigFlow, domain=DOMAIN):
return await self.async_step_finish(
{
**config,
**import_data,
CONF_SOURCE: SOURCE_IMPORT,
CONF_LEGACY_UNIQUE_ID: use_legacy_unique_id,
}

View file

@ -366,7 +366,7 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
"""Return the options flow."""
return OptionsFlowHandler(config_entry)
async def async_step_import(self, data: dict[str, Any]) -> ConfigFlowResult:
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle imported data.
This step will be used when importing data
@ -374,8 +374,8 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN):
"""
# Note that the data comes from the zwave integration.
# So we don't use our constants here.
self.s0_legacy_key = data.get("network_key")
self.usb_path = data.get("usb_path")
self.s0_legacy_key = import_data.get("network_key")
self.usb_path = import_data.get("usb_path")
return await self.async_step_user()
async def async_step_user(