Skip to content

Conversation

@Darsstar
Copy link
Contributor

@Darsstar Darsstar commented Jan 5, 2026

Proposed change

Implement reconfiguration.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Jan 5, 2026

Hey there @squishykid, mind taking a look at this pull request as it has been labeled with an integration (solax) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of solax can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign solax Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant home-assistant bot marked this pull request as draft January 6, 2026 07:41
@home-assistant
Copy link

home-assistant bot commented Jan 6, 2026

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@Darsstar Darsstar force-pushed the solax/reconfiguration branch 6 times, most recently from 768e5e8 to 25ecbcd Compare January 6, 2026 17:24
@Darsstar Darsstar marked this pull request as ready for review January 6, 2026 17:29
@home-assistant home-assistant bot requested a review from zweckj January 6, 2026 17:29
"""Handle reconfiguration."""
errors: dict[str, Any] = {}
if user_input is None:
if (entry_id := self.context.get("entry_id")) and (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when these variables are not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"entry_id" should always exist as a key since HA refuses to initialize a "reconfigure" flow without it.

If the config entry was deleted after initializing the "reconfigure" flow but before this code gets executed than config_entry would be None. Want me to use async_get_known_entry, which raises and UnkownEntry exception, instead?

Anyway, if that race occurs the form is show without the previous configuration values, but the default values instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that even occur that during the reconfugure flow the config entry gets deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh during the reconfigure flow is easy, that early during the reconfigure flow is not as easy, might be impossible for all I know. But as far as the type checkers are conserned it is possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use self._get_reconfigure_entry(). Save you the walrus operator and makes mypy happy out of the box.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a practical example, look here:

async def async_step_reconfigure(

@Darsstar Darsstar force-pushed the solax/reconfiguration branch from 25ecbcd to 9ca9b13 Compare January 7, 2026 10:16
@Darsstar Darsstar force-pushed the solax/reconfiguration branch from 9ca9b13 to 302f14a Compare January 7, 2026 11:02
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to dm me if you need help :)

if user_input is None:
return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
step_id=SOURCE_USER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
step_id=SOURCE_USER,
step_id="user",

While they mean the same, source_user has different uses than the step_id being user

return self.async_update_reload_and_abort(
self._get_reconfigure_entry(),
data=user_input,
reload_even_if_entry_is_unchanged=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we do this explicitly? If users encounter issues with this and try to reconfigure for an attempt to fix it, a reload might save things instead

Comment on lines +61 to +63
assert "type" in entry_result
assert "title" in entry_result
assert "data" in entry_result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, your IDE linting is probably too harsh

Comment on lines 76 to +98
flow = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with (
patch(
"homeassistant.components.solax.config_flow.real_time_api",
return_value=__mock_real_time_api_success(),
),
patch("solax.RealTimeAPI.get_data", return_value=__mock_get_data()),
patch(
"homeassistant.components.solax.async_setup_entry",
return_value=True,
) as mock_setup_entry,
):
entry_result = await hass.config_entries.flow.async_configure(
flow["flow_id"],
{CONF_IP_ADDRESS: "192.168.1.87", CONF_PORT: 80, CONF_PASSWORD: "password"},
)
await hass.async_block_till_done()

assert "result" in entry_result
assert "data" in entry_result
assert "context" in entry_result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, please use a MockConfigEntry and add it to hass, and use that to reconfigure, instead of going through a whole flow here

Comment on lines +106 to +112
flow = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"entry_id": entry_result["result"].entry_id,
"source": config_entries.SOURCE_RECONFIGURE,
},
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead use await mock_config_entry.start_reconfigure_flow(hass)

Comment on lines +119 to +138
await hass.config_entries.flow.async_configure(
flow["flow_id"],
{
CONF_IP_ADDRESS: "192.168.1.187",
CONF_PORT: 8080,
CONF_PASSWORD: "password123",
},
)
await hass.async_block_till_done()

config_entry = hass.config_entries.async_entry_for_domain_unique_id(
DOMAIN,
entry_result["context"]["unique_id"],
)
assert config_entry is not None
assert config_entry.data == {
CONF_IP_ADDRESS: "192.168.1.187",
CONF_PORT: 8080,
CONF_PASSWORD: "password123",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the result of async_configure and assert it

flow["flow_id"],
{CONF_IP_ADDRESS: "192.168.1.87", CONF_PORT: 80, CONF_PASSWORD: "password"},
)
await hass.async_block_till_done()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a blocking operation, so we can remove the block_till_done here

assert len(mock_setup_entry.mock_calls) == 2


async def test_form_configure_connect_error(hass: HomeAssistant) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference: Keep the user flow tests near each other (with the happy flow at the top). Now the file is

  1. user flow happy flow
  2. reconfigure
  3. user flow rest
  4. reconfigure error

Comment on lines +217 to +218
assert entry_result["type"] is FlowResultType.FORM
assert entry_result["errors"] == {"base": "cannot_connect"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies to this test as for the happy flow reconfiguration.

But here we should also repatch the library and try again to test that the flow is able to recover to make sure there are no race conditions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I am missing a test for trying to reconfigure into a different device (so if I reconfigure entry A to work with device with serial number B), that should abort

@home-assistant home-assistant bot marked this pull request as draft January 7, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants