mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-21 16:26:30 +00:00
Document required entry_id (#2436)
* Document required entry_id * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update and rename 2024-11-01-reauth-reconfigure-entry-id.md to 2024-11-03-reauth-reconfigure-entry-id.md * Update 2024-11-03-reauth-reconfigure-entry-id.md * Update 2024-11-03-reauth-reconfigure-entry-id.md * Update 2024-11-03-reauth-reconfigure-entry-id.md * Update blog/2024-11-03-reauth-reconfigure-entry-id.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update 2024-11-03-reauth-reconfigure-entry-id.md * Rename 2024-11-03-reauth-reconfigure-entry-id.md to 2024-11-04-reauth-reconfigure-entry-id.md * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
610a095506
commit
90eaf726cd
47
blog/2024-11-04-reauth-reconfigure-entry-id.md
Normal file
47
blog/2024-11-04-reauth-reconfigure-entry-id.md
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
author: epenet
|
||||
authorURL: https://github.com/epenet
|
||||
title: "Reauth and reconfigure flows need to be linked to a config entry"
|
||||
---
|
||||
|
||||
Starting a reauth or a reconfigure flow without a link to the config entry has been deprecated, and will start failing in 2025.12.
|
||||
|
||||
Custom integrations should be updated to trigger the reauth flow using the `entry.async_start_reauth(hass)` helper.
|
||||
```python
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
try:
|
||||
await self.device.press_button()
|
||||
except DevicePasswordProtected as ex:
|
||||
self.entry.async_start_reauth(self.hass)
|
||||
```
|
||||
|
||||
Old incorrect code:
|
||||
```python
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
try:
|
||||
await self.device.press_button()
|
||||
except DevicePasswordProtected as ex:
|
||||
# old incorrect code:
|
||||
self.hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(DOMAIN, context={"source": SOURCE_REAUTH}
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
Custom integrations can also raise a `ConfigEntryAuthFailed` exception during the initialization phase, or within the update method of a data update coordinator.
|
||||
|
||||
```python
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up integration from a config entry."""
|
||||
username = entry.data[CONF_USERNAME]
|
||||
password = entry.data[CONF_PASSWORD]
|
||||
|
||||
if not _credentials_valid(username, password):
|
||||
raise ConfigEntryAuthFailed()
|
||||
```
|
||||
|
||||
Starting a reconfigure flow is only done by the frontend and custom integrations should not need to change anything for these flows.
|
||||
|
||||
More details can be found in the [reconfigure](/docs/config_entries_config_flow_handler#reconfigure) and [reauthentication](/docs/config_entries_config_flow_handler#reauthentication) documentation.
|
Loading…
x
Reference in New Issue
Block a user