From c335b5b37cfc080fad578c779824d5b51c015996 Mon Sep 17 00:00:00 2001 From: Florian von Garrel Date: Mon, 16 Jun 2025 14:31:22 +0200 Subject: [PATCH] Add verify ssl option to paperless-ngx integration (#146802) * add verify ssl config option * Refactoring * Use .get() with default value instead of migration * Reconfigure fix * minor changes --- .../components/paperless_ngx/__init__.py | 4 ++-- .../components/paperless_ngx/config_flow.py | 23 ++++++++++++------- .../components/paperless_ngx/strings.json | 12 ++++++---- tests/components/paperless_ngx/const.py | 4 +++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/paperless_ngx/__init__.py b/homeassistant/components/paperless_ngx/__init__.py index 4d60f47e1e8..0fea90b7ea3 100644 --- a/homeassistant/components/paperless_ngx/__init__.py +++ b/homeassistant/components/paperless_ngx/__init__.py @@ -9,7 +9,7 @@ from pypaperless.exceptions import ( PaperlessInvalidTokenError, ) -from homeassistant.const import CONF_API_KEY, CONF_URL, Platform +from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ( ConfigEntryAuthFailed, @@ -69,7 +69,7 @@ async def _get_paperless_api( api = Paperless( entry.data[CONF_URL], entry.data[CONF_API_KEY], - session=async_get_clientsession(hass), + session=async_get_clientsession(hass, entry.data.get(CONF_VERIFY_SSL, True)), ) try: diff --git a/homeassistant/components/paperless_ngx/config_flow.py b/homeassistant/components/paperless_ngx/config_flow.py index c0c1dc4ce19..9a8ea05d168 100644 --- a/homeassistant/components/paperless_ngx/config_flow.py +++ b/homeassistant/components/paperless_ngx/config_flow.py @@ -16,7 +16,7 @@ from pypaperless.exceptions import ( import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_URL +from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN, LOGGER @@ -25,6 +25,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema( { vol.Required(CONF_URL): str, vol.Required(CONF_API_KEY): str, + vol.Required(CONF_VERIFY_SSL, default=True): bool, } ) @@ -78,15 +79,19 @@ class PaperlessConfigFlow(ConfigFlow, domain=DOMAIN): if not errors: return self.async_update_reload_and_abort(entry, data=user_input) + if user_input is not None: + suggested_values = user_input + else: + suggested_values = { + CONF_URL: entry.data[CONF_URL], + CONF_VERIFY_SSL: entry.data.get(CONF_VERIFY_SSL, True), + } + return self.async_show_form( step_id="reconfigure", data_schema=self.add_suggested_values_to_schema( data_schema=STEP_USER_DATA_SCHEMA, - suggested_values={ - CONF_URL: user_input[CONF_URL] - if user_input is not None - else entry.data[CONF_URL], - }, + suggested_values=suggested_values, ), errors=errors, ) @@ -122,13 +127,15 @@ class PaperlessConfigFlow(ConfigFlow, domain=DOMAIN): errors=errors, ) - async def _validate_input(self, user_input: dict[str, str]) -> dict[str, str]: + async def _validate_input(self, user_input: dict[str, Any]) -> dict[str, str]: errors: dict[str, str] = {} client = Paperless( user_input[CONF_URL], user_input[CONF_API_KEY], - session=async_get_clientsession(self.hass), + session=async_get_clientsession( + self.hass, user_input.get(CONF_VERIFY_SSL, True) + ), ) try: diff --git a/homeassistant/components/paperless_ngx/strings.json b/homeassistant/components/paperless_ngx/strings.json index 1347dc83e98..aa3f7ada943 100644 --- a/homeassistant/components/paperless_ngx/strings.json +++ b/homeassistant/components/paperless_ngx/strings.json @@ -4,11 +4,13 @@ "user": { "data": { "url": "[%key:common::config_flow::data::url%]", - "api_key": "[%key:common::config_flow::data::api_key%]" + "api_key": "[%key:common::config_flow::data::api_key%]", + "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" }, "data_description": { "url": "URL to connect to the Paperless-ngx instance", - "api_key": "API key to connect to the Paperless-ngx API" + "api_key": "API key to connect to the Paperless-ngx API", + "verify_ssl": "Verify the SSL certificate of the Paperless-ngx instance. Disable this option if you’re using a self-signed certificate." }, "title": "Add Paperless-ngx instance" }, @@ -24,11 +26,13 @@ "reconfigure": { "data": { "url": "[%key:common::config_flow::data::url%]", - "api_key": "[%key:common::config_flow::data::api_key%]" + "api_key": "[%key:common::config_flow::data::api_key%]", + "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" }, "data_description": { "url": "[%key:component::paperless_ngx::config::step::user::data_description::url%]", - "api_key": "[%key:component::paperless_ngx::config::step::user::data_description::api_key%]" + "api_key": "[%key:component::paperless_ngx::config::step::user::data_description::api_key%]", + "verify_ssl": "[%key:component::paperless_ngx::config::step::user::data_description::verify_ssl%]" }, "title": "Reconfigure Paperless-ngx instance" } diff --git a/tests/components/paperless_ngx/const.py b/tests/components/paperless_ngx/const.py index addfd54a001..36f62b507dd 100644 --- a/tests/components/paperless_ngx/const.py +++ b/tests/components/paperless_ngx/const.py @@ -1,15 +1,17 @@ """Constants for the Paperless NGX integration tests.""" -from homeassistant.const import CONF_API_KEY, CONF_URL +from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL USER_INPUT_ONE = { CONF_URL: "https://192.168.69.16:8000", CONF_API_KEY: "12345678", + CONF_VERIFY_SSL: True, } USER_INPUT_TWO = { CONF_URL: "https://paperless.example.de", CONF_API_KEY: "87654321", + CONF_VERIFY_SSL: True, } USER_INPUT_REAUTH = {CONF_API_KEY: "192837465"}