mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Reinitialize zeroconf discovery flow on unignore (#125753)
* Reinitialize zeroconf discovery flow on unignore * Adjust tests * Improve comments * Fix logic for updating discovery keys * Add tests * Use mock_config_flow helper in new config_entries test * Add discovery_keys attribute to ConfigEntry * Update zeroconf rediscovery * Change type of ConfigEntry.discovery_keys * Update tests * Fix DiscoveryKey.from_json_dict and add tests * Fix test --------- Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -8,7 +8,8 @@ import pytest
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
|
||||
from homeassistant.core import CoreState, HomeAssistant
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers import discovery_flow, json as json_helper
|
||||
from homeassistant.helpers.discovery_flow import DiscoveryKey
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -20,8 +21,29 @@ def mock_flow_init(hass: HomeAssistant) -> Generator[AsyncMock]:
|
||||
yield mock_init
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("discovery_key", "context"),
|
||||
[
|
||||
(None, {}),
|
||||
(
|
||||
DiscoveryKey(domain="test", key="string_key", version=1),
|
||||
{"discovery_key": DiscoveryKey(domain="test", key="string_key", version=1)},
|
||||
),
|
||||
(
|
||||
DiscoveryKey(domain="test", key=("one", "two"), version=1),
|
||||
{
|
||||
"discovery_key": DiscoveryKey(
|
||||
domain="test", key=("one", "two"), version=1
|
||||
)
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_async_create_flow(
|
||||
hass: HomeAssistant, mock_flow_init: AsyncMock
|
||||
hass: HomeAssistant,
|
||||
mock_flow_init: AsyncMock,
|
||||
discovery_key: DiscoveryKey | None,
|
||||
context: {},
|
||||
) -> None:
|
||||
"""Test we can create a flow."""
|
||||
discovery_flow.async_create_flow(
|
||||
@@ -29,11 +51,12 @@ async def test_async_create_flow(
|
||||
"hue",
|
||||
{"source": config_entries.SOURCE_HOMEKIT},
|
||||
{"properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
discovery_key=discovery_key,
|
||||
)
|
||||
assert mock_flow_init.mock_calls == [
|
||||
call(
|
||||
"hue",
|
||||
context={"source": "homekit"},
|
||||
context={"source": "homekit"} | context,
|
||||
data={"properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
]
|
||||
@@ -118,3 +141,16 @@ async def test_async_create_flow_does_nothing_after_stop(
|
||||
{"properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
assert len(mock_flow_init.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", ["test", ("blah", "bleh")])
|
||||
def test_discovery_key_serialize_deserialize(key: str | tuple[str]) -> None:
|
||||
"""Test serialize and deserialize discovery key."""
|
||||
discovery_key_1 = discovery_flow.DiscoveryKey(
|
||||
domain="test_domain", key=key, version=1
|
||||
)
|
||||
serialized = json_helper.json_dumps(discovery_key_1)
|
||||
assert (
|
||||
discovery_flow.DiscoveryKey.from_json_dict(json_helper.json_loads(serialized))
|
||||
== discovery_key_1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user