hass-core/homeassistant/components/onboarding/__init__.py
cgtobi 2c07bfb9e0 Remove dependencies and requirements (#23024)
* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit fe7171b4cd.

* Remove dependencies and requirements

* Revert "Remove dependencies and requirements"

This reverts commit 391355ee2c.

* Remove dependencies and requirements

* Fix flake8 complaints

* Fix more flake8 complaints

* Revert non-component removals
2019-04-12 10:13:30 -07:00

52 lines
1.2 KiB
Python

"""Support to help onboard new users."""
from homeassistant.core import callback
from homeassistant.loader import bind_hass
from .const import DOMAIN, STEP_USER, STEPS
STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
@bind_hass
@callback
def async_is_onboarded(hass):
"""Return if Home Assistant has been onboarded."""
return hass.data.get(DOMAIN, True)
async def async_setup(hass, config):
"""Set up the onboarding component."""
store = hass.helpers.storage.Store(
STORAGE_VERSION, STORAGE_KEY, private=True)
data = await store.async_load()
if data is None:
data = {
'done': []
}
if STEP_USER not in data['done']:
# Users can already have created an owner account via the command line
# If so, mark the user step as done.
has_owner = False
for user in await hass.auth.async_get_users():
if user.is_owner:
has_owner = True
break
if has_owner:
data['done'].append(STEP_USER)
await store.async_save(data)
if set(data['done']) == set(STEPS):
return True
hass.data[DOMAIN] = False
from . import views
await views.async_setup(hass, data, store)
return True