mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Abort add friend subentry flow for disabled config entry in PlayStation Network (#149784)
This commit is contained in:
@@ -16,6 +16,7 @@ import voluptuous as vol
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
ConfigEntry,
|
||||
ConfigEntryState,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
ConfigSubentryFlow,
|
||||
@@ -173,6 +174,8 @@ class FriendSubentryFlowHandler(ConfigSubentryFlow):
|
||||
) -> SubentryFlowResult:
|
||||
"""Subentry user flow."""
|
||||
config_entry: PlaystationNetworkConfigEntry = self._get_entry()
|
||||
if config_entry.state is not ConfigEntryState.LOADED:
|
||||
return self.async_abort(reason="config_entry_disabled")
|
||||
friends_list = config_entry.runtime_data.user_data.psn.friends_list
|
||||
|
||||
if user_input is not None:
|
||||
|
||||
@@ -70,7 +70,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.",
|
||||
"no_friends": "Looks like your friend list is empty right now. Add friends on PlayStation Network first."
|
||||
"no_friends": "Looks like your friend list is empty right now. Add friends on PlayStation Network first.",
|
||||
"config_entry_disabled": "Cannot add friend accounts when the main account is disabled or not loaded."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@ from homeassistant.components.playstation_network.const import (
|
||||
)
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_USER,
|
||||
ConfigEntryDisabler,
|
||||
ConfigEntryState,
|
||||
ConfigSubentry,
|
||||
ConfigSubentryData,
|
||||
@@ -516,3 +517,29 @@ async def test_add_friend_flow_no_friends(
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "no_friends"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_psnawpapi")
|
||||
async def test_add_friend_disabled_config_entry(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test we abort add friend subentry flow when the parent config entry is disabled."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="test-user",
|
||||
data={
|
||||
CONF_NPSSO: NPSSO_TOKEN,
|
||||
},
|
||||
disabled_by=ConfigEntryDisabler.USER,
|
||||
unique_id=PSN_ID,
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
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"] == "config_entry_disabled"
|
||||
|
||||
Reference in New Issue
Block a user