mirror of
https://github.com/elisspace/core.git
synced 2026-09-29 22:09:55 +00:00
Fix Soma integration connection issue (#27692)
* Added a check for Connect actually returning something before telling the user the setup succeeded * Added handling for KeyError in case API returns empty response, formatting * Trying to please the linter
This commit is contained in:
committed by
Martin Hjelmare
parent
004af97699
commit
01ef44fd68
@@ -3,7 +3,9 @@
|
||||
"abort": {
|
||||
"already_setup": "You can only configure one Soma account.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"missing_configuration": "The Soma component is not configured. Please follow the documentation."
|
||||
"missing_configuration": "The Soma component is not configured. Please follow the documentation.",
|
||||
"result_error": "SOMA Connect responded with error status.",
|
||||
"connection_error": "Failed to connect to SOMA Connect."
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "Successfully authenticated with Soma."
|
||||
|
||||
@@ -40,14 +40,22 @@ class SomaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Finish config flow."""
|
||||
api = SomaApi(user_input["host"], user_input["port"])
|
||||
try:
|
||||
await self.hass.async_add_executor_job(api.list_devices)
|
||||
result = await self.hass.async_add_executor_job(api.list_devices)
|
||||
_LOGGER.info("Successfully set up Soma Connect")
|
||||
return self.async_create_entry(
|
||||
title="Soma Connect",
|
||||
data={"host": user_input["host"], "port": user_input["port"]},
|
||||
if result["result"] == "success":
|
||||
return self.async_create_entry(
|
||||
title="Soma Connect",
|
||||
data={"host": user_input["host"], "port": user_input["port"]},
|
||||
)
|
||||
_LOGGER.error(
|
||||
"Connection to SOMA Connect failed (result:%s)", result["result"]
|
||||
)
|
||||
return self.async_abort(reason="result_error")
|
||||
except RequestException:
|
||||
_LOGGER.error("Connection to SOMA Connect failed")
|
||||
_LOGGER.error("Connection to SOMA Connect failed with RequestException")
|
||||
return self.async_abort(reason="connection_error")
|
||||
except KeyError:
|
||||
_LOGGER.error("Connection to SOMA Connect failed with KeyError")
|
||||
return self.async_abort(reason="connection_error")
|
||||
|
||||
async def async_step_import(self, user_input=None):
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
"abort": {
|
||||
"already_setup": "You can only configure one Soma account.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"missing_configuration": "The Soma component is not configured. Please follow the documentation."
|
||||
"missing_configuration": "The Soma component is not configured. Please follow the documentation.",
|
||||
"result_error": "SOMA Connect responded with error status.",
|
||||
"connection_error": "Failed to connect to SOMA Connect."
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "Successfully authenticated with Soma."
|
||||
|
||||
Reference in New Issue
Block a user