mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 14:29:21 -04:00
Update SMA host from DHCP discovery (#183335)
This commit is contained in:
@@ -298,7 +298,7 @@ class SmaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if not (match := HOSTNAME_SERIAL.match(discovery_info.hostname)):
|
||||
return self.async_abort(reason="not_supported")
|
||||
await self.async_set_unique_id(match.group(1))
|
||||
self._abort_if_unique_id_configured()
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: self._data[CONF_HOST]})
|
||||
|
||||
return await self.async_step_discovery_confirm()
|
||||
|
||||
|
||||
@@ -195,6 +195,26 @@ async def test_dhcp_already_configured(
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_dhcp_updates_host(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test DHCP discovery updates the host of a device that changed IP address."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=DhcpServiceInfo(
|
||||
ip="1.1.1.2", hostname="SMA123456789", macaddress="0015bb00abcd"
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_config_entry.data[CONF_HOST] == "1.1.1.2"
|
||||
|
||||
|
||||
async def test_dhcp_already_configured_duplicate(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
|
||||
Reference in New Issue
Block a user