33import sys
44import time
55import warnings
6+ from functools import cached_property
67from typing import Callable
78
89from blinkstick .colors import (
1213 remap_rgb_value_reverse ,
1314 ColorFormat ,
1415)
15- from blinkstick .decorators import no_backend_required
16+ from blinkstick .configs import _get_device_config
1617from blinkstick .devices import BlinkStickDevice
1718from blinkstick .enums import BlinkStickVariant
18- from blinkstick .exceptions import NotConnected
19+ from blinkstick .exceptions import NotConnected , UnsupportedOperation
20+ from blinkstick .models import Configuration
1921from blinkstick .utilities import string_to_info_block_data
2022
2123if sys .platform == "win32" :
@@ -78,6 +80,15 @@ def wrapper(*args, **kwargs):
7880 return wrapper
7981 return attr
8082
83+ @cached_property
84+ def _config (self ) -> Configuration :
85+ """
86+ Get the hardware configuration of the connected device, using the reported variant.
87+
88+ @rtype: Configuration
89+ """
90+ return _get_device_config (self .get_variant ())
91+
8192 def get_serial (self ) -> str :
8293 """
8394 Returns the serial number of backend.::
@@ -372,6 +383,10 @@ def set_mode(self, mode: int) -> None:
372383 @type mode: int
373384 @param mode: Device mode to set
374385 """
386+ if not self ._config .mode_change_support :
387+ raise UnsupportedOperation (
388+ "This operation is only supported on BlinkStick Pro devices"
389+ )
375390 control_string = bytes (bytearray ([4 , mode ]))
376391
377392 self .backend .control_transfer (0x20 , 0x9 , 0x0004 , 0 , control_string )
@@ -391,6 +406,10 @@ def get_mode(self) -> int:
391406 @rtype: int
392407 @return: Device mode
393408 """
409+ if not self ._config .mode_change_support :
410+ raise UnsupportedOperation (
411+ "This operation is only supported on BlinkStick Pro devices"
412+ )
394413
395414 device_bytes = self .backend .control_transfer (0x80 | 0x20 , 0x1 , 0x0004 , 0 , 2 )
396415
0 commit comments