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()
andself._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.source
should be checked againstSOURCE_REAUTH
andSOURCE_RECONFIGURE
before accessing the entry
- these should be used over
self._abort_if_unique_id_mismatch
allows you to abort if theunique_id
does not match theunique_id
of 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.source
should be checked againstSOURCE_REAUTH
andSOURCE_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_abort
has been adjusted to update the default message for reconfigure flows- the new message
reconfigure_successful
must be present instrings.json
- the new message
self.async_update_reload_and_abort
has a new argumentdata_updates
to merge the data updates with the pre-existing data- this is preferred over the
data
argument, 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.