mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use reauth helpers in ring (#128663)
This commit is contained in:
parent
bea13d039f
commit
d4c9841e44
@ -9,7 +9,7 @@ from ring_doorbell import Auth, AuthenticationError, Requires2FAError
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_DEVICE_ID,
|
CONF_DEVICE_ID,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
@ -71,7 +71,6 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
user_pass: dict[str, Any] = {}
|
user_pass: dict[str, Any] = {}
|
||||||
hardware_id: str | None = None
|
hardware_id: str | None = None
|
||||||
reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
async def async_step_dhcp(
|
async def async_step_dhcp(
|
||||||
self, discovery_info: dhcp.DhcpServiceInfo
|
self, discovery_info: dhcp.DhcpServiceInfo
|
||||||
@ -132,7 +131,7 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle 2fa step."""
|
"""Handle 2fa step."""
|
||||||
if user_input:
|
if user_input:
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return await self.async_step_reauth_confirm(
|
return await self.async_step_reauth_confirm(
|
||||||
{**self.user_pass, **user_input}
|
{**self.user_pass, **user_input}
|
||||||
)
|
)
|
||||||
@ -148,9 +147,6 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reauth upon an API authentication error."""
|
"""Handle reauth upon an API authentication error."""
|
||||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -158,14 +154,14 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Dialog that informs the user that reauth is required."""
|
"""Dialog that informs the user that reauth is required."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
assert self.reauth_entry is not None
|
|
||||||
|
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
if user_input:
|
if user_input:
|
||||||
user_input[CONF_USERNAME] = self.reauth_entry.data[CONF_USERNAME]
|
user_input[CONF_USERNAME] = reauth_entry.data[CONF_USERNAME]
|
||||||
# Reauth will use the same hardware id and re-authorise an existing
|
# Reauth will use the same hardware id and re-authorise an existing
|
||||||
# authorised device.
|
# authorised device.
|
||||||
if not self.hardware_id:
|
if not self.hardware_id:
|
||||||
self.hardware_id = self.reauth_entry.data[CONF_DEVICE_ID]
|
self.hardware_id = reauth_entry.data[CONF_DEVICE_ID]
|
||||||
assert self.hardware_id
|
assert self.hardware_id
|
||||||
try:
|
try:
|
||||||
token = await validate_input(self.hass, self.hardware_id, user_input)
|
token = await validate_input(self.hass, self.hardware_id, user_input)
|
||||||
@ -183,19 +179,15 @@ class RingConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_TOKEN: token,
|
CONF_TOKEN: token,
|
||||||
CONF_DEVICE_ID: self.hardware_id,
|
CONF_DEVICE_ID: self.hardware_id,
|
||||||
}
|
}
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(reauth_entry, data=data)
|
||||||
self.reauth_entry, data=data
|
|
||||||
)
|
|
||||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=STEP_REAUTH_DATA_SCHEMA,
|
data_schema=STEP_REAUTH_DATA_SCHEMA,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders={
|
description_placeholders={
|
||||||
CONF_USERNAME: self.reauth_entry.data[CONF_USERNAME],
|
CONF_USERNAME: reauth_entry.data[CONF_USERNAME],
|
||||||
CONF_NAME: self.reauth_entry.data[CONF_USERNAME],
|
CONF_NAME: reauth_entry.data[CONF_USERNAME],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user