@@ -127,6 +127,40 @@ async def async_step_reauth_confirm(self, user_input: dict[str, str] | None = No
127127 errors = errors ,
128128 )
129129
130+ async def async_step_reconfigure (self , user_input : dict [str , Any ] | None = None ) -> ConfigFlowResult :
131+ """Allow the user to update their email and/or password."""
132+ entry = self .hass .config_entries .async_get_entry (self .context ["entry_id" ])
133+ errors : dict [str , str ] = {}
134+
135+ if user_input is not None :
136+ self .email = user_input [CONF_EMAIL ]
137+ self .password = user_input [CONF_PASSWORD ]
138+ self .region = entry .data .get (CONF_REGION , "US" )
139+
140+ if not (error := await self ._validate_input ()):
141+ self .hass .config_entries .async_update_entry (
142+ entry ,
143+ title = self .email ,
144+ data = {
145+ CONF_REGION : self .region ,
146+ CONF_EMAIL : self .email ,
147+ CONF_PASSWORD : self .password ,
148+ CONF_API_TOKEN : self .token ,
149+ },
150+ )
151+ await self .hass .config_entries .async_reload (entry .entry_id )
152+ return self .async_abort (reason = "reconfigure_successful" )
153+ errors ["base" ] = error
154+
155+ return self .async_show_form (
156+ step_id = "reconfigure" ,
157+ data_schema = vol .Schema ({
158+ vol .Required (CONF_EMAIL , default = entry .data .get (CONF_EMAIL , "" )): str ,
159+ vol .Required (CONF_PASSWORD ): str ,
160+ }),
161+ errors = errors ,
162+ )
163+
130164 async def _validate_input (self ) -> str :
131165 """Validate the user input allows us to connect.
132166
@@ -142,7 +176,7 @@ async def _validate_input(self) -> str:
142176 )
143177
144178 self .token = await api .login (self .email , self .password )
145- _LOGGER .debug (f "Login successful, token: { self . token } " )
179+ _LOGGER .debug ("Login successful" )
146180 except PetLibroCannotConnect :
147181 return "cannot_connect"
148182 except PetLibroInvalidAuth :
@@ -192,7 +226,7 @@ async def async_step_init(
192226 _LOGGER .debug (
193227 "Started Petlibro options flow for account %s" , self .entry .data [CONF_EMAIL ]
194228 )
195- return self .async_show_menu (menu_options = ["integration_settings" , "account_settings" ])
229+ return self .async_show_menu (menu_options = ["integration_settings" , "account_settings" , "change_credentials" ])
196230
197231 async def async_step_integration_settings (
198232 self , user_input : dict [str , Any ] | None = None
@@ -325,6 +359,54 @@ async def async_step_account_settings(
325359 _LOGGER .debug ("Showing account settings form." )
326360 return self ._show_account_settings_form (user_input )
327361
362+ async def async_step_change_credentials (
363+ self , user_input : dict [str , Any ] | None = None
364+ ) -> ConfigFlowResult :
365+ """Allow the user to update their login email and/or password."""
366+ errors : dict [str , str ] = {}
367+
368+ if user_input :
369+ new_email = user_input [CONF_EMAIL ]
370+ new_password = user_input [CONF_PASSWORD ]
371+ try :
372+ api = PetLibroAPI (
373+ async_get_clientsession (self .hass ),
374+ self .hass .config .time_zone ,
375+ self .entry .data [CONF_REGION ],
376+ new_email ,
377+ new_password ,
378+ )
379+ new_token = await api .login (new_email , new_password )
380+ except PetLibroInvalidAuth :
381+ errors ["base" ] = "invalid_auth"
382+ except PetLibroCannotConnect :
383+ errors ["base" ] = "cannot_connect"
384+ except Exception :
385+ _LOGGER .exception ("Unexpected error updating credentials" )
386+ errors ["base" ] = "unknown"
387+ else :
388+ self .hass .config_entries .async_update_entry (
389+ self .entry ,
390+ title = new_email ,
391+ data = {
392+ ** self .entry .data ,
393+ CONF_EMAIL : new_email ,
394+ CONF_PASSWORD : new_password ,
395+ CONF_API_TOKEN : new_token ,
396+ },
397+ )
398+ await self .hass .config_entries .async_reload (self .entry .entry_id )
399+ return self .async_abort (reason = "credentials_updated" )
400+
401+ return self .async_show_form (
402+ step_id = "change_credentials" ,
403+ data_schema = vol .Schema ({
404+ vol .Required (CONF_EMAIL , default = self .entry .data .get (CONF_EMAIL , "" )): str ,
405+ vol .Required (CONF_PASSWORD ): str ,
406+ }),
407+ errors = errors ,
408+ )
409+
328410 # ------------------------------
329411 # Form Builders
330412 # ------------------------------
0 commit comments