Compare commits

...

1 Commits

Author SHA1 Message Date
Franck Nijhof 08bf223f6b Fix OctoPrint config flow crash when discovery plugin is disabled 2026-05-28 20:37:08 +00:00
2 changed files with 52 additions and 2 deletions
@@ -155,8 +155,11 @@ class OctoPrintConfigFlow(ConfigFlow, domain=DOMAIN):
finally:
await self._sessions.pop().close()
await self.async_set_unique_id(discovery.upnp_uuid, raise_on_progress=False)
self._abort_if_unique_id_configured()
if discovery and (unique_id := discovery.upnp_uuid):
await self.async_set_unique_id(unique_id, raise_on_progress=False)
self._abort_if_unique_id_configured()
else:
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
return self.async_create_entry(title=user_input[CONF_HOST], data=user_input)
@@ -608,3 +608,50 @@ async def test_reauth_form(hass: HomeAssistant) -> None:
assert result2["type"] is FlowResultType.ABORT
assert result2["reason"] == "reauth_successful"
async def test_form_discovery_plugin_disabled(hass: HomeAssistant) -> None:
"""Test setup succeeds when discovery plugin is disabled."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"pyoctoprintapi.OctoprintClient.request_app_key", return_value="test-key"
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "testuser",
"host": "1.1.1.1",
"name": "Printer",
"port": 81,
"ssl": True,
"path": "/",
},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.SHOW_PROGRESS
with (
patch(
"pyoctoprintapi.OctoprintClient.get_server_info",
return_value=True,
),
patch(
"pyoctoprintapi.OctoprintClient.get_discovery_info",
return_value=None,
),
patch("homeassistant.components.octoprint.async_setup", return_value=True),
patch(
"homeassistant.components.octoprint.async_setup_entry",
return_value=True,
),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
)
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == "1.1.1.1"