mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
React on IP changes in devolo Home Network (#86195)
This commit is contained in:
parent
aac89a3493
commit
164fad112c
@ -85,7 +85,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
return self.async_abort(reason="home_control")
|
return self.async_abort(reason="home_control")
|
||||||
|
|
||||||
await self.async_set_unique_id(discovery_info.properties["SN"])
|
await self.async_set_unique_id(discovery_info.properties["SN"])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured(
|
||||||
|
updates={CONF_IP_ADDRESS: discovery_info.host}
|
||||||
|
)
|
||||||
|
|
||||||
self.context[CONF_HOST] = discovery_info.host
|
self.context[CONF_HOST] = discovery_info.host
|
||||||
self.context["title_placeholders"] = {
|
self.context["title_placeholders"] = {
|
||||||
|
@ -12,7 +12,8 @@ from devolo_plc_api.plcnet_api import LogicalNetwork
|
|||||||
|
|
||||||
from homeassistant.components.zeroconf import ZeroconfServiceInfo
|
from homeassistant.components.zeroconf import ZeroconfServiceInfo
|
||||||
|
|
||||||
IP = "1.1.1.1"
|
IP = "192.0.2.1"
|
||||||
|
IP_ALT = "192.0.2.2"
|
||||||
|
|
||||||
CONNECTED_STATIONS = [
|
CONNECTED_STATIONS = [
|
||||||
ConnectedStationInfo(
|
ConnectedStationInfo(
|
||||||
@ -47,6 +48,27 @@ DISCOVERY_INFO = ZeroconfServiceInfo(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DISCOVERY_INFO_CHANGED = ZeroconfServiceInfo(
|
||||||
|
host=IP_ALT,
|
||||||
|
addresses=[IP_ALT],
|
||||||
|
port=14791,
|
||||||
|
hostname="test.local.",
|
||||||
|
type="_dvl-deviceapi._tcp.local.",
|
||||||
|
name="dLAN pro 1200+ WiFi ac._dvl-deviceapi._tcp.local.",
|
||||||
|
properties={
|
||||||
|
"Path": "abcdefghijkl/deviceapi",
|
||||||
|
"Version": "v0",
|
||||||
|
"Product": "dLAN pro 1200+ WiFi ac",
|
||||||
|
"Features": "reset,update,led,intmtg,wifi1",
|
||||||
|
"MT": "2730",
|
||||||
|
"SN": "1234567890",
|
||||||
|
"FirmwareVersion": "5.6.1",
|
||||||
|
"FirmwareDate": "2020-10-23",
|
||||||
|
"PS": "",
|
||||||
|
"PlcMacAddress": "AA:BB:CC:DD:EE:FF",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
DISCOVERY_INFO_WRONG_DEVICE = ZeroconfServiceInfo(
|
DISCOVERY_INFO_WRONG_DEVICE = ZeroconfServiceInfo(
|
||||||
host="mock_host",
|
host="mock_host",
|
||||||
addresses=["mock_host"],
|
addresses=["mock_host"],
|
||||||
|
@ -19,9 +19,17 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from . import configure_integration
|
from . import configure_integration
|
||||||
from .const import DISCOVERY_INFO, DISCOVERY_INFO_WRONG_DEVICE, IP
|
from .const import (
|
||||||
|
DISCOVERY_INFO,
|
||||||
|
DISCOVERY_INFO_CHANGED,
|
||||||
|
DISCOVERY_INFO_WRONG_DEVICE,
|
||||||
|
IP,
|
||||||
|
IP_ALT,
|
||||||
|
)
|
||||||
from .mock import MockDevice
|
from .mock import MockDevice
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass: HomeAssistant, info: dict[str, Any]):
|
async def test_form(hass: HomeAssistant, info: dict[str, Any]):
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
@ -132,20 +140,11 @@ async def test_abort_zeroconf_wrong_device(hass: HomeAssistant):
|
|||||||
@pytest.mark.usefixtures("info")
|
@pytest.mark.usefixtures("info")
|
||||||
async def test_abort_if_configued(hass: HomeAssistant):
|
async def test_abort_if_configued(hass: HomeAssistant):
|
||||||
"""Test we abort config flow if already configured."""
|
"""Test we abort config flow if already configured."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
serial_number = DISCOVERY_INFO.properties["SN"]
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, unique_id=serial_number, data={CONF_IP_ADDRESS: IP}
|
||||||
)
|
)
|
||||||
with patch(
|
entry.add_to_hass(hass)
|
||||||
"homeassistant.components.devolo_home_network.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
):
|
|
||||||
await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"],
|
|
||||||
{
|
|
||||||
CONF_IP_ADDRESS: IP,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Abort on concurrent user flow
|
# Abort on concurrent user flow
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -165,10 +164,11 @@ async def test_abort_if_configued(hass: HomeAssistant):
|
|||||||
result3 = await hass.config_entries.flow.async_init(
|
result3 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
data=DISCOVERY_INFO,
|
data=DISCOVERY_INFO_CHANGED,
|
||||||
)
|
)
|
||||||
assert result3["type"] == FlowResultType.ABORT
|
assert result3["type"] == FlowResultType.ABORT
|
||||||
assert result3["reason"] == "already_configured"
|
assert result3["reason"] == "already_configured"
|
||||||
|
assert entry.data[CONF_IP_ADDRESS] == IP_ALT
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_device")
|
@pytest.mark.usefixtures("mock_device")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user