Add integration step to onboarding (#23732)

* Return an extra oauth2 auth code during onboarding

* Areas in const

* Add integration step

* Lint

* Fix tests

* Fix test

* Verify integration added to done

* Verify step is marked as done
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-05-07 22:51:24 -07:00
1 parent 07ee3b2eb9
commit f4016b4aad
9 files changed
+205 -25

No files matched your search

@@ -1,24 +1,42 @@
"""Support to help onboard new users."""
from homeassistant.core import callback
from homeassistant.loader import bind_hass
from homeassistant.helpers.storage import Store
from .const import DOMAIN, STEP_USER, STEPS
from .const import DOMAIN, STEP_USER, STEPS, STEP_INTEGRATION
STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
STORAGE_VERSION = 2
class OnboadingStorage(Store):
"""Store onboarding data."""
async def _async_migrate_func(self, old_version, old_data):
"""Migrate to the new version."""
# From version 1 -> 2, we automatically mark the integration step done
old_data['done'].append(STEP_INTEGRATION)
return old_data
@bind_hass
@callback
def async_is_onboarded(hass):
"""Return if Home Assistant has been onboarded."""
return hass.data.get(DOMAIN, True)
data = hass.data.get(DOMAIN)
return data is None or data is True
@bind_hass
@callback
def async_is_user_onboarded(hass):
"""Return if a user has been created as part of onboarding."""
return async_is_onboarded(hass) or STEP_USER in hass.data[DOMAIN]['done']
async def async_setup(hass, config):
"""Set up the onboarding component."""
store = hass.helpers.storage.Store(
STORAGE_VERSION, STORAGE_KEY, private=True)
store = OnboadingStorage(hass, STORAGE_VERSION, STORAGE_KEY, private=True)
data = await store.async_load()
if data is None:
@@ -43,7 +61,7 @@ async def async_setup(hass, config):
if set(data['done']) == set(STEPS):
return True
hass.data[DOMAIN] = False
hass.data[DOMAIN] = data
from . import views