mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Use IP addresses instead of mDNS names when IPP discovered (#33610)
* use discovery resolved host rather than mdns host. * Update __init__.py * Update test_config_flow.py * Update __init__.py * Update test_init.py * Update test_config_flow.py * Update test_config_flow.py * Update __init__.py * Update __init__.py * Update __init__.py * Update test_init.py * Update test_config_flow.py
This commit is contained in:
parent
42353282d4
commit
07ae3f9ee9
@ -85,7 +85,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
self.discovery_info.update(
|
||||
{
|
||||
CONF_HOST: host,
|
||||
CONF_HOST: discovery_info[CONF_HOST],
|
||||
CONF_PORT: port,
|
||||
CONF_SSL: tls,
|
||||
CONF_VERIFY_SSL: False,
|
||||
|
@ -22,13 +22,13 @@ IPP_ZEROCONF_SERVICE_TYPE = "_ipp._tcp.local."
|
||||
IPPS_ZEROCONF_SERVICE_TYPE = "_ipps._tcp.local."
|
||||
|
||||
ZEROCONF_NAME = "EPSON123456"
|
||||
ZEROCONF_HOST = "1.2.3.4"
|
||||
ZEROCONF_HOST = "192.168.1.31"
|
||||
ZEROCONF_HOSTNAME = "EPSON123456.local."
|
||||
ZEROCONF_PORT = 631
|
||||
|
||||
|
||||
MOCK_USER_INPUT = {
|
||||
CONF_HOST: "EPSON123456.local",
|
||||
CONF_HOST: "192.168.1.31",
|
||||
CONF_PORT: 361,
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: False,
|
||||
@ -37,7 +37,7 @@ MOCK_USER_INPUT = {
|
||||
|
||||
MOCK_ZEROCONF_IPP_SERVICE_INFO = {
|
||||
CONF_TYPE: IPP_ZEROCONF_SERVICE_TYPE,
|
||||
CONF_NAME: ZEROCONF_NAME,
|
||||
CONF_NAME: f"{ZEROCONF_NAME}.{IPP_ZEROCONF_SERVICE_TYPE}",
|
||||
CONF_HOST: ZEROCONF_HOST,
|
||||
ATTR_HOSTNAME: ZEROCONF_HOSTNAME,
|
||||
CONF_PORT: ZEROCONF_PORT,
|
||||
@ -46,7 +46,7 @@ MOCK_ZEROCONF_IPP_SERVICE_INFO = {
|
||||
|
||||
MOCK_ZEROCONF_IPPS_SERVICE_INFO = {
|
||||
CONF_TYPE: IPPS_ZEROCONF_SERVICE_TYPE,
|
||||
CONF_NAME: ZEROCONF_NAME,
|
||||
CONF_NAME: f"{ZEROCONF_NAME}.{IPPS_ZEROCONF_SERVICE_TYPE}",
|
||||
CONF_HOST: ZEROCONF_HOST,
|
||||
ATTR_HOSTNAME: ZEROCONF_HOSTNAME,
|
||||
CONF_PORT: ZEROCONF_PORT,
|
||||
@ -65,10 +65,9 @@ async def init_integration(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the IPP integration in Home Assistant."""
|
||||
|
||||
fixture = "ipp/get-printer-attributes.bin"
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print",
|
||||
"http://192.168.1.31:631/ipp/print",
|
||||
content=load_fixture_binary(fixture),
|
||||
headers={"Content-Type": "application/ipp"},
|
||||
)
|
||||
@ -77,7 +76,7 @@ async def init_integration(
|
||||
domain=DOMAIN,
|
||||
unique_id="cfe92100-67c4-11d4-a45f-f8d027761251",
|
||||
data={
|
||||
CONF_HOST: "EPSON123456.local",
|
||||
CONF_HOST: "192.168.1.31",
|
||||
CONF_PORT: 631,
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
|
@ -38,7 +38,7 @@ async def test_show_zeroconf_form(
|
||||
) -> None:
|
||||
"""Test that the zeroconf confirmation form is served."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print",
|
||||
"http://192.168.1.31:631/ipp/print",
|
||||
content=load_fixture_binary("ipp/get-printer-attributes.bin"),
|
||||
headers={"Content-Type": "application/ipp"},
|
||||
)
|
||||
@ -57,9 +57,7 @@ async def test_connection_error(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we show user form on IPP connection error."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print", exc=aiohttp.ClientError
|
||||
)
|
||||
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=aiohttp.ClientError)
|
||||
|
||||
user_input = MOCK_USER_INPUT.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@ -75,7 +73,7 @@ async def test_zeroconf_connection_error(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we abort zeroconf flow on IPP connection error."""
|
||||
aioclient_mock.post("http://EPSON123456.local/ipp/print", exc=aiohttp.ClientError)
|
||||
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=aiohttp.ClientError)
|
||||
|
||||
discovery_info = MOCK_ZEROCONF_IPP_SERVICE_INFO.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@ -90,17 +88,11 @@ async def test_zeroconf_confirm_connection_error(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we abort zeroconf flow on IPP connection error."""
|
||||
aioclient_mock.post("http://EPSON123456.local/ipp/print", exc=aiohttp.ClientError)
|
||||
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=aiohttp.ClientError)
|
||||
|
||||
discovery_info = MOCK_ZEROCONF_IPP_SERVICE_INFO.copy()
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={
|
||||
"source": SOURCE_ZEROCONF,
|
||||
CONF_HOST: "EPSON123456.local",
|
||||
CONF_NAME: "EPSON123456",
|
||||
},
|
||||
data=discovery_info,
|
||||
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
@ -112,7 +104,7 @@ async def test_user_connection_upgrade_required(
|
||||
) -> None:
|
||||
"""Test we show the user form if connection upgrade required by server."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print", exc=IPPConnectionUpgradeRequired
|
||||
"http://192.168.1.31:631/ipp/print", exc=IPPConnectionUpgradeRequired
|
||||
)
|
||||
|
||||
user_input = MOCK_USER_INPUT.copy()
|
||||
@ -130,7 +122,7 @@ async def test_zeroconf_connection_upgrade_required(
|
||||
) -> None:
|
||||
"""Test we abort zeroconf flow on IPP connection error."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local/ipp/print", exc=IPPConnectionUpgradeRequired
|
||||
"http://192.168.1.31:631/ipp/print", exc=IPPConnectionUpgradeRequired
|
||||
)
|
||||
|
||||
discovery_info = MOCK_ZEROCONF_IPP_SERVICE_INFO.copy()
|
||||
@ -193,7 +185,7 @@ async def test_full_user_flow_implementation(
|
||||
) -> None:
|
||||
"""Test the full manual user flow from start to finish."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print",
|
||||
"http://192.168.1.31:631/ipp/print",
|
||||
content=load_fixture_binary("ipp/get-printer-attributes.bin"),
|
||||
headers={"Content-Type": "application/ipp"},
|
||||
)
|
||||
@ -207,14 +199,14 @@ async def test_full_user_flow_implementation(
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: "EPSON123456.local", CONF_BASE_PATH: "/ipp/print"},
|
||||
user_input={CONF_HOST: "192.168.1.31", CONF_BASE_PATH: "/ipp/print"},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "EPSON123456.local"
|
||||
assert result["title"] == "192.168.1.31"
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == "EPSON123456.local"
|
||||
assert result["data"][CONF_HOST] == "192.168.1.31"
|
||||
assert result["data"][CONF_UUID] == "cfe92100-67c4-11d4-a45f-f8d027761251"
|
||||
|
||||
|
||||
@ -223,7 +215,7 @@ async def test_full_zeroconf_flow_implementation(
|
||||
) -> None:
|
||||
"""Test the full manual user flow from start to finish."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print",
|
||||
"http://192.168.1.31:631/ipp/print",
|
||||
content=load_fixture_binary("ipp/get-printer-attributes.bin"),
|
||||
headers={"Content-Type": "application/ipp"},
|
||||
)
|
||||
@ -244,7 +236,7 @@ async def test_full_zeroconf_flow_implementation(
|
||||
assert result["title"] == "EPSON123456"
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == "EPSON123456.local"
|
||||
assert result["data"][CONF_HOST] == "192.168.1.31"
|
||||
assert result["data"][CONF_UUID] == "cfe92100-67c4-11d4-a45f-f8d027761251"
|
||||
assert not result["data"][CONF_SSL]
|
||||
|
||||
@ -254,7 +246,7 @@ async def test_full_zeroconf_tls_flow_implementation(
|
||||
) -> None:
|
||||
"""Test the full manual user flow from start to finish."""
|
||||
aioclient_mock.post(
|
||||
"https://EPSON123456.local:631/ipp/print",
|
||||
"https://192.168.1.31:631/ipp/print",
|
||||
content=load_fixture_binary("ipp/get-printer-attributes.bin"),
|
||||
headers={"Content-Type": "application/ipp"},
|
||||
)
|
||||
@ -276,7 +268,7 @@ async def test_full_zeroconf_tls_flow_implementation(
|
||||
assert result["title"] == "EPSON123456"
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == "EPSON123456.local"
|
||||
assert result["data"][CONF_HOST] == "192.168.1.31"
|
||||
assert result["data"][CONF_NAME] == "EPSON123456"
|
||||
assert result["data"][CONF_UUID] == "cfe92100-67c4-11d4-a45f-f8d027761251"
|
||||
assert result["data"][CONF_SSL]
|
||||
|
@ -17,9 +17,7 @@ async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test the IPP configuration entry not ready."""
|
||||
aioclient_mock.post(
|
||||
"http://EPSON123456.local:631/ipp/print", exc=aiohttp.ClientError
|
||||
)
|
||||
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=aiohttp.ClientError)
|
||||
|
||||
entry = await init_integration(hass, aioclient_mock)
|
||||
assert entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
|
Loading…
x
Reference in New Issue
Block a user