mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Set up shopping list during onboarding (#97974)
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
parent
dfdf592837
commit
dacfa4b4dc
@ -193,7 +193,12 @@ class CoreConfigOnboardingView(_BaseOnboardingView):
|
|||||||
await self._async_mark_done(hass)
|
await self._async_mark_done(hass)
|
||||||
|
|
||||||
# Integrations to set up when finishing onboarding
|
# Integrations to set up when finishing onboarding
|
||||||
onboard_integrations = ["google_translate", "met", "radio_browser"]
|
onboard_integrations = [
|
||||||
|
"google_translate",
|
||||||
|
"met",
|
||||||
|
"radio_browser",
|
||||||
|
"shopping_list",
|
||||||
|
]
|
||||||
|
|
||||||
# pylint: disable-next=import-outside-toplevel
|
# pylint: disable-next=import-outside-toplevel
|
||||||
from homeassistant.components import hassio
|
from homeassistant.components import hassio
|
||||||
|
@ -1,23 +1,36 @@
|
|||||||
"""Config flow to configure ShoppingList component."""
|
"""Config flow to configure the shopping list integration."""
|
||||||
from homeassistant import config_entries
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigFlow
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
class ShoppingListFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
class ShoppingListFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
"""Config flow for ShoppingList component."""
|
"""Config flow for the shopping list integration."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
# Check if already configured
|
# Check if already configured
|
||||||
await self.async_set_unique_id(DOMAIN)
|
await self.async_set_unique_id(DOMAIN)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="Shopping List", data=user_input)
|
return self.async_create_entry(title="Shopping list", data={})
|
||||||
|
|
||||||
return self.async_show_form(step_id="user")
|
return self.async_show_form(step_id="user")
|
||||||
|
|
||||||
async_step_import = async_step_user
|
async_step_import = async_step_user
|
||||||
|
|
||||||
|
async def async_step_onboarding(
|
||||||
|
self, _: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Handle a flow initialized by onboarding."""
|
||||||
|
return await self.async_step_user(user_input={})
|
||||||
|
@ -117,6 +117,8 @@ def mock_default_integrations():
|
|||||||
"homeassistant.components.met.async_setup_entry", return_value=True
|
"homeassistant.components.met.async_setup_entry", return_value=True
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.radio_browser.async_setup_entry", return_value=True
|
"homeassistant.components.radio_browser.async_setup_entry", return_value=True
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.shopping_list.async_setup_entry", return_value=True
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -453,6 +455,27 @@ async def test_onboarding_core_sets_up_met(
|
|||||||
assert len(hass.config_entries.async_entries("met")) == 1
|
assert len(hass.config_entries.async_entries("met")) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_onboarding_core_sets_up_shopping_list(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_storage: dict[str, Any],
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_default_integrations,
|
||||||
|
) -> None:
|
||||||
|
"""Test finishing the core step set up the shopping list."""
|
||||||
|
mock_storage(hass_storage, {"done": [const.STEP_USER]})
|
||||||
|
|
||||||
|
assert await async_setup_component(hass, "onboarding", {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
client = await hass_client()
|
||||||
|
resp = await client.post("/api/onboarding/core_config")
|
||||||
|
|
||||||
|
assert resp.status == 200
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.config_entries.async_entries("shopping_list")) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_onboarding_core_sets_up_google_translate(
|
async def test_onboarding_core_sets_up_google_translate(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_storage: dict[str, Any],
|
hass_storage: dict[str, Any],
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""Test config flow."""
|
"""Test config flow."""
|
||||||
from homeassistant import data_entry_flow
|
|
||||||
from homeassistant.components.shopping_list.const import DOMAIN
|
from homeassistant.components.shopping_list.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant) -> None:
|
async def test_import(hass: HomeAssistant) -> None:
|
||||||
@ -11,7 +11,7 @@ async def test_import(hass: HomeAssistant) -> None:
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
|
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
async def test_user(hass: HomeAssistant) -> None:
|
async def test_user(hass: HomeAssistant) -> None:
|
||||||
@ -21,7 +21,7 @@ async def test_user(hass: HomeAssistant) -> None:
|
|||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
assert result["type"] == FlowResultType.FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
|
||||||
@ -32,5 +32,16 @@ async def test_user_confirm(hass: HomeAssistant) -> None:
|
|||||||
DOMAIN, context={"source": SOURCE_USER}, data={}
|
DOMAIN, context={"source": SOURCE_USER}, data={}
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
assert result["result"].data == {}
|
assert result["result"].data == {}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_onboarding_flow(hass: HomeAssistant) -> None:
|
||||||
|
"""Test the onboarding configuration flow."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": "onboarding"}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["title"] == "Shopping list"
|
||||||
|
assert result["data"] == {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user