mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Automatically onboard Elgato (#73847)
This commit is contained in:
parent
ad7da9803f
commit
320ef55085
@ -6,7 +6,7 @@ from typing import Any
|
|||||||
from elgato import Elgato, ElgatoError
|
from elgato import Elgato, ElgatoError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import onboarding, zeroconf
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -56,6 +56,9 @@ class ElgatoFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except ElgatoError:
|
except ElgatoError:
|
||||||
return self.async_abort(reason="cannot_connect")
|
return self.async_abort(reason="cannot_connect")
|
||||||
|
|
||||||
|
if not onboarding.async_is_onboarded(self.hass):
|
||||||
|
return self._async_create_entry()
|
||||||
|
|
||||||
self._set_confirm_only()
|
self._set_confirm_only()
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="zeroconf_confirm",
|
step_id="zeroconf_confirm",
|
||||||
|
@ -37,6 +37,16 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|||||||
yield mock_setup
|
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
|
@pytest.fixture
|
||||||
def mock_elgato_config_flow() -> Generator[None, MagicMock, None]:
|
def mock_elgato_config_flow() -> Generator[None, MagicMock, None]:
|
||||||
"""Return a mocked Elgato client."""
|
"""Return a mocked Elgato client."""
|
||||||
|
@ -204,3 +204,39 @@ async def test_zeroconf_device_exists_abort(
|
|||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert entries[0].data[CONF_HOST] == "127.0.0.2"
|
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…
x
Reference in New Issue
Block a user