From 131ce094903894a6194bfc69af03a0445e524f7a Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Thu, 25 Jul 2024 16:27:08 +0100 Subject: [PATCH] Allow nightly Mealie versions to pass (#121761) * Allow invalid versions to pass * Add log warning * Change log message * Add assert for log --- homeassistant/components/mealie/__init__.py | 8 ++++++-- .../components/mealie/config_flow.py | 2 +- tests/components/mealie/test_config_flow.py | 1 - tests/components/mealie/test_init.py | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/mealie/__init__.py b/homeassistant/components/mealie/__init__.py index 393ef1e5ecd..df9faf6e540 100644 --- a/homeassistant/components/mealie/__init__.py +++ b/homeassistant/components/mealie/__init__.py @@ -16,7 +16,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.typing import ConfigType -from .const import DOMAIN, MIN_REQUIRED_MEALIE_VERSION +from .const import DOMAIN, LOGGER, MIN_REQUIRED_MEALIE_VERSION from .coordinator import ( MealieConfigEntry, MealieData, @@ -55,7 +55,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: MealieConfigEntry) -> bo except MealieConnectionError as error: raise ConfigEntryNotReady(error) from error - if not version.valid or version < MIN_REQUIRED_MEALIE_VERSION: + if not version.valid: + LOGGER.warning( + "It seems like you are using the nightly version of Mealie, nightly versions could have changes that stop this integration working" + ) + if version.valid and version < MIN_REQUIRED_MEALIE_VERSION: raise ConfigEntryError( translation_domain=DOMAIN, translation_key="version_error", diff --git a/homeassistant/components/mealie/config_flow.py b/homeassistant/components/mealie/config_flow.py index 6b75f57313c..ccbedff04fc 100644 --- a/homeassistant/components/mealie/config_flow.py +++ b/homeassistant/components/mealie/config_flow.py @@ -55,7 +55,7 @@ class MealieConfigFlow(ConfigFlow, domain=DOMAIN): except Exception: # noqa: BLE001 LOGGER.exception("Unexpected error") return {"base": "unknown"}, None - if not version.valid or version < MIN_REQUIRED_MEALIE_VERSION: + if version.valid and version < MIN_REQUIRED_MEALIE_VERSION: return {"base": "mealie_version"}, None return {}, info.user_id diff --git a/tests/components/mealie/test_config_flow.py b/tests/components/mealie/test_config_flow.py index 8edc89c3213..f2886578744 100644 --- a/tests/components/mealie/test_config_flow.py +++ b/tests/components/mealie/test_config_flow.py @@ -91,7 +91,6 @@ async def test_flow_errors( ("v1.0.0beta-5"), ("v1.0.0-RC2"), ("v0.1.0"), - ("something"), ], ) async def test_flow_version_error( diff --git a/tests/components/mealie/test_init.py b/tests/components/mealie/test_init.py index ed5b1290a9b..5c25af5a0a0 100644 --- a/tests/components/mealie/test_init.py +++ b/tests/components/mealie/test_init.py @@ -70,7 +70,6 @@ async def test_setup_failure( ("v1.0.0beta-5"), ("v1.0.0-RC2"), ("v0.1.0"), - ("something"), ], ) async def test_setup_too_old( @@ -87,6 +86,24 @@ async def test_setup_too_old( assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR +async def test_setup_invalid( + hass: HomeAssistant, + mock_mealie_client: AsyncMock, + mock_config_entry: MockConfigEntry, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test setup of Mealie entry with too old version of Mealie.""" + mock_mealie_client.get_about.return_value = About(version="nightly") + + await setup_integration(hass, mock_config_entry) + + assert ( + "It seems like you are using the nightly version of Mealie, nightly versions could have changes that stop this integration working" + in caplog.text + ) + assert mock_config_entry.state is ConfigEntryState.LOADED + + async def test_load_unload_entry( hass: HomeAssistant, mock_mealie_client: AsyncMock,