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

pull/33814/head
Paulus Schoutsen 2020-04-03 22:41:08 -07:00
parent ab7afbdaf7
commit 6a297b3758
6 changed files with 35 additions and 33 deletions

View File

@ -45,7 +45,7 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN):
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context.update(
{
CONF_HOST: host,
CONF_HOST: user_input["host"],
CONF_NAME: name,
CONF_MAC: user_input["properties"].get(CONF_MAC),
"title_placeholders": {"name": name},

View File

@ -18,31 +18,31 @@ async def init_integration(
fixture = "wled/rgb.json" if not rgbw else "wled/rgbw.json"
aioclient_mock.get(
"http://example.local:80/json/",
"http://192.168.1.123:80/json/",
text=load_fixture(fixture),
headers={"Content-Type": "application/json"},
)
aioclient_mock.post(
"http://example.local:80/json/state",
"http://192.168.1.123:80/json/state",
json={},
headers={"Content-Type": "application/json"},
)
aioclient_mock.get(
"http://example.local:80/json/info",
"http://192.168.1.123:80/json/info",
json={},
headers={"Content-Type": "application/json"},
)
aioclient_mock.get(
"http://example.local:80/json/state",
"http://192.168.1.123:80/json/state",
json={},
headers={"Content-Type": "application/json"},
)
entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "example.local", CONF_MAC: "aabbccddeeff"}
domain=DOMAIN, data={CONF_HOST: "192.168.1.123", CONF_MAC: "aabbccddeeff"}
)
entry.add_to_hass(hass)

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

View File

@ -13,7 +13,7 @@ async def test_config_entry_not_ready(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the WLED configuration entry not ready."""
aioclient_mock.get("http://example.local:80/json/", exc=aiohttp.ClientError)
aioclient_mock.get("http://192.168.1.123:80/json/", exc=aiohttp.ClientError)
entry = await init_integration(hass, aioclient_mock)
assert entry.state == ENTRY_STATE_SETUP_RETRY

View File

@ -141,7 +141,7 @@ async def test_light_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
) -> None:
"""Test error handling of the WLED lights."""
aioclient_mock.post("http://example.local:80/json/state", text="", status=400)
aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"):
@ -162,7 +162,7 @@ async def test_light_connection_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test error handling of the WLED switches."""
aioclient_mock.post("http://example.local:80/json/state", exc=aiohttp.ClientError)
aioclient_mock.post("http://192.168.1.123:80/json/state", exc=aiohttp.ClientError)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"):
@ -339,7 +339,7 @@ async def test_effect_service_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
) -> None:
"""Test error handling of the WLED effect service."""
aioclient_mock.post("http://example.local:80/json/state", text="", status=400)
aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"):

View File

@ -139,7 +139,7 @@ async def test_switch_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
) -> None:
"""Test error handling of the WLED switches."""
aioclient_mock.post("http://example.local:80/json/state", text="", status=400)
aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"):
@ -160,7 +160,7 @@ async def test_switch_connection_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test error handling of the WLED switches."""
aioclient_mock.post("http://example.local:80/json/state", exc=aiohttp.ClientError)
aioclient_mock.post("http://192.168.1.123:80/json/state", exc=aiohttp.ClientError)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLEDDataUpdateCoordinator.async_refresh"):