Skip to content

Commit bfd0fad

Browse files
committed
Improved mode validation of brightness, added validation override
1 parent d0a20a7 commit bfd0fad

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

openrgb/orgb.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22
import struct
33
import platform
4+
import warnings
45
from openrgb import utils
56
from typing import Union, Any, Optional
67
from openrgb.network import NetworkClient
78
from openrgb.plugins import create_plugin, ORGBPlugin
8-
from time import sleep
99
from os import environ
1010

1111

@@ -294,7 +294,7 @@ def set_colors(self, colors: list[utils.RGBColor], fast: bool = False):
294294
elif active_mode.color_mode == utils.ModeColors.PER_LED:
295295
self._set_device_colors(colors, fast)
296296

297-
def set_mode(self, mode: Union[str, int, utils.ModeData], save: bool = False):
297+
def set_mode(self, mode: Union[str, int, utils.ModeData], save: bool = False, force: bool = False):
298298
'''
299299
Sets the device's mode
300300
@@ -313,7 +313,13 @@ def set_mode(self, mode: Union[str, int, utils.ModeData], save: bool = False):
313313
pass
314314
else:
315315
raise TypeError()
316-
data = mode.pack(self.comms._protocol_version) # type: ignore
316+
try:
317+
data = mode.pack(self.comms._protocol_version) # type: ignore
318+
except ValueError as e:
319+
if force:
320+
warnings.warn(str(e))
321+
else:
322+
raise e
317323
self.comms.send_header(
318324
self.id,
319325
utils.PacketType.RGBCONTROLLER_UPDATEMODE,

openrgb/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def validate(self, version: int):
259259
if ModeFlags.HAS_MODE_SPECIFIC_COLOR in self.flags:
260260
assert self.colors_min <= len(self.colors) <= self.colors_max # type: ignore
261261
if ModeFlags.HAS_BRIGHTNESS in self.flags and version >= 3:
262-
assert self.brightness_min <= self.brightness <= self.brightness_max # type: ignore
262+
assert self.brightness_min <= self.brightness <= self.brightness_max or self.brightness_max <= self.brightness <= self.brightness_min # type: ignore
263263
except AssertionError as e:
264264
raise ValueError("Mode validation failed. Required values invalid or not present") from e
265265

0 commit comments

Comments
 (0)