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:
parent
004af97699
commit
01ef44fd68
4 changed files with 41 additions and 9 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue