From 1dbae752ef466223551249bc3221d42769ed97a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20St=C3=A5hl?= Date: Wed, 18 Nov 2020 11:39:11 +0100 Subject: [PATCH] Give error if no DPS are found in config flow (#167) Fixes #153 --- custom_components/localtuya/config_flow.py | 11 +++++++++++ custom_components/localtuya/translations/en.json | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index fed54d7..118e6f9 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -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.""" diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 4eb2614..a7f361b 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -9,7 +9,8 @@ "unknown": "An unknown error occurred. See log for details.", "entity_already_configured": "Entity with this ID has already been configured.", "address_in_use": "Address used for discovery is already in use. Make sure no other application is using it (TCP port 6668).", - "discovery_failed": "Something failed when discovering devices. See log for details." + "discovery_failed": "Something failed when discovering devices. See log for details.", + "empty_dps": "Connection to device succeeded but no datapoints found, please try again. Create a new issue and include debug logs if problem persists." }, "step": { "user": {