Use ZeroconfServiceInfo in modern_forms (#60043)
parent
95075448bd
commit
2270e920c3
|
@ -30,14 +30,14 @@ class ModernFormsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle zeroconf discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
host = discovery_info["hostname"].rstrip(".")
|
host = discovery_info[zeroconf.ATTR_HOSTNAME].rstrip(".")
|
||||||
name, _ = host.rsplit(".")
|
name, _ = host.rsplit(".")
|
||||||
|
|
||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
CONF_HOST: discovery_info["host"],
|
CONF_HOST: discovery_info[zeroconf.ATTR_HOST],
|
||||||
CONF_NAME: name,
|
CONF_NAME: name,
|
||||||
CONF_MAC: discovery_info["properties"].get(CONF_MAC),
|
CONF_MAC: discovery_info[zeroconf.ATTR_PROPERTIES].get(CONF_MAC),
|
||||||
"title_placeholders": {"name": name},
|
"title_placeholders": {"name": name},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiomodernforms import ModernFormsConnectionError
|
from aiomodernforms import ModernFormsConnectionError
|
||||||
|
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.modern_forms.const import DOMAIN
|
from homeassistant.components.modern_forms.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONTENT_TYPE_JSON
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONTENT_TYPE_JSON
|
||||||
|
@ -68,7 +69,9 @@ async def test_full_zeroconf_flow_implementation(
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="192.168.1.123", hostname="example.local.", properties={}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
flows = hass.config_entries.flow.async_progress()
|
flows = hass.config_entries.flow.async_progress()
|
||||||
|
@ -130,7 +133,9 @@ async def test_zeroconf_connection_error(
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="192.168.1.123", hostname="example.local.", properties={}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") == RESULT_TYPE_ABORT
|
assert result.get("type") == RESULT_TYPE_ABORT
|
||||||
|
@ -154,7 +159,9 @@ async def test_zeroconf_confirm_connection_error(
|
||||||
CONF_HOST: "example.com",
|
CONF_HOST: "example.com",
|
||||||
CONF_NAME: "test",
|
CONF_NAME: "test",
|
||||||
},
|
},
|
||||||
data={"host": "192.168.1.123", "hostname": "example.com.", "properties": {}},
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
|
host="192.168.1.123", hostname="example.com.", properties={}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") == RESULT_TYPE_ABORT
|
assert result.get("type") == RESULT_TYPE_ABORT
|
||||||
|
@ -216,11 +223,11 @@ async def test_zeroconf_with_mac_device_exists_abort(
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "192.168.1.123",
|
host="192.168.1.123",
|
||||||
"hostname": "example.local.",
|
hostname="example.local.",
|
||||||
"properties": {CONF_MAC: "AA:BB:CC:DD:EE:FF"},
|
properties={CONF_MAC: "AA:BB:CC:DD:EE:FF"},
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result.get("type") == RESULT_TYPE_ABORT
|
assert result.get("type") == RESULT_TYPE_ABORT
|
||||||
|
|
Loading…
Reference in New Issue