Skip to content

Add GUI configuration#369

Open
danelphick wants to merge 11 commits into
macxq:mainfrom
danelphick:add-config-flow
Open

Add GUI configuration#369
danelphick wants to merge 11 commits into
macxq:mainfrom
danelphick:add-config-flow

Conversation

@danelphick

Copy link
Copy Markdown

This adds a 2 page configuration UI for inverters, where the first page asks for the API key and uses that to fetch the list of devices which can then be selected on the second page. It doesn't remove YAML configuration which should continue to work as before.

I've also added extensive tests for the UI as well as adding automatic testing for pushes and pull requests on github.

Full disclosure: I'm using this project as an excuse to learn Claude Code, which generated nearly all of this. I've reviewed the code myself and tested it locally, but only have one inverter so can't test every feature in production.

Adds a UI-driven config flow as an alternative to YAML configuration.
The flow is split into two steps: API key entry (with validation against
the FoxESS API) and device/inverter selection. Bogus credentials and
non-JSON API responses are handled gracefully, and auth failures are
detected correctly.

Adds a reauthentication flow so users can rotate their API key without
removing and re-adding the integration.

Adds a full test suite covering the happy path, invalid credentials,
network errors, and the reauth flow.
The test action will run on push and pull_request actions.
Replace the HA-core-embedded test setup with a standalone approach using
pytest-homeassistant-custom-component. Add pyproject.toml and
requirements_test.txt, update CI to install from the requirements file,
and simplify conftest/imports to use the package directly.
…rror

- Replace _abort_if_unique_id_configured() with an inline check so
  duplicate-device errors appear as a field error on deviceSN, matching
  the existing name-collision behaviour
- Use add_suggested_values_to_schema in both steps so previously entered
  values are restored when the form is re-shown after an error
- Update tests: rename test, add suggested-value assertions, use
  MOCK_TWO_DEVICES (selecting the second device) to verify the selector
  does not revert to the first option, remove redundant
  test_device_id_set_to_device_sn
Creates FetchResult enum to return values from fetch functions instead
of returning a mixture of booleans and error numbers.
Changes config_flow to use GetAuth from sensor.py instead of its own
version of the same code.
Import constants from sensor.py instead of recreating them in
config_flow.py.
async_setup_platform now stores the device SN and name in hass.data so
the config flow can detect conflicts with YAML-configured devices.
Previously, _async_current_entries() only returned config entries, so
a device declared in YAML was invisible to the duplicate-SN and
duplicate-name checks, allowing a second entry to be created silently.

When a collision originates from a YAML-configured entry, distinct error
messages are shown (yaml_device_already_configured / yaml_name_already_in_use)
so the user knows to remove the device from configuration.yaml.
@danelphick danelphick marked this pull request as ready for review April 28, 2026 19:05
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