@@ -352,3 +352,178 @@ async def test_reauth(hass: HomeAssistant, config_entry_with_auth: ConfigEntry)
352352
353353 assert result .get ("type" ) is FlowResultType .ABORT
354354 assert result .get ("reason" ) == "reauth_successful"
355+
356+
357+ async def test_reconfigure_host (hass : HomeAssistant , config_entry : ConfigEntry ) -> None :
358+ """Test reconfigure host on a simple (no-auth) entry."""
359+ assert len (hass .config_entries .async_entries (DOMAIN )) == 1
360+
361+ result = await config_entry .start_reconfigure_flow (hass )
362+
363+ assert result .get ("type" ) is FlowResultType .FORM
364+ assert result .get ("step_id" ) == "user"
365+ assert result .get ("errors" ) == {}
366+
367+ assert config_entry .data [CONF_HOST ] == "192.168.0.1"
368+ with patch (
369+ "homeassistant.components.sfr_box.config_flow.SFRBox.system_get_info" ,
370+ return_value = SystemInfo (
371+ ** (
372+ await async_load_json_object_fixture (
373+ hass , "system_getInfo.json" , DOMAIN
374+ )
375+ )
376+ ),
377+ ):
378+ result = await hass .config_entries .flow .async_configure (
379+ result ["flow_id" ],
380+ user_input = {
381+ CONF_HOST : "192.168.0.100" ,
382+ },
383+ )
384+
385+ assert result .get ("type" ) is FlowResultType .MENU
386+ assert result .get ("step_id" ) == "choose_auth"
387+
388+ result = await hass .config_entries .flow .async_configure (
389+ result ["flow_id" ],
390+ {"next_step_id" : "skip_auth" },
391+ )
392+
393+ assert result .get ("type" ) is FlowResultType .ABORT
394+ assert result .get ("reason" ) == "reconfigure_successful"
395+ assert config_entry .data == {CONF_HOST : "192.168.0.100" }
396+
397+
398+ async def test_reconfigure_add_auth (
399+ hass : HomeAssistant , config_entry : ConfigEntry
400+ ) -> None :
401+ """Test reconfigure able to add authentication on a simple (no-auth) entry."""
402+ assert len (hass .config_entries .async_entries (DOMAIN )) == 1
403+
404+ result = await config_entry .start_reconfigure_flow (hass )
405+
406+ assert result .get ("type" ) is FlowResultType .FORM
407+ assert result .get ("step_id" ) == "user"
408+ assert result .get ("errors" ) == {}
409+
410+ assert CONF_USERNAME not in config_entry .data
411+ with patch (
412+ "homeassistant.components.sfr_box.config_flow.SFRBox.system_get_info" ,
413+ return_value = SystemInfo (
414+ ** (
415+ await async_load_json_object_fixture (
416+ hass , "system_getInfo.json" , DOMAIN
417+ )
418+ )
419+ ),
420+ ):
421+ result = await hass .config_entries .flow .async_configure (
422+ result ["flow_id" ],
423+ user_input = {
424+ CONF_HOST : "192.168.0.1" ,
425+ },
426+ )
427+
428+ assert result .get ("type" ) is FlowResultType .MENU
429+ assert result .get ("step_id" ) == "choose_auth"
430+
431+ result = await hass .config_entries .flow .async_configure (
432+ result ["flow_id" ],
433+ {"next_step_id" : "auth" },
434+ )
435+
436+ with patch ("homeassistant.components.sfr_box.config_flow.SFRBox.authenticate" ):
437+ result = await hass .config_entries .flow .async_configure (
438+ result ["flow_id" ],
439+ user_input = {
440+ CONF_USERNAME : "admin" ,
441+ CONF_PASSWORD : "valid" ,
442+ },
443+ )
444+
445+ assert result .get ("type" ) is FlowResultType .ABORT
446+ assert result .get ("reason" ) == "reconfigure_successful"
447+ assert config_entry .data == {
448+ CONF_HOST : "192.168.0.1" ,
449+ CONF_USERNAME : "admin" ,
450+ CONF_PASSWORD : "valid" ,
451+ }
452+
453+
454+ async def test_reconfigure_clear_auth (
455+ hass : HomeAssistant , config_entry_with_auth : ConfigEntry
456+ ) -> None :
457+ """Test reconfigure clears authentication on an entry with auth."""
458+ assert len (hass .config_entries .async_entries (DOMAIN )) == 1
459+
460+ result = await config_entry_with_auth .start_reconfigure_flow (hass )
461+
462+ assert result .get ("type" ) is FlowResultType .FORM
463+ assert result .get ("step_id" ) == "user"
464+ assert result .get ("errors" ) == {}
465+
466+ assert config_entry_with_auth .data [CONF_USERNAME ] == "admin"
467+ with patch (
468+ "homeassistant.components.sfr_box.config_flow.SFRBox.system_get_info" ,
469+ return_value = SystemInfo (
470+ ** (
471+ await async_load_json_object_fixture (
472+ hass , "system_getInfo.json" , DOMAIN
473+ )
474+ | {"mac_addr" : "e4:5d:51:00:11:23" }
475+ )
476+ ),
477+ ):
478+ result = await hass .config_entries .flow .async_configure (
479+ result ["flow_id" ],
480+ user_input = {
481+ CONF_HOST : "192.168.0.1" ,
482+ },
483+ )
484+
485+ assert result .get ("type" ) is FlowResultType .MENU
486+ assert result .get ("step_id" ) == "choose_auth"
487+
488+ result = await hass .config_entries .flow .async_configure (
489+ result ["flow_id" ],
490+ {"next_step_id" : "skip_auth" },
491+ )
492+
493+ assert result .get ("type" ) is FlowResultType .ABORT
494+ assert result .get ("reason" ) == "reconfigure_successful"
495+ assert CONF_USERNAME not in config_entry_with_auth .data
496+
497+
498+ async def test_reconfigure_mismatch (
499+ hass : HomeAssistant , config_entry_with_auth : ConfigEntry
500+ ) -> None :
501+ """Test reconfigure fails if the unique ID (=MAC) does not match."""
502+ assert len (hass .config_entries .async_entries (DOMAIN )) == 1
503+
504+ result = await config_entry_with_auth .start_reconfigure_flow (hass )
505+
506+ assert result .get ("type" ) is FlowResultType .FORM
507+ assert result .get ("step_id" ) == "user"
508+ assert result .get ("errors" ) == {}
509+
510+ assert config_entry_with_auth .data [CONF_USERNAME ] == "admin"
511+ with patch (
512+ "homeassistant.components.sfr_box.config_flow.SFRBox.system_get_info" ,
513+ return_value = SystemInfo (
514+ ** (
515+ await async_load_json_object_fixture (
516+ hass , "system_getInfo.json" , DOMAIN
517+ )
518+ )
519+ ),
520+ ):
521+ result = await hass .config_entries .flow .async_configure (
522+ result ["flow_id" ],
523+ user_input = {
524+ CONF_HOST : "192.168.0.1" ,
525+ },
526+ )
527+
528+ assert result .get ("type" ) is FlowResultType .ABORT
529+ assert result .get ("reason" ) == "unique_id_mismatch"
0 commit comments