Give error if no DPS are found in config flow (#167)

Fixes #153
This commit is contained in:
Pierre Ståhl
2020-11-18 11:39:11 +01:00
committed by GitHub
parent 4793e09104
commit 1dbae752ef
2 changed files with 13 additions and 1 deletions

View File

@@ -178,6 +178,11 @@ async def validate_input(hass: core.HomeAssistant, data):
if interface:
interface.close()
# Indicate an error if no datapoints found as the rest of the flow
# won't work in this case
if not detected_dps:
raise EmptyDpsList
return dps_string_list(detected_dps)
@@ -252,6 +257,8 @@ class LocaltuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
except EmptyDpsList:
errors["base"] = "empty_dps"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
@@ -408,3 +415,7 @@ class CannotConnect(exceptions.HomeAssistantError):
class InvalidAuth(exceptions.HomeAssistantError):
"""Error to indicate there is invalid auth."""
class EmptyDpsList(exceptions.HomeAssistantError):
"""Error to indicate no datapoints found."""