From f9cd67675f01283c48ad5140fe6cff2aadc71e59 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:48:56 +0100 Subject: [PATCH] Import auth, hassio and person in onboarding (#64542) Co-authored-by: epenet --- homeassistant/components/onboarding/views.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/onboarding/views.py b/homeassistant/components/onboarding/views.py index 2fbeb5592f8..08bd38a8647 100644 --- a/homeassistant/components/onboarding/views.py +++ b/homeassistant/components/onboarding/views.py @@ -8,6 +8,7 @@ from aiohttp.web_exceptions import HTTPUnauthorized import voluptuous as vol from homeassistant.auth.const import GROUP_ID_ADMIN +from homeassistant.components import auth, hassio, person from homeassistant.components.auth import indieauth from homeassistant.components.http.const import KEY_HASS_REFRESH_TOKEN_ID from homeassistant.components.http.data_validator import RequestDataValidator @@ -143,9 +144,7 @@ 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 person.async_create_person(hass, data["name"], user_id=user.id) # Create default areas using the users supplied language. translations = await hass.helpers.translation.async_get_translations( @@ -163,9 +162,7 @@ class UserOnboardingView(_BaseOnboardingView): # Return authorization code for fetching tokens and connect # during onboarding. - auth_code = hass.components.auth.create_auth_code( - data["client_id"], credentials - ) + auth_code = auth.create_auth_code(hass, data["client_id"], credentials) return self.json({"auth_code": auth_code}) @@ -193,8 +190,8 @@ class CoreConfigOnboardingView(_BaseOnboardingView): ) if ( - hass.components.hassio.is_hassio() - and "raspberrypi" in hass.components.hassio.get_core_info()["machine"] + hassio.is_hassio(hass) + and "raspberrypi" in hassio.get_core_info(hass)["machine"] ): await hass.config_entries.flow.async_init( "rpi_power", context={"source": "onboarding"} @@ -241,8 +238,8 @@ class IntegrationOnboardingView(_BaseOnboardingView): ) # Return authorization code so we can redirect user and log them in - auth_code = hass.components.auth.create_auth_code( - data["client_id"], refresh_token.credential + auth_code = auth.create_auth_code( + hass, data["client_id"], refresh_token.credential ) return self.json({"auth_code": auth_code})