megakid / ha_octopus_intelligent

Apache License 2.0
86 stars 10 forks source link

Config flow: Fix Octopus account validation, improve error handling #40

Closed pdcastro closed 4 months ago

pdcastro commented 4 months ago

This PR is a spin-off of other PRs and a result of my testing of the integration while working on those other PRs. Testing involved adding and removing the integration a few times, which goes through the config flow. I noticed that the config flow web UI was not displaying authentication errors when the user entered an incorrect Octopus account number or API key. After this PR, “Invalid Authentication” is displayed in red on the form as shown in the following screenshot:

Octopus Intelligent Invalid Auth

It’s a terse two-word error message, but it takes advantage of Home Assistant’s standard error message localisation in multiple languages. Anyway, I just made it work the way I understood it was supposed to. :-)

While working on PR #38, I noticed that the body of OctopusIntelligentSystem.start() was copy-and-paste-kind-of-similar to the try_connection() function in config_flow.py, and had the same bugs. So I refactored them to call a common function (in a new graphql_util.py file) and fixed some issues there.

See more details in other comments.