New helpers and best practises for reauth and reconfigure flows
 · 2 min read
New helper methods have been added to the ConfigFlow to facilitate management of reauth and reconfigure flows:
- self._get_reauth_entry()and- self._get_reconfigure_entry()give access at any time to the corresponding config entry- these should be used over self.hass.config_entries.async_get_entry(self.context["entry_id"])
- the config entry should be requested when needed (local variable, once per step) and not cached as class attributes
- if the steps are shared with discovery or user flows, self.sourceshould be checked againstSOURCE_REAUTHandSOURCE_RECONFIGUREbefore accessing the entry
 
- these should be used over 
- self._abort_if_unique_id_mismatchallows you to abort if the- unique_iddoes not match the- unique_idof the config entry to reauthenticate or reconfigure- this should be used after a call to self.async_set_unique_id
- if the steps are shared with discovery or user flows, self.sourceshould be checked againstSOURCE_REAUTHandSOURCE_RECONFIGURE
- other sources should continue to use self._abort_if_unique_id_configured
 
- this should be used after a call to 
- self.async_update_reload_and_aborthas been adjusted to update the default message for reconfigure flows- the new message reconfigure_successfulmust be present instrings.json
 
- the new message 
- self.async_update_reload_and_aborthas a new argument- data_updatesto merge the data updates with the pre-existing data- this is preferred over the dataargument, as it reduces the risk of data loss if the schema is updated
 
- this is preferred over the 
More details can be found in the reconfigure and reauthentication documentation.