Skip to content

Commit b560007

Browse files
committed
feat: update set_mode method to accept Mode enum for improved mode handling
1 parent 9808b71 commit b560007

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/blinkstick/clients/blinkstick.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
from blinkstick.decorators import no_backend_required
1616
from blinkstick.devices import BlinkStickDevice
17-
from blinkstick.enums import BlinkStickVariant
17+
from blinkstick.enums import BlinkStickVariant, Mode
1818
from blinkstick.exceptions import NotConnected
1919
from blinkstick.utilities import string_to_info_block_data
2020

@@ -373,7 +373,7 @@ def get_led_data(self, count: int) -> list[int]:
373373

374374
return device_bytes[2 : 2 + count * 3]
375375

376-
def set_mode(self, mode: int) -> None:
376+
def set_mode(self, mode: Mode | int) -> None:
377377
"""
378378
Set backend mode for BlinkStick Pro. Device currently supports the following modes:
379379
@@ -388,6 +388,10 @@ def set_mode(self, mode: int) -> None:
388388
@type mode: int
389389
@param mode: Device mode to set
390390
"""
391+
# If mode is an enum, get the value
392+
# this will allow the user to pass in the enum directly, and also gate the value to the enum values
393+
if not isinstance(mode, int):
394+
mode = Mode(mode).value
391395
control_string = bytes(bytearray([4, mode]))
392396

393397
self.backend.control_transfer(0x20, 0x9, 0x0004, 0, control_string)

0 commit comments

Comments
 (0)