mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use reauth_confirm in osoenergy (#128665)
This commit is contained in:
parent
1f8fd52103
commit
bea13d039f
@ -7,12 +7,7 @@ from typing import Any
|
|||||||
from apyosoenergyapi import OSOEnergy
|
from apyosoenergyapi import OSOEnergy
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
SOURCE_REAUTH,
|
|
||||||
ConfigEntry,
|
|
||||||
ConfigFlow,
|
|
||||||
ConfigFlowResult,
|
|
||||||
)
|
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
|
|
||||||
@ -27,10 +22,6 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Initialize."""
|
|
||||||
self.entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
|
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
errors = {}
|
errors = {}
|
||||||
@ -40,12 +31,10 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
if user_email := await self.get_user_email(user_input[CONF_API_KEY]):
|
if user_email := await self.get_user_email(user_input[CONF_API_KEY]):
|
||||||
await self.async_set_unique_id(user_email)
|
await self.async_set_unique_id(user_email)
|
||||||
|
|
||||||
if self.context["source"] == SOURCE_REAUTH and self.entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.entry, title=user_email, data=user_input
|
self._get_reauth_entry(), title=user_email, data=user_input
|
||||||
)
|
)
|
||||||
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(title=user_email, data=user_input)
|
return self.async_create_entry(title=user_email, data=user_input)
|
||||||
@ -72,6 +61,9 @@ class OSOEnergyFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Re Authenticate a user."""
|
"""Re Authenticate a user."""
|
||||||
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
return self.async_show_form(
|
||||||
data = {CONF_API_KEY: entry_data[CONF_API_KEY]}
|
step_id="user",
|
||||||
return await self.async_step_user(data)
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
|
_SCHEMA_STEP_USER, self._get_reauth_entry().data
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@ -68,7 +68,8 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
result = await mock_config.start_reauth_flow(hass)
|
result = await mock_config.start_reauth_flow(hass)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {"base": "invalid_auth"}
|
assert result["step_id"] == "user"
|
||||||
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.osoenergy.config_flow.OSOEnergy.get_user_email",
|
"homeassistant.components.osoenergy.config_flow.OSOEnergy.get_user_email",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user