mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use reauth_confirm in ovo_energy (#129306)
This commit is contained in:
parent
1d23adcda3
commit
e5b25bfa58
@ -79,22 +79,26 @@ class OVOEnergyFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_reauth(
|
async def async_step_reauth(
|
||||||
self,
|
self,
|
||||||
user_input: Mapping[str, Any],
|
entry_data: Mapping[str, Any],
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle configuration by re-auth."""
|
"""Handle configuration by re-auth."""
|
||||||
errors = {}
|
self.username = entry_data.get(CONF_USERNAME)
|
||||||
|
self.account = entry_data.get(CONF_ACCOUNT)
|
||||||
if user_input and user_input.get(CONF_USERNAME):
|
|
||||||
self.username = user_input[CONF_USERNAME]
|
|
||||||
|
|
||||||
if user_input and user_input.get(CONF_ACCOUNT):
|
|
||||||
self.account = user_input[CONF_ACCOUNT]
|
|
||||||
|
|
||||||
if self.username:
|
if self.username:
|
||||||
# If we have a username, use it as flow title
|
# If we have a username, use it as flow title
|
||||||
self.context["title_placeholders"] = {CONF_USERNAME: self.username}
|
self.context["title_placeholders"] = {CONF_USERNAME: self.username}
|
||||||
|
|
||||||
if user_input is not None and user_input.get(CONF_PASSWORD) is not None:
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(
|
||||||
|
self,
|
||||||
|
user_input: Mapping[str, Any] | None = None,
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle configuration by re-auth."""
|
||||||
|
errors = {}
|
||||||
|
|
||||||
|
if user_input is not None:
|
||||||
client = OVOEnergy(
|
client = OVOEnergy(
|
||||||
client_session=async_get_clientsession(self.hass),
|
client_session=async_get_clientsession(self.hass),
|
||||||
)
|
)
|
||||||
@ -111,19 +115,13 @@ class OVOEnergyFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "connection_error"
|
errors["base"] = "connection_error"
|
||||||
else:
|
else:
|
||||||
if authenticated:
|
if authenticated:
|
||||||
entry = await self.async_set_unique_id(self.username)
|
return self.async_update_reload_and_abort(
|
||||||
if entry:
|
self._get_reauth_entry(),
|
||||||
self.hass.config_entries.async_update_entry(
|
data_updates={CONF_PASSWORD: user_input[CONF_PASSWORD]},
|
||||||
entry,
|
)
|
||||||
data={
|
|
||||||
CONF_USERNAME: self.username,
|
|
||||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
errors["base"] = "authorization_error"
|
errors["base"] = "authorization_error"
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth", data_schema=REAUTH_SCHEMA, errors=errors
|
step_id="reauth_confirm", data_schema=REAUTH_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"description": "Set up an OVO Energy instance to access your energy usage.",
|
"description": "Set up an OVO Energy instance to access your energy usage.",
|
||||||
"title": "Add OVO Energy Account"
|
"title": "Add OVO Energy Account"
|
||||||
},
|
},
|
||||||
"reauth": {
|
"reauth_confirm": {
|
||||||
"data": {
|
"data": {
|
||||||
"password": "[%key:common::config_flow::data::password%]"
|
"password": "[%key:common::config_flow::data::password%]"
|
||||||
},
|
},
|
||||||
|
@ -131,15 +131,14 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None:
|
|||||||
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
||||||
)
|
)
|
||||||
mock_config.add_to_hass(hass)
|
mock_config.add_to_hass(hass)
|
||||||
|
result = await mock_config.start_reauth_flow(hass)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
||||||
return_value=False,
|
return_value=False,
|
||||||
):
|
):
|
||||||
result = await mock_config.start_reauth_flow(hass)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
|
||||||
assert result["step_id"] == "reauth"
|
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
FIXTURE_REAUTH_INPUT,
|
FIXTURE_REAUTH_INPUT,
|
||||||
@ -147,7 +146,7 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.FORM
|
assert result2["type"] is FlowResultType.FORM
|
||||||
assert result2["step_id"] == "reauth"
|
assert result2["step_id"] == "reauth_confirm"
|
||||||
assert result2["errors"] == {"base": "authorization_error"}
|
assert result2["errors"] == {"base": "authorization_error"}
|
||||||
|
|
||||||
|
|
||||||
@ -161,15 +160,16 @@ async def test_reauth_connection_error(hass: HomeAssistant) -> None:
|
|||||||
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
||||||
)
|
)
|
||||||
mock_config.add_to_hass(hass)
|
mock_config.add_to_hass(hass)
|
||||||
|
result = await mock_config.start_reauth_flow(hass)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
||||||
side_effect=aiohttp.ClientError,
|
side_effect=aiohttp.ClientError,
|
||||||
):
|
):
|
||||||
result = await mock_config.start_reauth_flow(hass)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
|
||||||
assert result["step_id"] == "reauth"
|
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
FIXTURE_REAUTH_INPUT,
|
FIXTURE_REAUTH_INPUT,
|
||||||
@ -177,7 +177,7 @@ async def test_reauth_connection_error(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.FORM
|
assert result2["type"] is FlowResultType.FORM
|
||||||
assert result2["step_id"] == "reauth"
|
assert result2["step_id"] == "reauth_confirm"
|
||||||
assert result2["errors"] == {"base": "connection_error"}
|
assert result2["errors"] == {"base": "connection_error"}
|
||||||
|
|
||||||
|
|
||||||
@ -196,14 +196,22 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
domain=DOMAIN, unique_id=UNIQUE_ID, data=FIXTURE_USER_INPUT
|
||||||
)
|
)
|
||||||
mock_config.add_to_hass(hass)
|
mock_config.add_to_hass(hass)
|
||||||
|
result = await mock_config.start_reauth_flow(hass)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
"homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate",
|
||||||
return_value=False,
|
return_value=False,
|
||||||
):
|
):
|
||||||
result = await mock_config.start_reauth_flow(hass)
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
FIXTURE_REAUTH_INPUT,
|
||||||
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["errors"] == {"base": "authorization_error"}
|
assert result["errors"] == {"base": "authorization_error"}
|
||||||
|
|
||||||
with (
|
with (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user