diff --git a/homeassistant/components/playstation_network/config_flow.py b/homeassistant/components/playstation_network/config_flow.py index 72df14dd239..e6220812219 100644 --- a/homeassistant/components/playstation_network/config_flow.py +++ b/homeassistant/components/playstation_network/config_flow.py @@ -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: diff --git a/homeassistant/components/playstation_network/strings.json b/homeassistant/components/playstation_network/strings.json index 72648be2cc2..845e32ea544 100644 --- a/homeassistant/components/playstation_network/strings.json +++ b/homeassistant/components/playstation_network/strings.json @@ -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." } } }, diff --git a/tests/components/playstation_network/test_config_flow.py b/tests/components/playstation_network/test_config_flow.py index 14c5633d384..f8caac72ccd 100644 --- a/tests/components/playstation_network/test_config_flow.py +++ b/tests/components/playstation_network/test_config_flow.py @@ -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"