Guard creating areas in onboarding (#74306)

This commit is contained in:
Paulus Schoutsen 2022-07-01 11:01:07 -07:00 committed by GitHub
parent 1288085b31
commit 810e29f1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -156,9 +156,11 @@ class UserOnboardingView(_BaseOnboardingView):
area_registry = ar.async_get(hass)
for area in DEFAULT_AREAS:
area_registry.async_create(
translations[f"component.onboarding.area.{area}"]
)
name = 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)

View File

@ -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):
"""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, "onboarding", {})
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
area_registry = ar.async_get(hass)
assert len(area_registry.areas) == 3
assert sorted(area.name for area in area_registry.async_list_areas()) == [
"Bedroom",