Skip to content

Commit

Permalink
Config_flow improved
Browse files Browse the repository at this point in the history
  • Loading branch information
littleyoda committed Jun 28, 2024
1 parent 26d0817 commit 9720427
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions custom_components/pysmaplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 7 additions & 3 deletions custom_components/pysmaplus/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]"
},
Expand Down
10 changes: 7 additions & 3 deletions custom_components/pysmaplus/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 9720427

Please sign in to comment.