Use IP addresses instead of mDNS names when wled discovered (#33608)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-03 22:41:08 -07:00
1 parent 07ae3f9ee9
commit c6ba607c8c
6 files changed
+35 -33

No files matched your search

+23 -21
View File
@@ -40,7 +40,7 @@ async def test_show_zerconf_form(
) -> None:
"""Test that the zeroconf confirmation form is served."""
aioclient_mock.get(
"http://example.local:80/json/",
"http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.json"),
headers={"Content-Type": "application/json"},
)
@@ -49,10 +49,10 @@ async def test_show_zerconf_form(
flow.hass = hass
flow.context = {"source": SOURCE_ZEROCONF}
result = await flow.async_step_zeroconf(
{"hostname": "example.local.", "properties": {}}
{"host": "192.168.1.123", "hostname": "example.local.", "properties": {}}
)
assert flow.context[CONF_HOST] == "example.local"
assert flow.context[CONF_HOST] == "192.168.1.123"
assert flow.context[CONF_NAME] == "example"
assert result["description_placeholders"] == {CONF_NAME: "example"}
assert result["step_id"] == "zeroconf_confirm"
@@ -80,12 +80,12 @@ async def test_zeroconf_connection_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test we abort zeroconf flow on WLED connection error."""
aioclient_mock.get("http://example.local/json/", exc=aiohttp.ClientError)
aioclient_mock.get("http://192.168.1.123/json/", exc=aiohttp.ClientError)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "properties": {}},
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
)
assert result["reason"] == "connection_error"
@@ -96,7 +96,7 @@ async def test_zeroconf_confirm_connection_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test we abort zeroconf flow on WLED connection error."""
aioclient_mock.get("http://example.com/json/", exc=aiohttp.ClientError)
aioclient_mock.get("http://192.168.1.123:80/json/", exc=aiohttp.ClientError)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
@@ -105,7 +105,7 @@ async def test_zeroconf_confirm_connection_error(
CONF_HOST: "example.com",
CONF_NAME: "test",
},
data={"hostname": "example.com.", "properties": {}},
data={"host": "192.168.1.123", "hostname": "example.com.", "properties": {}},
)
assert result["reason"] == "connection_error"
@@ -133,7 +133,7 @@ async def test_user_device_exists_abort(
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "example.local"},
data={CONF_HOST: "192.168.1.123"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@@ -149,7 +149,7 @@ async def test_zeroconf_device_exists_abort(
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "properties": {}},
data={"host": "192.168.1.123", "hostname": "example.local.", "properties": {}},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@@ -165,7 +165,11 @@ async def test_zeroconf_with_mac_device_exists_abort(
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_ZEROCONF},
data={"hostname": "example.local.", "properties": {CONF_MAC: "aabbccddeeff"}},
data={
"host": "192.168.1.123",
"hostname": "example.local.",
"properties": {CONF_MAC: "aabbccddeeff"},
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
@@ -177,7 +181,7 @@ async def test_full_user_flow_implementation(
) -> None:
"""Test the full manual user flow from start to finish."""
aioclient_mock.get(
"http://example.local:80/json/",
"http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.json"),
headers={"Content-Type": "application/json"},
)
@@ -190,12 +194,12 @@ async def test_full_user_flow_implementation(
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "example.local"}
result["flow_id"], user_input={CONF_HOST: "192.168.1.123"}
)
assert result["data"][CONF_HOST] == "example.local"
assert result["data"][CONF_HOST] == "192.168.1.123"
assert result["data"][CONF_MAC] == "aabbccddeeff"
assert result["title"] == "example.local"
assert result["title"] == "192.168.1.123"
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@@ -204,7 +208,7 @@ async def test_full_zeroconf_flow_implementation(
) -> None:
"""Test the full manual user flow from start to finish."""
aioclient_mock.get(
"http://example.local:80/json/",
"http://192.168.1.123:80/json/",
text=load_fixture("wled/rgb.json"),
headers={"Content-Type": "application/json"},
)
@@ -213,19 +217,17 @@ async def test_full_zeroconf_flow_implementation(
flow.hass = hass
flow.context = {"source": SOURCE_ZEROCONF}
result = await flow.async_step_zeroconf(
{"hostname": "example.local.", "properties": {}}
{"host": "192.168.1.123", "hostname": "example.local.", "properties": {}}
)
assert flow.context[CONF_HOST] == "example.local"
assert flow.context[CONF_HOST] == "192.168.1.123"
assert flow.context[CONF_NAME] == "example"
assert result["description_placeholders"] == {CONF_NAME: "example"}
assert result["step_id"] == "zeroconf_confirm"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await flow.async_step_zeroconf_confirm(
user_input={CONF_HOST: "example.local"}
)
assert result["data"][CONF_HOST] == "example.local"
result = await flow.async_step_zeroconf_confirm(user_input={})
assert result["data"][CONF_HOST] == "192.168.1.123"
assert result["data"][CONF_MAC] == "aabbccddeeff"
assert result["title"] == "example"
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY