Automatically onboard Elgato (#73847)
This commit is contained in:
parent
ad7da9803f
commit
320ef55085
3 changed files with 50 additions and 1 deletions
|
@ -6,7 +6,7 @@ from typing import Any
|
|||
from elgato import Elgato, ElgatoError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components import onboarding, zeroconf
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT
|
||||
from homeassistant.core import callback
|
||||
|
@ -56,6 +56,9 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
except ElgatoError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
if not onboarding.async_is_onboarded(self.hass):
|
||||
return self._async_create_entry()
|
||||
|
||||
self._set_confirm_only()
|
||||
return self.async_show_form(
|
||||
step_id="zeroconf_confirm",
|
||||
|
|
|
@ -37,6 +37,16 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|||
yield mock_setup
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_onboarding() -> Generator[None, MagicMock, None]:
|
||||
"""Mock that Home Assistant is currently onboarding."""
|
||||
with patch(
|
||||
"homeassistant.components.onboarding.async_is_onboarded",
|
||||
return_value=False,
|
||||
) as mock_onboarding:
|
||||
yield mock_onboarding
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_elgato_config_flow() -> Generator[None, MagicMock, None]:
|
||||
"""Return a mocked Elgato client."""
|
||||
|
|
|
@ -204,3 +204,39 @@ async def test_zeroconf_device_exists_abort(
|
|||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert entries[0].data[CONF_HOST] == "127.0.0.2"
|
||||
|
||||
|
||||
async def test_zeroconf_during_onboarding(
|
||||
hass: HomeAssistant,
|
||||
mock_elgato_config_flow: MagicMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_onboarding: MagicMock,
|
||||
) -> None:
|
||||
"""Test the zeroconf creates an entry during onboarding."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
host="127.0.0.1",
|
||||
addresses=["127.0.0.1"],
|
||||
hostname="example.local.",
|
||||
name="mock_name",
|
||||
port=9123,
|
||||
properties={"id": "AA:BB:CC:DD:EE:FF"},
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result.get("title") == "CN11A1A00001"
|
||||
assert result.get("data") == {
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
CONF_PORT: 9123,
|
||||
}
|
||||
assert "result" in result
|
||||
assert result["result"].unique_id == "CN11A1A00001"
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert len(mock_elgato_config_flow.info.mock_calls) == 1
|
||||
assert len(mock_onboarding.mock_calls) == 1
|
||||
|
|
Loading…
Add table
Reference in a new issue