Use reauth helpers in permobil config flow (#127530)

This commit is contained in:
epenet 2024-10-07 11:37:28 +02:00 committed by GitHub
parent 563de82707
commit d99429463b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View File

@ -14,7 +14,7 @@ from mypermobil import (
)
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_CODE, CONF_EMAIL, CONF_REGION, CONF_TOKEN, CONF_TTL
from homeassistant.core import HomeAssistant, async_get_hass
from homeassistant.helpers import selector
@ -158,6 +158,11 @@ class PermobilConfigFlow(ConfigFlow, domain=DOMAIN):
description_placeholders={"app_name": "MyPermobil"},
)
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self._get_reauth_entry(), title=self.data[CONF_EMAIL], data=self.data
)
return self.async_create_entry(title=self.data[CONF_EMAIL], data=self.data)
async def async_step_reauth(

View File

@ -20,7 +20,8 @@
}
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
},
"error": {
"unknown": "Unexpected error, more information in the logs",

View File

@ -294,14 +294,15 @@ async def test_config_flow_reauth_success(
assert result["step_id"] == "email_code"
assert result["errors"] == {}
# request request new token
# request new token
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_CODE: reauth_code},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert mock_entry.data == {
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: reauth_code,