@@ -62,20 +62,42 @@ async def test_create_entry(
6262 assert result ["data" ][SECTION_ADVANCED_SETTINGS ][CONF_COMMUNITY ] == "public"
6363
6464
65- async def test_invalid_hostname (hass : HomeAssistant ) -> None :
65+ async def test_invalid_hostname (
66+ hass : HomeAssistant , mock_brother_client : AsyncMock
67+ ) -> None :
6668 """Test invalid hostname in user_input."""
6769 result = await hass .config_entries .flow .async_init (
68- DOMAIN ,
69- context = {"source" : SOURCE_USER },
70- data = {
70+ DOMAIN , context = {"source" : SOURCE_USER }
71+ )
72+
73+ assert result ["type" ] is FlowResultType .FORM
74+ assert result ["step_id" ] == "user"
75+ assert result ["errors" ] == {}
76+
77+ result = await hass .config_entries .flow .async_configure (
78+ result ["flow_id" ],
79+ {
7180 CONF_HOST : "invalid/hostname" ,
7281 CONF_TYPE : "laser" ,
7382 SECTION_ADVANCED_SETTINGS : {CONF_PORT : 161 , CONF_COMMUNITY : "public" },
7483 },
7584 )
7685
86+ assert result ["type" ] is FlowResultType .FORM
7787 assert result ["errors" ] == {CONF_HOST : "wrong_host" }
7888
89+ result = await hass .config_entries .flow .async_configure (
90+ result ["flow_id" ],
91+ CONFIG ,
92+ )
93+
94+ assert result ["type" ] is FlowResultType .CREATE_ENTRY
95+ assert result ["title" ] == "HL-L2340DW 0123456789"
96+ assert result ["data" ][CONF_HOST ] == "127.0.0.1"
97+ assert result ["data" ][CONF_TYPE ] == "laser"
98+ assert result ["data" ][SECTION_ADVANCED_SETTINGS ][CONF_PORT ] == 161
99+ assert result ["data" ][SECTION_ADVANCED_SETTINGS ][CONF_COMMUNITY ] == "public"
100+
79101
80102@pytest .mark .parametrize (
81103 ("exc" , "base_error" ),
@@ -89,14 +111,38 @@ async def test_errors(
89111 hass : HomeAssistant , exc : Exception , base_error : str , mock_brother_client : AsyncMock
90112) -> None :
91113 """Test connection to host error."""
114+ result = await hass .config_entries .flow .async_init (
115+ DOMAIN , context = {"source" : SOURCE_USER }
116+ )
117+
118+ assert result ["type" ] is FlowResultType .FORM
119+ assert result ["step_id" ] == "user"
120+ assert result ["errors" ] == {}
121+
92122 mock_brother_client .async_update .side_effect = exc
93123
94- result = await hass .config_entries .flow .async_init (
95- DOMAIN , context = {"source" : SOURCE_USER }, data = CONFIG
124+ result = await hass .config_entries .flow .async_configure (
125+ result ["flow_id" ],
126+ CONFIG ,
96127 )
97128
129+ assert result ["type" ] is FlowResultType .FORM
98130 assert result ["errors" ] == {"base" : base_error }
99131
132+ mock_brother_client .async_update .side_effect = None
133+
134+ result = await hass .config_entries .flow .async_configure (
135+ result ["flow_id" ],
136+ CONFIG ,
137+ )
138+
139+ assert result ["type" ] is FlowResultType .CREATE_ENTRY
140+ assert result ["title" ] == "HL-L2340DW 0123456789"
141+ assert result ["data" ][CONF_HOST ] == "127.0.0.1"
142+ assert result ["data" ][CONF_TYPE ] == "laser"
143+ assert result ["data" ][SECTION_ADVANCED_SETTINGS ][CONF_PORT ] == 161
144+ assert result ["data" ][SECTION_ADVANCED_SETTINGS ][CONF_COMMUNITY ] == "public"
145+
100146
101147async def test_unsupported_model_error (
102148 hass : HomeAssistant , mock_brother : AsyncMock , mock_brother_client : AsyncMock
@@ -382,6 +428,22 @@ async def test_reconfigure_invalid_hostname(
382428 assert result ["step_id" ] == "reconfigure"
383429 assert result ["errors" ] == {CONF_HOST : "wrong_host" }
384430
431+ result = await hass .config_entries .flow .async_configure (
432+ result ["flow_id" ],
433+ user_input = {
434+ CONF_HOST : "10.10.10.10" ,
435+ SECTION_ADVANCED_SETTINGS : {CONF_PORT : 161 , CONF_COMMUNITY : "public" },
436+ },
437+ )
438+
439+ assert result ["type" ] is FlowResultType .ABORT
440+ assert result ["reason" ] == "reconfigure_successful"
441+ assert mock_config_entry .data == {
442+ CONF_HOST : "10.10.10.10" ,
443+ CONF_TYPE : "laser" ,
444+ SECTION_ADVANCED_SETTINGS : {CONF_PORT : 161 , CONF_COMMUNITY : "public" },
445+ }
446+
385447
386448async def test_reconfigure_not_the_same_device (
387449 hass : HomeAssistant ,
@@ -409,3 +471,21 @@ async def test_reconfigure_not_the_same_device(
409471 assert result ["type" ] is FlowResultType .FORM
410472 assert result ["step_id" ] == "reconfigure"
411473 assert result ["errors" ] == {"base" : "another_device" }
474+
475+ mock_brother_client .serial = "0123456789"
476+
477+ result = await hass .config_entries .flow .async_configure (
478+ result ["flow_id" ],
479+ user_input = {
480+ CONF_HOST : "11.11.11.11" ,
481+ SECTION_ADVANCED_SETTINGS : {CONF_PORT : 161 , CONF_COMMUNITY : "public" },
482+ },
483+ )
484+
485+ assert result ["type" ] is FlowResultType .ABORT
486+ assert result ["reason" ] == "reconfigure_successful"
487+ assert mock_config_entry .data == {
488+ CONF_HOST : "11.11.11.11" ,
489+ CONF_TYPE : "laser" ,
490+ SECTION_ADVANCED_SETTINGS : {CONF_PORT : 161 , CONF_COMMUNITY : "public" },
491+ }
0 commit comments