Persist iZone controller host on config entries (#176733)

This commit is contained in:
Penny Wood
2026-07-18 06:26:47 +08:00
committed by GitHub
parent b295cb3888
commit 373c0ed46c
3 changed files with 18 additions and 15 deletions
+2 -1
View File
@@ -4,7 +4,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EXCLUDE, Platform
from homeassistant.const import CONF_EXCLUDE, CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
@@ -108,6 +108,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry,
unique_id=controller.device_uid,
title=new_title,
data={CONF_HOST: controller.device_ip},
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@@ -242,8 +242,7 @@ class IZoneConfigFlow(ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(uid)
self._abort_if_unique_id_configured()
# Discovery host is for confirm-step context only; runtime discovery owns
# current device IP state and keeps it up to date independently of entry data.
# Persist through confirm into entry data as CONF_HOST.
self._discovered_controller_ip = host
return await self.async_step_confirm()
@@ -357,7 +356,7 @@ class IZoneConfigFlow(ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=self._entry_title(controller.device_uid),
data={},
data={CONF_HOST: controller.device_ip},
)
@callback
+14 -11
View File
@@ -61,7 +61,7 @@ async def test_user_discovery_success(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000001"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.55"}
assert result["result"].unique_id == "000000001"
@@ -82,7 +82,7 @@ async def test_user_discovery_default_selects_first_and_queues_other(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000001"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.1"}
assert result["result"].unique_id == "000000001"
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
@@ -120,7 +120,7 @@ async def test_broadcast_skips_already_configured_controller(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000002"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.2"}
assert result["result"].unique_id == "000000002"
@@ -143,7 +143,7 @@ async def test_user_discovery_skips_yaml_excluded_controllers(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000002"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.2"}
assert result["result"].unique_id == "000000002"
@@ -172,7 +172,7 @@ async def test_broadcast_multiple_unconfigured_shows_choice(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000001"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.2"}
assert result["result"].unique_id == "000000001"
entries = hass.config_entries.async_entries(DOMAIN)
@@ -251,6 +251,7 @@ async def test_select_controller_creates_selected_uid_and_queues_others(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000002"
assert result["data"] == {CONF_HOST: "192.0.2.1"}
assert result["result"].unique_id == "000000002"
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
@@ -331,7 +332,7 @@ async def test_reuses_existing_discovery_service(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000002"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.2"}
assert result["result"].unique_id == "000000002"
mock_pizone_discovery.assert_not_called()
@@ -427,7 +428,7 @@ async def test_homekit_confirm_uses_discovered_host(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000001"
assert result["data"] == {}
assert result["data"] == {CONF_HOST: "192.0.2.3"}
assert result["result"].unique_id == "000000001"
@@ -882,6 +883,7 @@ async def test_integration_discovery_confirm_creates_entry(
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "iZone 000000002"
assert result["data"] == {CONF_HOST: "192.0.2.2"}
assert result["result"].unique_id == "000000002"
@@ -1230,12 +1232,12 @@ def test_async_fan_out_skips_uids_already_in_progress() -> None:
async def test_async_migrate_entry_clears_legacy_data(
hass: HomeAssistant,
) -> None:
"""v1→v2 migration clears legacy entry data; UID and title binding is deferred.
"""v1→v2 migration clears legacy entry data; UID/host binding is deferred to setup.
ConfigEntryNotReady retry semantics only work inside async_setup_entry — raising
from async_migrate_entry permanently lands the entry in MIGRATION_ERROR with no
retry path. All network-dependent work is therefore intentionally deferred to
async_setup_entry.
async_setup_entry, which also persists CONF_HOST when the UID is resolved.
"""
entry = MockConfigEntry(
domain=DOMAIN,
@@ -1258,7 +1260,7 @@ async def test_async_migrate_entry_clears_legacy_data(
await hass.async_block_till_done()
assert entry.version == 2
assert entry.data == {}
assert entry.data == {CONF_HOST: "192.0.2.1"}
assert entry.unique_id == "000000001"
assert entry.title == "iZone 000000001"
@@ -1377,6 +1379,7 @@ async def test_setup_entry_resolves_legacy_uid_and_updates_title(
assert entry.unique_id == "000000001"
assert entry.title == expected_title
assert entry.data == {CONF_HOST: "192.0.2.2"}
@pytest.mark.parametrize(
@@ -1502,7 +1505,7 @@ async def test_setup_entry_picks_eligible_controller_after_filtering_for_legacy_
await hass.async_block_till_done()
assert entry.unique_id == "000000002"
assert entry.data == {}
assert entry.data == {CONF_HOST: "192.0.2.2"}
@pytest.mark.parametrize(