Use new reauth helpers in yale_smart_alarm (#128836)

This commit is contained in:
epenet 2024-10-20 23:52:37 +02:00 committed by GitHub
parent f01231277b
commit 6bfed5c98c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 24 deletions

View File

@ -40,7 +40,6 @@ DATA_SCHEMA = vol.Schema(
DATA_SCHEMA_AUTH = vol.Schema(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)
@ -51,8 +50,6 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 2
entry: ConfigEntry | None
@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> YaleOptionsFlowHandler:
@ -63,7 +60,6 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle initiation of re-authentication with Yale."""
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
@ -73,7 +69,8 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
errors = {}
if user_input is not None:
username = user_input[CONF_USERNAME]
reauth_entry = self._get_reauth_entry()
username = reauth_entry.data[CONF_USERNAME]
password = user_input[CONF_PASSWORD]
try:
@ -88,18 +85,10 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
errors = {"base": "cannot_connect"}
if not errors:
existing_entry = await self.async_set_unique_id(username)
if existing_entry and self.entry:
self.hass.config_entries.async_update_entry(
existing_entry,
data={
**self.entry.data,
CONF_USERNAME: username,
CONF_PASSWORD: password,
},
)
await self.hass.config_entries.async_reload(existing_entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_update_reload_and_abort(
reauth_entry,
data_updates={CONF_PASSWORD: password},
)
return self.async_show_form(
step_id="reauth_confirm",

View File

@ -19,10 +19,7 @@
},
"reauth_confirm": {
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]",
"name": "[%key:common::config_flow::data::name%]",
"area_id": "[%key:component::yale_smart_alarm::config::step::user::data::area_id%]"
"password": "[%key:common::config_flow::data::password%]"
}
}
}

View File

@ -149,7 +149,6 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "new-test-password",
},
)
@ -203,7 +202,6 @@ async def test_reauth_flow_error(
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "wrong-password",
},
)
@ -226,7 +224,6 @@ async def test_reauth_flow_error(
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "new-test-password",
},
)