From b1379f6a8979b6b628101f40e38eb7ae0becddd9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 5 Dec 2024 21:20:02 +0100 Subject: [PATCH] Avoid access to `self.context["source"]` in integration config flows (#132355) * Avoid access to `self.context["source"]` in integration config flows * One more * One more --- homeassistant/components/cert_expiry/config_flow.py | 2 +- homeassistant/components/hive/config_flow.py | 4 ++-- homeassistant/components/vizio/config_flow.py | 8 ++++---- homeassistant/components/zwave_js/config_flow.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/cert_expiry/config_flow.py b/homeassistant/components/cert_expiry/config_flow.py index 22d443c700d..3fbb1c08c9b 100644 --- a/homeassistant/components/cert_expiry/config_flow.py +++ b/homeassistant/components/cert_expiry/config_flow.py @@ -74,7 +74,7 @@ class CertexpiryConfigFlow(ConfigFlow, domain=DOMAIN): title=title, data={CONF_HOST: host, CONF_PORT: port}, ) - if self.context["source"] == SOURCE_IMPORT: + if self.source == SOURCE_IMPORT: _LOGGER.error("Config import failed for %s", user_input[CONF_HOST]) return self.async_abort(reason="import_failed") else: diff --git a/homeassistant/components/hive/config_flow.py b/homeassistant/components/hive/config_flow.py index a997954f4cc..8df9a635302 100644 --- a/homeassistant/components/hive/config_flow.py +++ b/homeassistant/components/hive/config_flow.py @@ -104,7 +104,7 @@ class HiveFlowHandler(ConfigFlow, domain=DOMAIN): errors["base"] = "no_internet_available" if not errors: - if self.context["source"] == SOURCE_REAUTH: + if self.source == SOURCE_REAUTH: return await self.async_setup_hive_entry() self.device_registration = True return await self.async_step_configuration() @@ -144,7 +144,7 @@ class HiveFlowHandler(ConfigFlow, domain=DOMAIN): # Setup the config entry self.data["tokens"] = self.tokens - if self.context["source"] == SOURCE_REAUTH: + if self.source == SOURCE_REAUTH: assert self.entry self.hass.config_entries.async_update_entry( self.entry, title=self.data["username"], data=self.data diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index 49f6a709565..54031930503 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -231,7 +231,7 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN): errors[CONF_HOST] = "existing_config_entry_found" if not errors: - if self._must_show_form and self.context["source"] == SOURCE_ZEROCONF: + if self._must_show_form and self.source == SOURCE_ZEROCONF: # Discovery should always display the config form before trying to # create entry so that user can update default config options self._must_show_form = False @@ -251,7 +251,7 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN): if not errors: return await self._create_entry(user_input) - elif self._must_show_form and self.context["source"] == SOURCE_IMPORT: + elif self._must_show_form and self.source == SOURCE_IMPORT: # Import should always display the config form if CONF_ACCESS_TOKEN # wasn't included but is needed so that the user can choose to update # their configuration.yaml or to proceed with config flow pairing. We @@ -272,7 +272,7 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN): schema = self._user_schema or _get_config_schema() - if errors and self.context["source"] == SOURCE_IMPORT: + if errors and self.source == SOURCE_IMPORT: # Log an error message if import config flow fails since otherwise failure is silent _LOGGER.error( "Importing from configuration.yaml failed: %s", @@ -434,7 +434,7 @@ class VizioConfigFlow(ConfigFlow, domain=DOMAIN): self._data[CONF_ACCESS_TOKEN] = pair_data.auth_token self._must_show_form = True - if self.context["source"] == SOURCE_IMPORT: + if self.source == SOURCE_IMPORT: # If user is pairing via config import, show different message return await self.async_step_pairing_complete_import() diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index 36f208e18d5..711eb14070d 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -671,7 +671,7 @@ class ZWaveJSConfigFlow(BaseZwaveJSFlow, ConfigFlow, domain=DOMAIN): discovery_info = await self._async_get_addon_discovery_info() self.ws_address = f"ws://{discovery_info['host']}:{discovery_info['port']}" - if not self.unique_id or self.context["source"] == SOURCE_USB: + if not self.unique_id or self.source == SOURCE_USB: if not self.version_info: try: self.version_info = await async_get_version_info(