@@ -169,19 +169,69 @@ async def test_options_flow(hass: HomeAssistant) -> None:
169169@pytest .mark .asyncio
170170async def test_reconfigure_flow (hass : HomeAssistant ) -> None :
171171 """Test the reconfigure flow."""
172- entry = MockConfigEntry (domain = DOMAIN , data = {}, options = {})
172+ entry = MockConfigEntry (
173+ domain = DOMAIN , data = {"session_cookie" : "old_cookie" }, options = {}
174+ )
173175 entry .add_to_hass (hass )
174176
175- await hass .config_entries .async_setup (entry .entry_id )
176- await hass .async_block_till_done ()
177+ with patch ("custom_components.generac.async_setup_entry" , return_value = True ):
178+ await hass .config_entries .async_setup (entry .entry_id )
179+ await hass .async_block_till_done ()
177180
178181 result = await hass .config_entries .flow .async_init (
179182 DOMAIN ,
180183 context = {
181- "source" : config_entries . SOURCE_RECONFIGURE ,
184+ "source" : "reconfigure" ,
182185 "entry_id" : entry .entry_id ,
183186 },
184187 )
185188
186189 assert result ["type" ] == "form"
187- assert result ["step_id" ] == "user"
190+ assert result ["step_id" ] == "reconfigure"
191+
192+ with patch (
193+ "custom_components.generac.config_flow.GeneracApiClient.async_get_data" ,
194+ return_value = True ,
195+ ), patch ("custom_components.generac.async_setup_entry" , return_value = True ), patch (
196+ "custom_components.generac.async_unload_entry" , return_value = True
197+ ):
198+ result2 = await hass .config_entries .flow .async_configure (
199+ result ["flow_id" ],
200+ {
201+ "session_cookie" : "new_cookie" ,
202+ },
203+ )
204+ await hass .async_block_till_done ()
205+
206+ assert result2 ["type" ] == "abort"
207+ assert result2 ["reason" ] == "reconfigure_successful"
208+ assert entry .data ["session_cookie" ] == "new_cookie"
209+
210+
211+ async def test_duplicate_entry (hass : HomeAssistant ) -> None :
212+ """Test duplicate entry is handled."""
213+ entry = MockConfigEntry (
214+ domain = DOMAIN ,
215+ unique_id = "binarydev@testing.com" ,
216+ data = {"session_cookie" : "existing" },
217+ )
218+ entry .add_to_hass (hass )
219+
220+ await setup .async_setup_component (hass , "persistent_notification" , {})
221+ result = await hass .config_entries .flow .async_init (
222+ DOMAIN , context = {"source" : config_entries .SOURCE_USER }
223+ )
224+
225+ with patch (
226+ "custom_components.generac.config_flow.GeneracApiClient.async_get_data" ,
227+ return_value = True ,
228+ ):
229+ result2 = await hass .config_entries .flow .async_configure (
230+ result ["flow_id" ],
231+ {
232+ "session_cookie" : "MobileLinkClientCookie=%7B%0D%0A%20%20%22signInName%22%3A%20%22binarydev%40testing.com%22%0D%0A%7D" ,
233+ },
234+ )
235+
236+ assert result2 ["type" ] == "abort"
237+ assert result2 ["reason" ] == "already_configured"
0 commit comments