mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-10 00:39:22 -06:00
Fix addon options reset to defaults (#6397)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6f12d2cb6f
commit
5d02b09a0d
@ -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(
|
||||
|
||||
@ -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
|
||||
):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user