Skip to content

Commit f850142

Browse files
committed
Chore: add fallback for all enums
1 parent 8408a93 commit f850142

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

music_assistant_models/enums.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ class RepeatMode(StrEnum):
309309
ONE = "one" # repeat one/single track
310310
ALL = "all" # repeat entire queue
311311

312+
# fallback
313+
UNKNOWN = "unknown"
314+
312315

313316
class PlayerState(StrEnum):
314317
"""Enum for the (playback)state of a player."""
@@ -317,6 +320,14 @@ class PlayerState(StrEnum):
317320
PAUSED = "paused"
318321
PLAYING = "playing"
319322

323+
# fallback
324+
UNKNOWN = "unknown"
325+
326+
@classmethod
327+
def _missing_(cls, value: object) -> PlayerState: # noqa: ARG003
328+
"""Set default enum member if an unknown value is provided."""
329+
return cls.UNKNOWN
330+
320331

321332
class PlayerType(StrEnum):
322333
"""Enum with possible Player Types.
@@ -478,6 +489,14 @@ class ProviderType(StrEnum):
478489
PLUGIN = "plugin"
479490
CORE = "core"
480491

492+
# fallback
493+
UNKNOWN = "unknown"
494+
495+
@classmethod
496+
def _missing_(cls, value: object) -> ProviderType: # noqa: ARG003
497+
"""Set default enum member if an unknown value is provided."""
498+
return cls.UNKNOWN
499+
481500

482501
class ConfigEntryType(StrEnum):
483502
"""Enum for the type of a config entry."""
@@ -531,6 +550,14 @@ class StreamType(StrEnum):
531550
# custom: custom (bytes) stream - provided by an (async) generator
532551
CUSTOM = "custom"
533552

553+
# fallback
554+
UNKNOWN = "unknown"
555+
556+
@classmethod
557+
def _missing_(cls, value: object) -> StreamType: # noqa: ARG003
558+
"""Set default enum member if an unknown value is provided."""
559+
return cls.UNKNOWN
560+
534561

535562
class VolumeNormalizationMode(StrEnum):
536563
"""Enum with possible VolumeNormalization modes."""
@@ -541,3 +568,11 @@ class VolumeNormalizationMode(StrEnum):
541568
FALLBACK_FIXED_GAIN = "fallback_fixed_gain"
542569
FIXED_GAIN = "fixed_gain"
543570
FALLBACK_DYNAMIC = "fallback_dynamic"
571+
572+
# fallback
573+
UNKNOWN = "unknown"
574+
575+
@classmethod
576+
def _missing_(cls, value: object) -> VolumeNormalizationMode: # noqa: ARG003
577+
"""Set default enum member if an unknown value is provided."""
578+
return cls.UNKNOWN

0 commit comments

Comments
 (0)