diff --git a/homeassistant/components/mealie/__init__.py b/homeassistant/components/mealie/__init__.py index 0e1ea080f4695b3a2e2fec59eb1cf60c7cc0b1d3..87b3e3988a23fd70c76371ab572fd4bebb8a7daf 100644 --- a/homeassistant/components/mealie/__init__.py +++ b/homeassistant/components/mealie/__init__.py @@ -4,7 +4,7 @@ from __future__ import annotations from aiomealie import MealieAuthenticationError, MealieClient, MealieConnectionError -from homeassistant.const import CONF_API_TOKEN, CONF_HOST, Platform +from homeassistant.const import CONF_API_TOKEN, CONF_HOST, CONF_VERIFY_SSL, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ( ConfigEntryAuthFailed, @@ -42,7 +42,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: MealieConfigEntry) -> bo client = MealieClient( entry.data[CONF_HOST], token=entry.data[CONF_API_TOKEN], - session=async_get_clientsession(hass), + session=async_get_clientsession( + hass, verify_ssl=entry.data.get(CONF_VERIFY_SSL, True) + ), ) try: about = await client.get_about() diff --git a/homeassistant/components/mealie/config_flow.py b/homeassistant/components/mealie/config_flow.py index 110599928c51730b40a4a2ccff5921b922048c5f..6b75f57313c65d26d52836f747d7e2b75bef2d8c 100644 --- a/homeassistant/components/mealie/config_flow.py +++ b/homeassistant/components/mealie/config_flow.py @@ -7,7 +7,7 @@ from aiomealie import MealieAuthenticationError, MealieClient, MealieConnectionE import voluptuous as vol from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_TOKEN, CONF_HOST +from homeassistant.const import CONF_API_TOKEN, CONF_HOST, CONF_VERIFY_SSL from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DOMAIN, LOGGER, MIN_REQUIRED_MEALIE_VERSION @@ -17,6 +17,7 @@ USER_SCHEMA = vol.Schema( { vol.Required(CONF_HOST): str, vol.Required(CONF_API_TOKEN): str, + vol.Optional(CONF_VERIFY_SSL, default=True): bool, } ) REAUTH_SCHEMA = vol.Schema( @@ -30,6 +31,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): """Mealie config flow.""" host: str | None = None + verify_ssl: bool = True entry: ConfigEntry | None = None async def check_connection( @@ -40,7 +42,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): client = MealieClient( self.host, token=api_token, - session=async_get_clientsession(self.hass), + session=async_get_clientsession(self.hass, verify_ssl=self.verify_ssl), ) try: info = await client.get_user_info() @@ -64,6 +66,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): errors: dict[str, str] = {} if user_input: self.host = user_input[CONF_HOST] + self.verify_ssl = user_input[CONF_VERIFY_SSL] errors, user_id = await self.check_connection( user_input[CONF_API_TOKEN], ) @@ -85,6 +88,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Perform reauth upon an API authentication error.""" self.host = entry_data[CONF_HOST] + self.verify_ssl = entry_data.get(CONF_VERIFY_SSL, True) self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) return await self.async_step_reauth_confirm() @@ -128,6 +132,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): errors: dict[str, str] = {} if user_input: self.host = user_input[CONF_HOST] + self.verify_ssl = user_input[CONF_VERIFY_SSL] errors, user_id = await self.check_connection( user_input[CONF_API_TOKEN], ) @@ -138,6 +143,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): self.entry, data={ **self.entry.data, + CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL], CONF_HOST: user_input[CONF_HOST], CONF_API_TOKEN: user_input[CONF_API_TOKEN], }, diff --git a/homeassistant/components/mealie/strings.json b/homeassistant/components/mealie/strings.json index 43f6cde80b2666e54ffc89e7d562916bba3044d1..a0b0dcbfc4f98641ea46bfb7e7105e6ada56f58e 100644 --- a/homeassistant/components/mealie/strings.json +++ b/homeassistant/components/mealie/strings.json @@ -4,7 +4,8 @@ "user": { "data": { "host": "[%key:common::config_flow::data::url%]", - "api_token": "[%key:common::config_flow::data::api_token%]" + "api_token": "[%key:common::config_flow::data::api_token%]", + "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" }, "data_description": { "host": "The URL of your Mealie instance." @@ -20,7 +21,8 @@ "description": "Please reconfigure with Mealie.", "data": { "host": "[%key:common::config_flow::data::url%]", - "api_token": "[%key:common::config_flow::data::api_token%]" + "api_token": "[%key:common::config_flow::data::api_token%]", + "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" } } }, diff --git a/tests/components/mealie/test_config_flow.py b/tests/components/mealie/test_config_flow.py index c08a52394d7afd348e6f62dd031970bf58de930e..8edc89c3213a8fa5b49fb9952143f67e5f0e2ad2 100644 --- a/tests/components/mealie/test_config_flow.py +++ b/tests/components/mealie/test_config_flow.py @@ -7,7 +7,7 @@ import pytest from homeassistant.components.mealie.const import DOMAIN from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_RECONFIGURE, SOURCE_USER -from homeassistant.const import CONF_API_TOKEN, CONF_HOST +from homeassistant.const import CONF_API_TOKEN, CONF_HOST, CONF_VERIFY_SSL from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -38,6 +38,7 @@ async def test_full_flow( assert result["data"] == { CONF_HOST: "demo.mealie.io", CONF_API_TOKEN: "token", + CONF_VERIFY_SSL: True, } assert result["result"].unique_id == "bf1c62fe-4941-4332-9886-e54e88dbdba0" @@ -264,13 +265,18 @@ async def test_reconfigure_flow( result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: "http://test:9090", CONF_API_TOKEN: "token2"}, + { + CONF_HOST: "http://test:9090", + CONF_API_TOKEN: "token2", + CONF_VERIFY_SSL: False, + }, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reconfigure_successful" assert mock_config_entry.data[CONF_API_TOKEN] == "token2" assert mock_config_entry.data[CONF_HOST] == "http://test:9090" + assert mock_config_entry.data[CONF_VERIFY_SSL] is False async def test_reconfigure_flow_wrong_account(