Skip to content

State

busylight_core.vendors.agile_innovative.implementation.state

Agile Innovative BlinkStick device state management.

This module defines the State class that manages command construction for BlinkStick devices, including LED arrays and color format conversion.

Classes

busylight_core.vendors.agile_innovative.implementation.state.State

State(*, report, nleds)

BlinkStick State manager for multi-LED devices.

BlinkStick devices store colors in Green-Red-Blue (GRB) format internally, while the public API uses the standard Red-Green-Blue (RGB) format. This class handles the conversion automatically and supports multiple device variants with different LED counts and report formats.

Initialize BlinkStick state.

:param report: HID report number for this device variant :param nleds: Number of LEDs supported by this device

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
def __init__(self, *, report: int, nleds: int) -> None:
    """Initialize BlinkStick state.

    :param report: HID report number for this device variant
    :param nleds: Number of LEDs supported by this device
    """
    self.report = report
    self.nleds = nleds
    self.channel = 0
    self.colors: list[tuple[int, int, int]] = [(0, 0, 0)] * nleds
Attributes
busylight_core.vendors.agile_innovative.implementation.state.State.report instance-attribute
report = report
busylight_core.vendors.agile_innovative.implementation.state.State.nleds instance-attribute
nleds = nleds
busylight_core.vendors.agile_innovative.implementation.state.State.channel instance-attribute
channel = 0
busylight_core.vendors.agile_innovative.implementation.state.State.colors instance-attribute
colors = [(0, 0, 0)] * nleds
busylight_core.vendors.agile_innovative.implementation.state.State.color property writable
color

Get the current RGB color of the first lit LED.

Returns the color of the first LED that has a non-zero color value, converted from internal GRB format to standard RGB format.

Functions
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick classmethod
blinkstick()

Create state for original BlinkStick (single LED, report 1).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick(cls) -> State:
    """Create state for original BlinkStick (single LED, report 1)."""
    return cls(report=1, nleds=1)
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick_pro classmethod
blinkstick_pro()

Create state for BlinkStick Pro (192 LEDs, report 2).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick_pro(cls) -> State:
    """Create state for BlinkStick Pro (192 LEDs, report 2)."""
    return cls(report=2, nleds=192)
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick_square classmethod
blinkstick_square()

Create state for BlinkStick Square (8 LEDs, report 6).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick_square(cls) -> State:
    """Create state for BlinkStick Square (8 LEDs, report 6)."""
    return cls(report=6, nleds=8)
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick_strip classmethod
blinkstick_strip()

Create state for BlinkStick Strip (8 LEDs, report 6).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick_strip(cls) -> State:
    """Create state for BlinkStick Strip (8 LEDs, report 6)."""
    return cls(report=6, nleds=8)
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick_nano classmethod
blinkstick_nano()

Create state for BlinkStick Nano (2 LEDs, report 6).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick_nano(cls) -> State:
    """Create state for BlinkStick Nano (2 LEDs, report 6)."""
    return cls(report=6, nleds=2)
busylight_core.vendors.agile_innovative.implementation.state.State.blinkstick_flex classmethod
blinkstick_flex()

Create state for BlinkStick Flex (32 LEDs, report 6).

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@classmethod
def blinkstick_flex(cls) -> State:
    """Create state for BlinkStick Flex (32 LEDs, report 6)."""
    return cls(report=6, nleds=32)
busylight_core.vendors.agile_innovative.implementation.state.State.rgb_to_grb staticmethod
rgb_to_grb(color)

Convert RGB color tuple to internal GRB representation.

:param color: RGB color tuple (red, green, blue) :return: GRB color tuple (green, red, blue)

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@staticmethod
def rgb_to_grb(color: tuple[int, int, int]) -> tuple[int, int, int]:
    """Convert RGB color tuple to internal GRB representation.

    :param color: RGB color tuple (red, green, blue)
    :return: GRB color tuple (green, red, blue)
    """
    r, g, b = color
    return (g, r, b)
busylight_core.vendors.agile_innovative.implementation.state.State.grb_to_rgb staticmethod
grb_to_rgb(color)

Convert internal GRB color tuple to RGB representation.

:param color: GRB color tuple (green, red, blue) :return: RGB color tuple (red, green, blue)

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
@staticmethod
def grb_to_rgb(color: tuple[int, int, int]) -> tuple[int, int, int]:
    """Convert internal GRB color tuple to RGB representation.

    :param color: GRB color tuple (green, red, blue)
    :return: RGB color tuple (red, green, blue)
    """
    g, r, b = color
    return (r, g, b)
busylight_core.vendors.agile_innovative.implementation.state.State.get_led
get_led(index)

Get the RGB color of a specific LED.

:param index: LED index (0-based) :return: RGB color tuple, or (0,0,0) if index is invalid

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
def get_led(self, index: int) -> tuple[int, int, int]:
    """Get the RGB color of a specific LED.

    :param index: LED index (0-based)
    :return: RGB color tuple, or (0,0,0) if index is invalid
    """
    try:
        return self.grb_to_rgb(self.colors[index])
    except IndexError:
        return (0, 0, 0)
busylight_core.vendors.agile_innovative.implementation.state.State.set_led
set_led(index, color)

Set the RGB color of a specific LED.

:param index: LED index (0-based) :param color: RGB color tuple to set

Source code in src/busylight_core/vendors/agile_innovative/implementation/state.py
def set_led(self, index: int, color: tuple[int, int, int]) -> None:
    """Set the RGB color of a specific LED.

    :param index: LED index (0-based)
    :param color: RGB color tuple to set
    """
    with contextlib.suppress(IndexError):
        self.colors[index] = self.rgb_to_grb(color)