From 39a00ffe09dbaed86943ca540f62aaf29917abb2 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 22 Jun 2022 09:49:54 +0200 Subject: [PATCH] Automatically onboard Cast (#73813) --- homeassistant/components/cast/config_flow.py | 4 ++-- tests/components/cast/test_config_flow.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/cast/config_flow.py b/homeassistant/components/cast/config_flow.py index fc657fd2422..1c983d6f67a 100644 --- a/homeassistant/components/cast/config_flow.py +++ b/homeassistant/components/cast/config_flow.py @@ -6,7 +6,7 @@ from typing import Any import voluptuous as vol from homeassistant import config_entries -from homeassistant.components import zeroconf +from homeassistant.components import onboarding, zeroconf from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import config_validation as cv @@ -102,7 +102,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): data = self._get_data() - if user_input is not None: + if user_input is not None or not onboarding.async_is_onboarded(self.hass): return self.async_create_entry(title="Google Cast", data=data) return self.async_show_form(step_id="confirm") diff --git a/tests/components/cast/test_config_flow.py b/tests/components/cast/test_config_flow.py index 1ad89c7a8e5..d7aa0fdeda9 100644 --- a/tests/components/cast/test_config_flow.py +++ b/tests/components/cast/test_config_flow.py @@ -116,6 +116,26 @@ async def test_zeroconf_setup(hass): } +async def test_zeroconf_setup_onboarding(hass): + """Test we automatically finish a config flow through zeroconf during onboarding.""" + with patch( + "homeassistant.components.onboarding.async_is_onboarded", return_value=False + ): + result = await hass.config_entries.flow.async_init( + "cast", context={"source": config_entries.SOURCE_ZEROCONF} + ) + + users = await hass.auth.async_get_users() + assert len(users) == 1 + assert result["type"] == "create_entry" + assert result["result"].data == { + "ignore_cec": [], + "known_hosts": [], + "uuid": [], + "user_id": users[0].id, # Home Assistant cast user + } + + def get_suggested(schema, key): """Get suggested value for key in voluptuous schema.""" for k in schema.keys():