Standardize import step variable name (part 2) (#124679)

This commit is contained in:
epenet 2024-08-27 11:22:35 +02:00 committed by GitHub
parent 0d2f22838a
commit 6b0428774d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 73 additions and 98 deletions

View File

@ -80,11 +80,9 @@ class AirVisualProFlowHandler(ConfigFlow, domain=DOMAIN):
"""Initialize.""" """Initialize."""
self._reauth_entry: ConfigEntry | None = None self._reauth_entry: ConfigEntry | None = None
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a config entry from configuration.yaml.""" """Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config) return await self.async_step_user(import_data)
async def async_step_reauth( async def async_step_reauth(
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]

View File

@ -1,6 +1,5 @@
"""Config flow for AWS component.""" """Config flow for AWS component."""
from collections.abc import Mapping
from typing import Any from typing import Any
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
@ -13,11 +12,9 @@ class AWSFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, user_input: Mapping[str, Any]
) -> ConfigFlowResult:
"""Import a config entry.""" """Import a config entry."""
if self._async_current_entries(): if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="single_instance_allowed")
return self.async_create_entry(title="configuration.yaml", data=user_input) return self.async_create_entry(title="configuration.yaml", data=import_data)

View File

@ -154,17 +154,15 @@ class AEHConfigFlow(ConfigFlow, domain=DOMAIN):
options=self._options, options=self._options,
) )
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import config from configuration.yaml.""" """Import config from configuration.yaml."""
if self._async_current_entries(): if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="single_instance_allowed")
if CONF_SEND_INTERVAL in import_config: if CONF_SEND_INTERVAL in import_data:
self._options[CONF_SEND_INTERVAL] = import_config.pop(CONF_SEND_INTERVAL) self._options[CONF_SEND_INTERVAL] = import_data.pop(CONF_SEND_INTERVAL)
if CONF_MAX_DELAY in import_config: if CONF_MAX_DELAY in import_data:
self._options[CONF_MAX_DELAY] = import_config.pop(CONF_MAX_DELAY) self._options[CONF_MAX_DELAY] = import_data.pop(CONF_MAX_DELAY)
self._data = import_config self._data = import_data
errors = await validate_data(self._data) errors = await validate_data(self._data)
if errors: if errors:
return self.async_abort(reason=errors["base"]) return self.async_abort(reason=errors["base"])

View File

@ -19,9 +19,7 @@ class FirmataFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a firmata board as a config entry. """Import a firmata board as a config entry.
This flow is triggered by `async_setup` for configured boards. This flow is triggered by `async_setup` for configured boards.
@ -30,14 +28,14 @@ class FirmataFlowHandler(ConfigFlow, domain=DOMAIN):
config entry yet (based on entry_id). It validates a connection config entry yet (based on entry_id). It validates a connection
and then adds the entry. and then adds the entry.
""" """
name = f"serial-{import_config[CONF_SERIAL_PORT]}" name = f"serial-{import_data[CONF_SERIAL_PORT]}"
import_config[CONF_NAME] = name import_data[CONF_NAME] = name
# Connect to the board to verify connection and then shutdown # Connect to the board to verify connection and then shutdown
# If either fail then we cannot continue # If either fail then we cannot continue
_LOGGER.debug("Connecting to Firmata board %s to test connection", name) _LOGGER.debug("Connecting to Firmata board %s to test connection", name)
try: try:
api = await get_board(import_config) api = await get_board(import_data)
await api.shutdown() await api.shutdown()
except RuntimeError as err: except RuntimeError as err:
_LOGGER.error("Error connecting to PyMata board %s: %s", name, err) _LOGGER.error("Error connecting to PyMata board %s: %s", name, err)
@ -54,6 +52,4 @@ class FirmataFlowHandler(ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="cannot_connect") return self.async_abort(reason="cannot_connect")
_LOGGER.debug("Connection test to Firmata board %s successful", name) _LOGGER.debug("Connection test to Firmata board %s successful", name)
return self.async_create_entry( return self.async_create_entry(title=import_data[CONF_NAME], data=import_data)
title=import_config[CONF_NAME], data=import_config
)

View File

@ -9,6 +9,7 @@ import pypck
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.config_entries import ConfigFlowResult
from homeassistant.const import ( from homeassistant.const import (
CONF_BASE, CONF_BASE,
CONF_DEVICES, CONF_DEVICES,
@ -107,12 +108,10 @@ class LcnFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, data: ConfigType
) -> config_entries.ConfigFlowResult:
"""Import existing configuration from LCN.""" """Import existing configuration from LCN."""
# validate the imported connection parameters # validate the imported connection parameters
if error := await validate_connection(data): if error := await validate_connection(import_data):
async_create_issue( async_create_issue(
self.hass, self.hass,
DOMAIN, DOMAIN,
@ -144,17 +143,19 @@ class LcnFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
) )
# check if we already have a host with the same address configured # check if we already have a host with the same address configured
if entry := get_config_entry(self.hass, data): if entry := get_config_entry(self.hass, import_data):
entry.source = config_entries.SOURCE_IMPORT entry.source = config_entries.SOURCE_IMPORT
# Cleanup entity and device registry, if we imported from configuration.yaml to # Cleanup entity and device registry, if we imported from configuration.yaml to
# remove orphans when entities were removed from configuration # remove orphans when entities were removed from configuration
purge_entity_registry(self.hass, entry.entry_id, data) purge_entity_registry(self.hass, entry.entry_id, import_data)
purge_device_registry(self.hass, entry.entry_id, data) purge_device_registry(self.hass, entry.entry_id, import_data)
self.hass.config_entries.async_update_entry(entry, data=data) self.hass.config_entries.async_update_entry(entry, data=import_data)
return self.async_abort(reason="existing_configuration_updated") return self.async_abort(reason="existing_configuration_updated")
return self.async_create_entry(title=f"{data[CONF_HOST]}", data=data) return self.async_create_entry(
title=f"{import_data[CONF_HOST]}", data=import_data
)
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

View File

@ -67,19 +67,17 @@ class MPDConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors, errors=errors,
) )
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Attempt to import the existing configuration.""" """Attempt to import the existing configuration."""
self._async_abort_entries_match({CONF_HOST: import_config[CONF_HOST]}) self._async_abort_entries_match({CONF_HOST: import_data[CONF_HOST]})
client = MPDClient() client = MPDClient()
client.timeout = 30 client.timeout = 30
client.idletimeout = 10 client.idletimeout = 10
try: try:
async with timeout(35): async with timeout(35):
await client.connect(import_config[CONF_HOST], import_config[CONF_PORT]) await client.connect(import_data[CONF_HOST], import_data[CONF_PORT])
if CONF_PASSWORD in import_config: if CONF_PASSWORD in import_data:
await client.password(import_config[CONF_PASSWORD]) await client.password(import_data[CONF_PASSWORD])
with suppress(mpd.ConnectionError): with suppress(mpd.ConnectionError):
client.disconnect() client.disconnect()
except ( except (
@ -94,10 +92,10 @@ class MPDConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="unknown") return self.async_abort(reason="unknown")
return self.async_create_entry( return self.async_create_entry(
title=import_config.get(CONF_NAME, "Music Player Daemon"), title=import_data.get(CONF_NAME, "Music Player Daemon"),
data={ data={
CONF_HOST: import_config[CONF_HOST], CONF_HOST: import_data[CONF_HOST],
CONF_PORT: import_config[CONF_PORT], CONF_PORT: import_data[CONF_PORT],
CONF_PASSWORD: import_config.get(CONF_PASSWORD), CONF_PASSWORD: import_data.get(CONF_PASSWORD),
}, },
) )

View File

@ -157,11 +157,9 @@ class PanasonicVieraConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors, errors=errors,
) )
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a config entry from configuration.yaml.""" """Import a config entry from configuration.yaml."""
return await self.async_step_user(user_input=import_config) return await self.async_step_user(user_input=import_data)
async def async_load_data(self, config: dict[str, Any]) -> None: async def async_load_data(self, config: dict[str, Any]) -> None:
"""Load the data.""" """Load the data."""

View File

@ -80,13 +80,11 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=DATA_SCHEMA, errors=errors step_id="user", data_schema=DATA_SCHEMA, errors=errors
) )
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Attempt to import the existing configuration.""" """Attempt to import the existing configuration."""
self._async_abort_entries_match({CONF_HOST: import_config[CONF_HOST]}) self._async_abort_entries_match({CONF_HOST: import_data[CONF_HOST]})
host = import_config[CONF_HOST] host = import_data[CONF_HOST]
port = import_config.get(CONF_PORT, 9621) port = import_data.get(CONF_PORT, 9621)
# Connection logic is repeated here since this method will be removed in future releases # Connection logic is repeated here since this method will be removed in future releases
russ = Russound(self.hass.loop, host, port) russ = Russound(self.hass.loop, host, port)

View File

@ -28,22 +28,20 @@ class SleepIQFlowHandler(ConfigFlow, domain=DOMAIN):
"""Initialize the config flow.""" """Initialize the config flow."""
self._reauth_entry: ConfigEntry | None = None self._reauth_entry: ConfigEntry | None = None
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a SleepIQ account as a config entry. """Import a SleepIQ account as a config entry.
This flow is triggered by 'async_setup' for configured accounts. This flow is triggered by 'async_setup' for configured accounts.
""" """
await self.async_set_unique_id(import_config[CONF_USERNAME].lower()) await self.async_set_unique_id(import_data[CONF_USERNAME].lower())
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
if error := await try_connection(self.hass, import_config): if error := await try_connection(self.hass, import_data):
_LOGGER.error("Could not authenticate with SleepIQ server: %s", error) _LOGGER.error("Could not authenticate with SleepIQ server: %s", error)
return self.async_abort(reason=error) return self.async_abort(reason=error)
return self.async_create_entry( return self.async_create_entry(
title=import_config[CONF_USERNAME], data=import_config title=import_data[CONF_USERNAME], data=import_data
) )
async def async_step_user( async def async_step_user(

View File

@ -71,11 +71,9 @@ class TileFlowHandler(ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title=self._username, data=data) return self.async_create_entry(title=self._username, data=data)
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a config entry from configuration.yaml.""" """Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config) return await self.async_step_user(import_data)
async def async_step_reauth( async def async_step_reauth(
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping
from typing import Any from typing import Any
from pytraccar import ApiClient, ServerModel, TraccarException from pytraccar import ApiClient, ServerModel, TraccarException
@ -161,36 +160,34 @@ class TraccarServerConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors, errors=errors,
) )
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_info: Mapping[str, Any]
) -> ConfigFlowResult:
"""Import an entry.""" """Import an entry."""
configured_port = str(import_info[CONF_PORT]) configured_port = str(import_data[CONF_PORT])
self._async_abort_entries_match( self._async_abort_entries_match(
{ {
CONF_HOST: import_info[CONF_HOST], CONF_HOST: import_data[CONF_HOST],
CONF_PORT: configured_port, CONF_PORT: configured_port,
} }
) )
if "all_events" in (imported_events := import_info.get("event", [])): if "all_events" in (imported_events := import_data.get("event", [])):
events = list(EVENTS.values()) events = list(EVENTS.values())
else: else:
events = imported_events events = imported_events
return self.async_create_entry( return self.async_create_entry(
title=f"{import_info[CONF_HOST]}:{configured_port}", title=f"{import_data[CONF_HOST]}:{configured_port}",
data={ data={
CONF_HOST: import_info[CONF_HOST], CONF_HOST: import_data[CONF_HOST],
CONF_PORT: configured_port, CONF_PORT: configured_port,
CONF_SSL: import_info.get(CONF_SSL, False), CONF_SSL: import_data.get(CONF_SSL, False),
CONF_VERIFY_SSL: import_info.get(CONF_VERIFY_SSL, True), CONF_VERIFY_SSL: import_data.get(CONF_VERIFY_SSL, True),
CONF_USERNAME: import_info[CONF_USERNAME], CONF_USERNAME: import_data[CONF_USERNAME],
CONF_PASSWORD: import_info[CONF_PASSWORD], CONF_PASSWORD: import_data[CONF_PASSWORD],
}, },
options={ options={
CONF_MAX_ACCURACY: import_info[CONF_MAX_ACCURACY], CONF_MAX_ACCURACY: import_data[CONF_MAX_ACCURACY],
CONF_EVENTS: events, CONF_EVENTS: events,
CONF_CUSTOM_ATTRIBUTES: import_info.get("monitored_conditions", []), CONF_CUSTOM_ATTRIBUTES: import_data.get("monitored_conditions", []),
CONF_SKIP_ACCURACY_FILTER_FOR: import_info.get( CONF_SKIP_ACCURACY_FILTER_FOR: import_data.get(
"skip_accuracy_filter_on", [] "skip_accuracy_filter_on", []
), ),
}, },

View File

@ -285,9 +285,7 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_show_form(step_id="user", data_schema=schema, errors=errors) return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
async def async_step_import( async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Import a config entry from configuration.yaml.""" """Import a config entry from configuration.yaml."""
# Check if new config entry matches any existing config entries # Check if new config entry matches any existing config entries
for entry in self._async_current_entries(): for entry in self._async_current_entries():
@ -296,28 +294,28 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN):
continue continue
if await self.hass.async_add_executor_job( if await self.hass.async_add_executor_job(
_host_is_same, entry.data[CONF_HOST], import_config[CONF_HOST] _host_is_same, entry.data[CONF_HOST], import_data[CONF_HOST]
): ):
updated_options: dict[str, Any] = {} updated_options: dict[str, Any] = {}
updated_data: dict[str, Any] = {} updated_data: dict[str, Any] = {}
remove_apps = False remove_apps = False
if entry.data[CONF_HOST] != import_config[CONF_HOST]: if entry.data[CONF_HOST] != import_data[CONF_HOST]:
updated_data[CONF_HOST] = import_config[CONF_HOST] updated_data[CONF_HOST] = import_data[CONF_HOST]
if entry.data[CONF_NAME] != import_config[CONF_NAME]: if entry.data[CONF_NAME] != import_data[CONF_NAME]:
updated_data[CONF_NAME] = import_config[CONF_NAME] updated_data[CONF_NAME] = import_data[CONF_NAME]
# Update entry.data[CONF_APPS] if import_config[CONF_APPS] differs, and # Update entry.data[CONF_APPS] if import_config[CONF_APPS] differs, and
# pop entry.data[CONF_APPS] if import_config[CONF_APPS] is not specified # pop entry.data[CONF_APPS] if import_config[CONF_APPS] is not specified
if entry.data.get(CONF_APPS) != import_config.get(CONF_APPS): if entry.data.get(CONF_APPS) != import_data.get(CONF_APPS):
if not import_config.get(CONF_APPS): if not import_data.get(CONF_APPS):
remove_apps = True remove_apps = True
else: else:
updated_options[CONF_APPS] = import_config[CONF_APPS] updated_options[CONF_APPS] = import_data[CONF_APPS]
if entry.data.get(CONF_VOLUME_STEP) != import_config[CONF_VOLUME_STEP]: if entry.data.get(CONF_VOLUME_STEP) != import_data[CONF_VOLUME_STEP]:
updated_options[CONF_VOLUME_STEP] = import_config[CONF_VOLUME_STEP] updated_options[CONF_VOLUME_STEP] = import_data[CONF_VOLUME_STEP]
if updated_options or updated_data or remove_apps: if updated_options or updated_data or remove_apps:
new_data = entry.data.copy() new_data = entry.data.copy()
@ -345,9 +343,9 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN):
self._must_show_form = True self._must_show_form = True
# Store config key/value pairs that are not configurable in user step so they # Store config key/value pairs that are not configurable in user step so they
# don't get lost on user step # don't get lost on user step
if import_config.get(CONF_APPS): if import_data.get(CONF_APPS):
self._apps = copy.deepcopy(import_config[CONF_APPS]) self._apps = copy.deepcopy(import_data[CONF_APPS])
return await self.async_step_user(user_input=import_config) return await self.async_step_user(user_input=import_data)
async def async_step_zeroconf( async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo self, discovery_info: zeroconf.ZeroconfServiceInfo