mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Create a person during onboarding (#21057)
This commit is contained in:
parent
bf0a50cdb2
commit
50ba3d0427
@ -11,6 +11,7 @@ DEPENDENCIES = (
|
|||||||
'history',
|
'history',
|
||||||
'logbook',
|
'logbook',
|
||||||
'map',
|
'map',
|
||||||
|
'person',
|
||||||
'script',
|
'script',
|
||||||
'sun',
|
'sun',
|
||||||
'system_health',
|
'system_health',
|
||||||
|
@ -94,6 +94,10 @@ class UserOnboardingView(_BaseOnboardingView):
|
|||||||
})
|
})
|
||||||
await provider.data.async_save()
|
await provider.data.async_save()
|
||||||
await hass.auth.async_link_user(user, credentials)
|
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)
|
await self._async_mark_done(hass)
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
|
|||||||
from homeassistant.components import websocket_api
|
from homeassistant.components import websocket_api
|
||||||
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
|
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
from homeassistant.loader import bind_hass
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
ATTR_EDITABLE = 'editable'
|
ATTR_EDITABLE = 'editable'
|
||||||
@ -51,6 +52,17 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
_UNDEF = object()
|
_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:
|
class PersonManager:
|
||||||
"""Manage person data."""
|
"""Manage person data."""
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ async def test_onboarding_user_already_done(hass, hass_storage,
|
|||||||
|
|
||||||
async def test_onboarding_user(hass, hass_storage, aiohttp_client):
|
async def test_onboarding_user(hass, hass_storage, aiohttp_client):
|
||||||
"""Test creating a new user."""
|
"""Test creating a new user."""
|
||||||
|
assert await async_setup_component(hass, 'person', {})
|
||||||
mock_storage(hass_storage, {
|
mock_storage(hass_storage, {
|
||||||
'done': ['hello']
|
'done': ['hello']
|
||||||
})
|
})
|
||||||
@ -90,6 +91,7 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
|
|||||||
assert user.name == 'Test Name'
|
assert user.name == 'Test Name'
|
||||||
assert len(user.credentials) == 1
|
assert len(user.credentials) == 1
|
||||||
assert user.credentials[0].data['username'] == 'test-user'
|
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,
|
async def test_onboarding_user_invalid_name(hass, hass_storage,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user