Create a person during onboarding (#21057)

This commit is contained in:
Paulus Schoutsen 2019-02-13 20:00:08 -08:00 committed by GitHub
parent bf0a50cdb2
commit 50ba3d0427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View File

@ -11,6 +11,7 @@ DEPENDENCIES = (
'history',
'logbook',
'map',
'person',
'script',
'sun',
'system_health',

View File

@ -94,6 +94,10 @@ class UserOnboardingView(_BaseOnboardingView):
})
await provider.data.async_save()
await hass.auth.async_link_user(user, credentials)
if 'person' in hass.config.components:
await hass.components.person.async_create_person(
data['name'], user_id=user.id
)
await self._async_mark_done(hass)

View File

@ -24,6 +24,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.components import websocket_api
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
from homeassistant.util import dt as dt_util
from homeassistant.loader import bind_hass
_LOGGER = logging.getLogger(__name__)
ATTR_EDITABLE = 'editable'
@ -51,6 +52,17 @@ CONFIG_SCHEMA = vol.Schema({
_UNDEF = object()
@bind_hass
async def async_create_person(hass, name, *, user_id=None,
device_trackers=None):
"""Create a new person."""
await hass.data[DOMAIN].async_create_person(
name=name,
user_id=user_id,
device_trackers=device_trackers,
)
class PersonManager:
"""Manage person data."""

View File

@ -69,6 +69,7 @@ async def test_onboarding_user_already_done(hass, hass_storage,
async def test_onboarding_user(hass, hass_storage, aiohttp_client):
"""Test creating a new user."""
assert await async_setup_component(hass, 'person', {})
mock_storage(hass_storage, {
'done': ['hello']
})
@ -90,6 +91,7 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
assert user.name == 'Test Name'
assert len(user.credentials) == 1
assert user.credentials[0].data['username'] == 'test-user'
assert len(hass.data['person'].storage_data) == 1
async def test_onboarding_user_invalid_name(hass, hass_storage,