mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add reconfigure flow to Ohme (#140835)
* Add reconfigure flow to Ohme * Remove incorrect unique ID check from ohme reconfig
This commit is contained in:
parent
5438532780
commit
30c19ec373
@ -99,6 +99,29 @@ class OhmeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def async_step_reconfigure(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle re-configuration."""
|
||||||
|
errors: dict[str, str] = {}
|
||||||
|
reconfigure_entry = self._get_reconfigure_entry()
|
||||||
|
if user_input:
|
||||||
|
errors = await self._validate_account(
|
||||||
|
reconfigure_entry.data[CONF_EMAIL],
|
||||||
|
user_input[CONF_PASSWORD],
|
||||||
|
)
|
||||||
|
if not errors:
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
reconfigure_entry,
|
||||||
|
data_updates=user_input,
|
||||||
|
)
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="reconfigure",
|
||||||
|
data_schema=REAUTH_SCHEMA,
|
||||||
|
description_placeholders={"email": reconfigure_entry.data[CONF_EMAIL]},
|
||||||
|
errors=errors,
|
||||||
|
)
|
||||||
|
|
||||||
async def _validate_account(self, email: str, password: str) -> dict[str, str]:
|
async def _validate_account(self, email: str, password: str) -> dict[str, str]:
|
||||||
"""Validate Ohme account and return dict of errors."""
|
"""Validate Ohme account and return dict of errors."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
@ -62,7 +62,7 @@ rules:
|
|||||||
entity-translations: done
|
entity-translations: done
|
||||||
exception-translations: done
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: todo
|
reconfiguration-flow: done
|
||||||
repair-issues:
|
repair-issues:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: |
|
comment: |
|
||||||
|
@ -21,6 +21,16 @@
|
|||||||
"data_description": {
|
"data_description": {
|
||||||
"password": "Enter the password for your Ohme account"
|
"password": "Enter the password for your Ohme account"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"reconfigure": {
|
||||||
|
"description": "Update your password for {email}",
|
||||||
|
"title": "Reconfigure Ohme Account",
|
||||||
|
"data": {
|
||||||
|
"password": "[%key:common::config_flow::data::password%]"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"password": "Enter the password for your Ohme account"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
@ -29,7 +39,8 @@
|
|||||||
},
|
},
|
||||||
"abort": {
|
"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%]"
|
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
|
||||||
|
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
|
@ -182,3 +182,84 @@ async def test_reauth_fail(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reconfigure_form(hass: HomeAssistant, mock_client: MagicMock) -> None:
|
||||||
|
"""Test reconfigure form."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={
|
||||||
|
CONF_EMAIL: "test@example.com",
|
||||||
|
CONF_PASSWORD: "hunter1",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": "reconfigure", "entry_id": entry.entry_id}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reconfigure"
|
||||||
|
assert not result["errors"]
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_PASSWORD: "hunter2"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("test_exception", "expected_error"),
|
||||||
|
[(AuthException, "invalid_auth"), (ApiException, "unknown")],
|
||||||
|
)
|
||||||
|
async def test_reconfigure_fail(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_client: MagicMock,
|
||||||
|
test_exception: Exception,
|
||||||
|
expected_error: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test reconfigure errors."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={
|
||||||
|
CONF_EMAIL: "test@example.com",
|
||||||
|
CONF_PASSWORD: "hunter1",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": "reconfigure", "entry_id": entry.entry_id}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["step_id"] == "reconfigure"
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert not result["errors"]
|
||||||
|
|
||||||
|
# Simulate failed login attempt
|
||||||
|
mock_client.async_login.side_effect = test_exception
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_PASSWORD: "hunter1"},
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["errors"] == {"base": expected_error}
|
||||||
|
|
||||||
|
# Retry with a successful login
|
||||||
|
mock_client.async_login.side_effect = None
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_PASSWORD: "hunter2"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "reconfigure_successful"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user