Add view to get installation type during onboarding (#56095)

pull/56107/head
Joakim Sørensen 2021-09-11 15:38:38 +02:00 committed by GitHub
parent ec21c5f4a9
commit 1b46190a0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -1,6 +1,7 @@
"""Onboarding views."""
import asyncio
from aiohttp.web_exceptions import HTTPUnauthorized
import voluptuous as vol
from homeassistant.auth.const import GROUP_ID_ADMIN
@ -10,6 +11,7 @@ from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.http.view import HomeAssistantView
from homeassistant.const import HTTP_BAD_REQUEST, HTTP_FORBIDDEN
from homeassistant.core import callback
from homeassistant.helpers.system_info import async_get_system_info
from .const import (
DEFAULT_AREAS,
@ -25,6 +27,7 @@ from .const import (
async def async_setup(hass, data, store):
"""Set up the onboarding view."""
hass.http.register_view(OnboardingView(data, store))
hass.http.register_view(InstallationTypeOnboardingView(data))
hass.http.register_view(UserOnboardingView(data, store))
hass.http.register_view(CoreConfigOnboardingView(data, store))
hass.http.register_view(IntegrationOnboardingView(data, store))
@ -50,6 +53,27 @@ class OnboardingView(HomeAssistantView):
)
class InstallationTypeOnboardingView(HomeAssistantView):
"""Return the installation type during onboarding."""
requires_auth = False
url = "/api/onboarding/installation_type"
name = "api:onboarding:installation_type"
def __init__(self, data):
"""Initialize the onboarding installation type view."""
self._data = data
async def get(self, request):
"""Return the onboarding status."""
if self._data["done"]:
raise HTTPUnauthorized()
hass = request.app["hass"]
info = await async_get_system_info(hass)
return self.json({"installation_type": info["installation_type"]})
class _BaseOnboardingView(HomeAssistantView):
"""Base class for onboarding."""

View File

@ -442,3 +442,40 @@ async def test_onboarding_analytics(hass, hass_storage, hass_client, hass_admin_
resp = await client.post("/api/onboarding/analytics")
assert resp.status == 403
async def test_onboarding_installation_type(hass, hass_storage, hass_client):
"""Test returning installation type during onboarding."""
mock_storage(hass_storage, {"done": []})
await async_setup_component(hass, "persistent_notification", {})
assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client()
with patch(
"homeassistant.components.onboarding.views.async_get_system_info",
return_value={"installation_type": "Home Assistant Core"},
):
resp = await client.get("/api/onboarding/installation_type")
assert resp.status == 200
resp_content = await resp.json()
assert resp_content["installation_type"] == "Home Assistant Core"
async def test_onboarding_installation_type_after_done(hass, hass_storage, hass_client):
"""Test raising for installation type after onboarding."""
mock_storage(hass_storage, {"done": [const.STEP_USER]})
await async_setup_component(hass, "persistent_notification", {})
assert await async_setup_component(hass, "onboarding", {})
await hass.async_block_till_done()
client = await hass_client()
resp = await client.get("/api/onboarding/installation_type")
assert resp.status == 401