mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Guard creating areas in onboarding (#74306)
This commit is contained in:
parent
1288085b31
commit
810e29f1ef
@ -156,9 +156,11 @@ class UserOnboardingView(_BaseOnboardingView):
|
|||||||
area_registry = ar.async_get(hass)
|
area_registry = ar.async_get(hass)
|
||||||
|
|
||||||
for area in DEFAULT_AREAS:
|
for area in DEFAULT_AREAS:
|
||||||
area_registry.async_create(
|
name = translations[f"component.onboarding.area.{area}"]
|
||||||
translations[f"component.onboarding.area.{area}"]
|
# Guard because area might have been created by an automatically
|
||||||
)
|
# set up integration.
|
||||||
|
if not area_registry.async_get_area_by_name(name):
|
||||||
|
area_registry.async_create(name)
|
||||||
|
|
||||||
await self._async_mark_done(hass)
|
await self._async_mark_done(hass)
|
||||||
|
|
||||||
|
@ -144,6 +144,12 @@ async def test_onboarding_user_already_done(hass, hass_storage, hass_client_no_a
|
|||||||
|
|
||||||
async def test_onboarding_user(hass, hass_storage, hass_client_no_auth):
|
async def test_onboarding_user(hass, hass_storage, hass_client_no_auth):
|
||||||
"""Test creating a new user."""
|
"""Test creating a new user."""
|
||||||
|
area_registry = ar.async_get(hass)
|
||||||
|
|
||||||
|
# Create an existing area to mimic an integration creating an area
|
||||||
|
# before onboarding is done.
|
||||||
|
area_registry.async_create("Living Room")
|
||||||
|
|
||||||
assert await async_setup_component(hass, "person", {})
|
assert await async_setup_component(hass, "person", {})
|
||||||
assert await async_setup_component(hass, "onboarding", {})
|
assert await async_setup_component(hass, "onboarding", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -194,7 +200,6 @@ async def test_onboarding_user(hass, hass_storage, hass_client_no_auth):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Validate created areas
|
# Validate created areas
|
||||||
area_registry = ar.async_get(hass)
|
|
||||||
assert len(area_registry.areas) == 3
|
assert len(area_registry.areas) == 3
|
||||||
assert sorted(area.name for area in area_registry.async_list_areas()) == [
|
assert sorted(area.name for area in area_registry.async_list_areas()) == [
|
||||||
"Bedroom",
|
"Bedroom",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user