mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 21:37:07 +00:00
Catch IPPVersionNotSupportedError in IPP (#34184)
* Update config_flow.py * squash. * Update test_config_flow.py * Update config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Update test_config_flow.py
This commit is contained in:
parent
e0a7ea52fd
commit
e268c5b873
@ -6,8 +6,10 @@ from pyipp import (
|
|||||||
IPP,
|
IPP,
|
||||||
IPPConnectionError,
|
IPPConnectionError,
|
||||||
IPPConnectionUpgradeRequired,
|
IPPConnectionUpgradeRequired,
|
||||||
|
IPPError,
|
||||||
IPPParseError,
|
IPPParseError,
|
||||||
IPPResponseError,
|
IPPResponseError,
|
||||||
|
IPPVersionNotSupportedError,
|
||||||
)
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -70,10 +72,16 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except IPPConnectionUpgradeRequired:
|
except IPPConnectionUpgradeRequired:
|
||||||
return self._show_setup_form({"base": "connection_upgrade"})
|
return self._show_setup_form({"base": "connection_upgrade"})
|
||||||
except (IPPConnectionError, IPPResponseError):
|
except (IPPConnectionError, IPPResponseError):
|
||||||
|
_LOGGER.debug("IPP Connection/Response Error", exc_info=True)
|
||||||
return self._show_setup_form({"base": "connection_error"})
|
return self._show_setup_form({"base": "connection_error"})
|
||||||
except IPPParseError:
|
except IPPParseError:
|
||||||
_LOGGER.exception("IPP Parse Error")
|
_LOGGER.debug("IPP Parse Error", exc_info=True)
|
||||||
return self.async_abort(reason="parse_error")
|
return self.async_abort(reason="parse_error")
|
||||||
|
except IPPVersionNotSupportedError:
|
||||||
|
return self.async_abort(reason="ipp_version_error")
|
||||||
|
except IPPError:
|
||||||
|
_LOGGER.debug("IPP Error", exc_info=True)
|
||||||
|
return self.async_abort(reason="ipp_error")
|
||||||
|
|
||||||
user_input[CONF_UUID] = info[CONF_UUID]
|
user_input[CONF_UUID] = info[CONF_UUID]
|
||||||
|
|
||||||
@ -111,10 +119,16 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except IPPConnectionUpgradeRequired:
|
except IPPConnectionUpgradeRequired:
|
||||||
return self.async_abort(reason="connection_upgrade")
|
return self.async_abort(reason="connection_upgrade")
|
||||||
except (IPPConnectionError, IPPResponseError):
|
except (IPPConnectionError, IPPResponseError):
|
||||||
|
_LOGGER.debug("IPP Connection/Response Error", exc_info=True)
|
||||||
return self.async_abort(reason="connection_error")
|
return self.async_abort(reason="connection_error")
|
||||||
except IPPParseError:
|
except IPPParseError:
|
||||||
_LOGGER.exception("IPP Parse Error")
|
_LOGGER.debug("IPP Parse Error", exc_info=True)
|
||||||
return self.async_abort(reason="parse_error")
|
return self.async_abort(reason="parse_error")
|
||||||
|
except IPPVersionNotSupportedError:
|
||||||
|
return self.async_abort(reason="ipp_version_error")
|
||||||
|
except IPPError:
|
||||||
|
_LOGGER.debug("IPP Error", exc_info=True)
|
||||||
|
return self.async_abort(reason="ipp_error")
|
||||||
|
|
||||||
if info[CONF_UUID] is not None:
|
if info[CONF_UUID] is not None:
|
||||||
self.discovery_info[CONF_UUID] = info[CONF_UUID]
|
self.discovery_info[CONF_UUID] = info[CONF_UUID]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "ipp",
|
"domain": "ipp",
|
||||||
"name": "Internet Printing Protocol (IPP)",
|
"name": "Internet Printing Protocol (IPP)",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/ipp",
|
"documentation": "https://www.home-assistant.io/integrations/ipp",
|
||||||
"requirements": ["pyipp==0.9.2"],
|
"requirements": ["pyipp==0.10.1"],
|
||||||
"codeowners": ["@ctalkington"],
|
"codeowners": ["@ctalkington"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
"already_configured": "This printer is already configured.",
|
"already_configured": "This printer is already configured.",
|
||||||
"connection_error": "Failed to connect to printer.",
|
"connection_error": "Failed to connect to printer.",
|
||||||
"connection_upgrade": "Failed to connect to printer due to connection upgrade being required.",
|
"connection_upgrade": "Failed to connect to printer due to connection upgrade being required.",
|
||||||
|
"ipp_error": "Encountered IPP error.",
|
||||||
|
"ipp_version_error": "IPP version not supported by printer.",
|
||||||
"parse_error": "Failed to parse response from printer."
|
"parse_error": "Failed to parse response from printer."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1341,7 +1341,7 @@ pyintesishome==1.7.3
|
|||||||
pyipma==2.0.5
|
pyipma==2.0.5
|
||||||
|
|
||||||
# homeassistant.components.ipp
|
# homeassistant.components.ipp
|
||||||
pyipp==0.9.2
|
pyipp==0.10.1
|
||||||
|
|
||||||
# homeassistant.components.iqvia
|
# homeassistant.components.iqvia
|
||||||
pyiqvia==0.2.1
|
pyiqvia==0.2.1
|
||||||
|
@ -527,7 +527,7 @@ pyicloud==0.9.6.1
|
|||||||
pyipma==2.0.5
|
pyipma==2.0.5
|
||||||
|
|
||||||
# homeassistant.components.ipp
|
# homeassistant.components.ipp
|
||||||
pyipp==0.9.2
|
pyipp==0.10.1
|
||||||
|
|
||||||
# homeassistant.components.iqvia
|
# homeassistant.components.iqvia
|
||||||
pyiqvia==0.2.1
|
pyiqvia==0.2.1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Tests for the IPP config flow."""
|
"""Tests for the IPP config flow."""
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from pyipp import IPPConnectionUpgradeRequired
|
from pyipp import IPPConnectionUpgradeRequired, IPPError
|
||||||
|
|
||||||
from homeassistant.components.ipp.const import CONF_BASE_PATH, CONF_UUID, DOMAIN
|
from homeassistant.components.ipp.const import CONF_BASE_PATH, CONF_UUID, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
|
||||||
@ -172,6 +172,74 @@ async def test_zeroconf_parse_error(
|
|||||||
assert result["reason"] == "parse_error"
|
assert result["reason"] == "parse_error"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_ipp_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test we abort the user flow on IPP error."""
|
||||||
|
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=IPPError)
|
||||||
|
|
||||||
|
user_input = MOCK_USER_INPUT.copy()
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_USER}, data=user_input,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "ipp_error"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_ipp_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test we abort zeroconf flow on IPP error."""
|
||||||
|
aioclient_mock.post("http://192.168.1.31:631/ipp/print", exc=IPPError)
|
||||||
|
|
||||||
|
discovery_info = MOCK_ZEROCONF_IPP_SERVICE_INFO.copy()
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "ipp_error"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_ipp_version_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test we abort user flow on IPP version not supported error."""
|
||||||
|
aioclient_mock.post(
|
||||||
|
"http://192.168.1.31:631/ipp/print",
|
||||||
|
content=load_fixture_binary("ipp/get-printer-attributes-error-0x0503.bin"),
|
||||||
|
headers={"Content-Type": "application/ipp"},
|
||||||
|
)
|
||||||
|
|
||||||
|
user_input = {**MOCK_USER_INPUT}
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_USER}, data=user_input,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "ipp_version_error"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_ipp_version_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
|
"""Test we abort zeroconf flow on IPP version not supported error."""
|
||||||
|
aioclient_mock.post(
|
||||||
|
"http://192.168.1.31:631/ipp/print",
|
||||||
|
content=load_fixture_binary("ipp/get-printer-attributes-error-0x0503.bin"),
|
||||||
|
headers={"Content-Type": "application/ipp"},
|
||||||
|
)
|
||||||
|
|
||||||
|
discovery_info = {**MOCK_ZEROCONF_IPP_SERVICE_INFO}
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == RESULT_TYPE_ABORT
|
||||||
|
assert result["reason"] == "ipp_version_error"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_device_exists_abort(
|
async def test_user_device_exists_abort(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
|
BIN
tests/fixtures/ipp/get-printer-attributes-error-0x0503.bin
vendored
Normal file
BIN
tests/fixtures/ipp/get-printer-attributes-error-0x0503.bin
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user