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:
Tiit Rätsep 2019-12-11 14:27:28 +02:00 committed by Martin Hjelmare
parent 004af97699
commit 01ef44fd68
4 changed files with 41 additions and 9 deletions

View file

@ -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):