Abort config flow if user has no friends in PlayStation Network (#150301)

This commit is contained in:
Manu
2025-08-09 07:44:35 +02:00
committed by GitHub
parent 73be4625ae
commit 5c1d16d582
3 changed files with 30 additions and 1 deletions

View File

@@ -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(

View File

@@ -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."
}
}
},

View File

@@ -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"