From 9720427983ed2d37641f12c34d067691aa05d441 Mon Sep 17 00:00:00 2001 From: Sven Bursch-Osewold Date: Fri, 28 Jun 2024 20:32:01 +0200 Subject: [PATCH] Config_flow improved --- custom_components/pysmaplus/config_flow.py | 7 ++++--- custom_components/pysmaplus/strings.json | 10 +++++++--- custom_components/pysmaplus/translations/en.json | 10 +++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/custom_components/pysmaplus/config_flow.py b/custom_components/pysmaplus/config_flow.py index e3c12b7..7555b6e 100644 --- a/custom_components/pysmaplus/config_flow.py +++ b/custom_components/pysmaplus/config_flow.py @@ -55,7 +55,6 @@ async def validate_input( except Exception: # pylint: disable=broad-except _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" - return device_list, errors @@ -143,6 +142,8 @@ def async_get_options_flow(config_entry: ConfigEntry) -> PySMAOptionsConfigFlow: """Get the options flow for this handler.""" return PySMAOptionsConfigFlow(config_entry) + # "User" => 0,1,2,4 => details => selection + # => 3 => selection async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: @@ -253,6 +254,8 @@ async def async_step_deviceselection( # Create a list of all devices errors = {} device_list, errors = await validate_input(self.hass, self._data) + if errors: + return self.async_abort(reason=errors["base"]) self.listNames = [] self.listDeviceInfo = [] self.deviceList = device_list @@ -262,8 +265,6 @@ async def async_step_deviceselection( for i in device_list.values(): self.listNames.append(f"{i.name} {i.type} ({i.serial})") self.listDeviceInfo.append(i) - if errors: - return self.async_abort(reason="Error testing devices") if len(self.listDeviceInfo) == 1: self._data[CONF_DEVICE] = self.listDeviceInfo[0].id diff --git a/custom_components/pysmaplus/strings.json b/custom_components/pysmaplus/strings.json index d5af5ea..2fe6278 100644 --- a/custom_components/pysmaplus/strings.json +++ b/custom_components/pysmaplus/strings.json @@ -2,11 +2,15 @@ "config": { "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", - "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]" - }, + "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", + "cannot_connect": "[%key:common::config_flow::abort::cannot_connect%]", + "invalid_auth": "[%key:common::config_flow::abort::invalid_auth%]", + "unknown": "Unexpected error" +}, "error": { + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", - "cannot_retrieve_device_info": "Successfully connected, but unable to retrieve the device information", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "unknown": "[%key:common::config_flow::error::unknown%]" }, diff --git a/custom_components/pysmaplus/translations/en.json b/custom_components/pysmaplus/translations/en.json index 83566b4..e16639d 100644 --- a/custom_components/pysmaplus/translations/en.json +++ b/custom_components/pysmaplus/translations/en.json @@ -2,12 +2,16 @@ "config": { "abort": { "already_configured": "Device is already configured", - "already_in_progress": "Configuration flow is already in progress" + "already_in_progress": "Configuration flow is already in progress", + "cannot_connect": "Failed to connect. Please check hostname/ip.", + "cannot_retrieve_device_info": "Successfully connected, but unable to retrieve the device information", + "invalid_auth": "Invalid authentication. Please check user/group and password.", + "unknown": "Unexpected error" }, "error": { - "cannot_connect": "Failed to connect", + "cannot_connect": "Failed to connect. Please check hostname/ip.", "cannot_retrieve_device_info": "Successfully connected, but unable to retrieve the device information", - "invalid_auth": "Invalid authentication", + "invalid_auth": "Invalid authentication. Please check user/group and password.", "unknown": "Unexpected error" }, "step": {