mirror of
https://github.com/home-assistant/core.git
synced 2025-09-06 13:21:33 +02:00
Abort config flow if user has no friends in PlayStation Network (#150301)
This commit is contained in:
@@ -202,6 +202,9 @@ class FriendSubentryFlowHandler(ConfigSubentryFlow):
|
||||
}
|
||||
)
|
||||
|
||||
if not self.friends_list:
|
||||
return self.async_abort(reason="no_friends")
|
||||
|
||||
options = [
|
||||
SelectOptionDict(
|
||||
value=friend.account_id,
|
||||
@@ -209,6 +212,7 @@ class FriendSubentryFlowHandler(ConfigSubentryFlow):
|
||||
)
|
||||
for friend in self.friends_list.values()
|
||||
]
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=self.add_suggested_values_to_schema(
|
||||
|
@@ -69,7 +69,8 @@
|
||||
},
|
||||
"abort": {
|
||||
"already_configured_as_entry": "Already configured as a service. This account cannot be added as a friend.",
|
||||
"already_configured": "Already configured as a friend in this or another account."
|
||||
"already_configured": "Already configured as a friend in this or another account.",
|
||||
"no_friends": "Looks like your friend list is empty right now. Add friends on PlayStation Network first."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@@ -493,3 +493,27 @@ async def test_add_friend_flow_already_configured_as_entry(
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured_as_entry"
|
||||
|
||||
|
||||
async def test_add_friend_flow_no_friends(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
mock_psnawpapi: MagicMock,
|
||||
) -> None:
|
||||
"""Test we abort add friend subentry flow when the user has no friends."""
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_psnawpapi.user.return_value.friends_list.return_value = []
|
||||
|
||||
result = await hass.config_entries.subentries.async_init(
|
||||
(config_entry.entry_id, "friend"),
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "no_friends"
|
||||
|
Reference in New Issue
Block a user