From 5d02b09a0d050f236a7ccae680889450cde0fea9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 5 Dec 2025 13:53:51 +0100 Subject: [PATCH] Fix addon options reset to defaults (#6397) Co-authored-by: Claude --- supervisor/api/addons.py | 18 +++++++++++------- tests/api/test_addons.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index ae49afcfa..9114c0f30 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -307,13 +307,17 @@ class APIAddons(CoreSysAttributes): # Validate/Process Body body = await api_validate(SCHEMA_OPTIONS, request) if ATTR_OPTIONS in body: - try: - addon.options = addon.schema(body[ATTR_OPTIONS]) - except vol.Invalid as ex: - raise AddonConfigurationInvalidError( - addon=addon.slug, - validation_error=humanize_error(body[ATTR_OPTIONS], ex), - ) from None + # None resets options to defaults, otherwise validate the options + if body[ATTR_OPTIONS] is None: + addon.options = None + else: + try: + addon.options = addon.schema(body[ATTR_OPTIONS]) + except vol.Invalid as ex: + raise AddonConfigurationInvalidError( + addon=addon.slug, + validation_error=humanize_error(body[ATTR_OPTIONS], ex), + ) from None if ATTR_BOOT in body: if addon.boot_config == AddonBootConfig.MANUAL_ONLY: raise AddonBootConfigCannotChangeError( diff --git a/tests/api/test_addons.py b/tests/api/test_addons.py index 87b5dd5af..d94f0c97d 100644 --- a/tests/api/test_addons.py +++ b/tests/api/test_addons.py @@ -562,6 +562,27 @@ async def test_addon_set_options(api_client: TestClient, install_addon_example: assert install_addon_example.options == {"message": "test"} +async def test_addon_reset_options( + api_client: TestClient, install_addon_example: Addon +): + """Test resetting options for an addon to defaults. + + Fixes SUPERVISOR-171F. + """ + # First set some custom options + install_addon_example.options = {"message": "custom"} + assert install_addon_example.persist["options"] == {"message": "custom"} + + # Reset to defaults by sending null + resp = await api_client.post( + "/addons/local_example/options", json={"options": None} + ) + assert resp.status == 200 + + # Persisted options should be empty (meaning defaults will be used) + assert install_addon_example.persist["options"] == {} + + async def test_addon_set_options_error( api_client: TestClient, install_addon_example: Addon ):