From 9c7df28f0ba8dfd381af168fde7944f225dbc9fe Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Fri, 10 May 2024 20:02:50 -0400 Subject: [PATCH 1/2] color_mode is not unpacked to an enum Fixes https://github.com/jath03/openrgb-python/issues/69 --- openrgb/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openrgb/utils.py b/openrgb/utils.py index 24d2a6d..dbd4b9f 100644 --- a/openrgb/utils.py +++ b/openrgb/utils.py @@ -33,6 +33,9 @@ class ModeDirections(IntEnum): class ModeColors(IntEnum): + """ + Partial list of color_mode values. This is not a comprehensive set so do not use this to unpack. + """ NONE = 0 PER_LED = 1 MODE_SPECIFIC = 2 @@ -245,7 +248,7 @@ class ModeData: speed: Optional[int] brightness: Optional[int] direction: Optional[ModeDirections] - color_mode: ModeColors + color_mode: int colors: Optional[list[RGBColor]] def validate(self, version: int): @@ -329,7 +332,7 @@ def unpack(cls, data: Iterator[int], version: int, index: int = 0) -> ModeData: else: brightness = None direction = parse_var('I', data) - color_mode = ModeColors(parse_var('I', data)) + color_mode = parse_var('I', data) num_colors = parse_var('H', data) colors = [] From 4dd73017fd2e1a8323381a8ea9e235880639ba35 Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Fri, 10 May 2024 20:12:26 -0400 Subject: [PATCH 2/2] Handle cases when direction still comes in as garbage --- openrgb/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openrgb/utils.py b/openrgb/utils.py index dbd4b9f..e510daf 100644 --- a/openrgb/utils.py +++ b/openrgb/utils.py @@ -341,7 +341,10 @@ def unpack(cls, data: Iterator[int], version: int, index: int = 0) -> ModeData: if (ModeFlags.HAS_DIRECTION_HV in flags or ModeFlags.HAS_DIRECTION_UD in flags or ModeFlags.HAS_DIRECTION_LR in flags): - direction = ModeDirections(direction) + try: + direction = ModeDirections(direction) + except ValueError: + direction = None else: direction = None if ModeFlags.HAS_SPEED not in flags: