From 3ff3c2cda14c8ec9174ab2944f22b147cada17ea Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 7 Aug 2024 12:45:20 +0200 Subject: [PATCH] Ensure preset segments are lists (#1420) --- src/wled/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wled/models.py b/src/wled/models.py index 52f94e87..912a0090 100644 --- a/src/wled/models.py +++ b/src/wled/models.py @@ -612,6 +612,15 @@ class Preset(BaseModel): ) """Segments are individual parts of the LED strip.""" + @classmethod + def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]: + """Pre deserialize hook for Preset object.""" + # If the segment is a single value, we will convert it to a list. + if "seg" in d and not isinstance(d["seg"], list): + d["seg"] = [d["seg"]] + + return d + @classmethod def __post_deserialize__(cls, obj: Preset) -> Preset: """Post deserialize hook for Preset object."""