Skip to content

feat: Improve config flow validation, error handling, and reconfigure UX - #142

Open
davidnoyes wants to merge 1 commit into
cdpuk:masterfrom
davidnoyes:fix/config-flow-improvements
Open

feat: Improve config flow validation, error handling, and reconfigure UX#142
davidnoyes wants to merge 1 commit into
cdpuk:masterfrom
davidnoyes:fix/config-flow-improvements

Conversation

@davidnoyes

Copy link
Copy Markdown
Contributor

Summary

  • Host validation: strips whitespace and rejects URLs containing :// or / before attempting a connection, giving immediate feedback rather than a confusing timeout
  • Granular error messages: maps connection failures to specific error keys (invalid_host / cannot_connect / invalid_inverter) with user-friendly translated messages
  • Always close on failure: moves the serial number read inside the try block so client.close() is guaranteed to run even when detection fails
  • Unique ID: sets the inverter serial number as the config entry unique ID on first setup, allowing HA to detect and prevent duplicate entries
  • Reconfigure step: adds async_step_reconfigure so users can update the inverter host in-place (e.g. after a DHCP change) without removing and re-adding the integration
  • Stale translation cleanup: removes the orphaned num_batteries translation key left behind when the field was removed from the config flow schema in Write settings using services #4

Test plan

  • Enter an invalid host (e.g. http://192.168.1.1) — should show invalid_host error immediately
  • Enter a hostname that doesn't resolve — should show cannot_connect
  • Enter a reachable host that isn't a GivEnergy inverter — should show invalid_inverter
  • Add the integration twice with the same inverter — should abort with already_configured
  • Use the Reconfigure option on an existing entry to change the host

- Validate and normalise the host field before connecting: strip
  whitespace, reject URLs containing :// or /
- Map connection errors to granular user-visible error keys
  (invalid_host / cannot_connect / invalid_inverter) with translated
  messages in strings.json and translations/en.json
- Move serial number read inside the try block so client.close() always
  runs on failure
- Set a unique ID from the inverter serial number on first setup so HA
  can detect duplicate entries
- Add async_step_reconfigure so users can update the inverter host
  in-place without removing and re-adding the integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant