-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Fix MAC address mix-ups between WLED devices #155491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
79654b2
48ef15e
78f0004
bb895d0
4b53424
8d97e3d
595c1a0
fb1d0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,102 @@ async def test_full_user_flow_implementation(hass: HomeAssistant) -> None: | |
| assert result["result"].unique_id == "aabbccddeeff" | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("mock_setup_entry", "mock_wled") | ||
| async def test_full_reconfigure_flow_success( | ||
| hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_wled: MagicMock | ||
| ) -> None: | ||
| """Test the full reconfigure flow from start to finish.""" | ||
| mock_config_entry.add_to_hass(hass) | ||
|
|
||
| result = await mock_config_entry.start_reconfigure_flow(hass) | ||
|
|
||
| # Assert show form initially | ||
| assert result.get("step_id") == "user" | ||
| assert result.get("type") is FlowResultType.FORM | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], user_input={CONF_HOST: "10.10.0.10"} | ||
| ) | ||
|
|
||
| # Assert show text message and close flow | ||
| assert result.get("type") is FlowResultType.ABORT | ||
| assert result.get("reason") == "reconfigure_successful" | ||
|
|
||
| # Assert config entry has been updated. | ||
| new_entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id) | ||
| assert new_entry is not None | ||
| assert new_entry.data[CONF_HOST] == "10.10.0.10" | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("mock_setup_entry", "mock_wled") | ||
| async def test_full_reconfigure_flow_unique_id_mismatch( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In circumstances it can fail at reconfigure right? Since it uses the user_step, but that has a try-except that can fail. Normally it's good practice to write a test that initially fails and then demonstrates the flow can recover and successfully reconfigure. That would be a good additional test. :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a new test case: |
||
| hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_wled: MagicMock | ||
| ) -> None: | ||
| """Test reconfiguration failure when the unique ID changes.""" | ||
| mock_config_entry.add_to_hass(hass) | ||
|
|
||
| # Change mac address | ||
| device = mock_wled.update.return_value | ||
| device.info.mac_address = "invalid" | ||
|
|
||
| result = await mock_config_entry.start_reconfigure_flow(hass) | ||
|
|
||
| # Assert show form initially | ||
| assert result.get("step_id") == "user" | ||
| assert result.get("type") is FlowResultType.FORM | ||
|
|
||
| # Input new host value | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], user_input={CONF_HOST: "10.10.0.10"} | ||
| ) | ||
|
|
||
| # Assert Show text message and close flow | ||
| assert result.get("type") is FlowResultType.ABORT | ||
| assert result.get("reason") == "unique_id_mismatch" | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("mock_setup_entry", "mock_wled") | ||
| async def test_full_reconfigure_flow_connection_error_and_success( | ||
| hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_wled: MagicMock | ||
| ) -> None: | ||
| """Test we show user form on WLED connection error and allows user to change host.""" | ||
| mock_config_entry.add_to_hass(hass) | ||
|
|
||
| # Mock connection error | ||
| mock_wled.update.side_effect = WLEDConnectionError | ||
|
|
||
| result = await mock_config_entry.start_reconfigure_flow(hass) | ||
|
|
||
| # Assert show form initially | ||
| assert result.get("step_id") == "user" | ||
| assert result.get("type") is FlowResultType.FORM | ||
|
|
||
| # Input new host value | ||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], user_input={CONF_HOST: "10.10.0.10"} | ||
| ) | ||
|
|
||
| # Assert form with errors | ||
| assert result.get("type") is FlowResultType.FORM | ||
| assert result.get("step_id") == "user" | ||
| assert result.get("errors") == {"base": "cannot_connect"} | ||
|
|
||
| # Remove mock for connection error | ||
| mock_wled.update.side_effect = None | ||
|
|
||
| result = await hass.config_entries.flow.async_configure( | ||
| result["flow_id"], user_input={CONF_HOST: "10.10.0.10"} | ||
| ) | ||
|
|
||
| # Assert show text message and close flow | ||
| assert result.get("type") is FlowResultType.ABORT | ||
| assert result.get("reason") == "reconfigure_successful" | ||
|
|
||
| # Assert config entry has been updated. | ||
| new_entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id) | ||
| assert new_entry is not None | ||
| assert new_entry.data[CONF_HOST] == "10.10.0.10" | ||
|
joostlek marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| @pytest.mark.usefixtures("mock_setup_entry", "mock_wled") | ||
| async def test_full_zeroconf_flow_implementation(hass: HomeAssistant) -> None: | ||
| """Test the full manual user flow from start to finish.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.