Skip to content

Commit

Permalink
Update Roborock config flow message when an account is already config…
Browse files Browse the repository at this point in the history
…ured (#134854)
  • Loading branch information
allenporter authored and frenck committed Jan 6, 2025
1 parent fbd031a commit 29989e9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def async_step_user(
if user_input is not None:
username = user_input[CONF_USERNAME]
await self.async_set_unique_id(username.lower())
self._abort_if_unique_id_configured()
self._abort_if_unique_id_configured(error="already_configured_account")
self._username = username
_LOGGER.debug("Requesting code for Roborock account")
self._client = RoborockApiClient(username)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roborock/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"already_configured_account": "[%key:common::config_flow::abort::already_configured_account%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
Expand Down
1 change: 1 addition & 0 deletions tests/components/roborock/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def mock_roborock_entry(hass: HomeAssistant) -> MockConfigEntry:
CONF_USER_DATA: USER_DATA.as_dict(),
CONF_BASE_URL: BASE_URL,
},
unique_id=USER_EMAIL,
)
mock_entry.add_to_hass(hass)
return mock_entry
Expand Down
25 changes: 25 additions & 0 deletions tests/components/roborock/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,28 @@ async def test_reauth_flow(
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert mock_roborock_entry.data["user_data"]["rriot"]["s"] == "new_password_hash"


async def test_account_already_configured(
hass: HomeAssistant,
bypass_api_fixture,
mock_roborock_entry: MockConfigEntry,
) -> None:
"""Handle the config flow and make sure it succeeds."""
with patch(
"homeassistant.components.roborock.async_setup_entry", return_value=True
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
with patch(
"homeassistant.components.roborock.config_flow.RoborockApiClient.request_code"
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_USERNAME: USER_EMAIL}
)

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured_account"

0 comments on commit 29989e9

Please # to comment.