Skip to content

State

busylight_core.vendors.thingm.implementation.state

ThingM Blink(1) device state management.

This module defines the State class that manages command construction and device control for ThingM Blink(1) devices, including color control, pattern management, and LED selection.

Classes

busylight_core.vendors.thingm.implementation.state.State

State()

Bases: Word

Complete device state for ThingM Blink(1) commands.

The State class manages command construction for Blink(1) devices. It provides high-level methods for color control, pattern management, and device configuration while handling the low-level bit manipulation required for device communication.

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def __init__(self) -> None:
    super().__init__(0, 64)
Attributes
busylight_core.vendors.thingm.implementation.state.State.report class-attribute instance-attribute
report = ReportField()
busylight_core.vendors.thingm.implementation.state.State.action class-attribute instance-attribute
action = ActionField()
busylight_core.vendors.thingm.implementation.state.State.red class-attribute instance-attribute
red = RedField()
busylight_core.vendors.thingm.implementation.state.State.green class-attribute instance-attribute
green = GreenField()
busylight_core.vendors.thingm.implementation.state.State.blue class-attribute instance-attribute
blue = BlueField()
busylight_core.vendors.thingm.implementation.state.State.play class-attribute instance-attribute
play = PlayField()
busylight_core.vendors.thingm.implementation.state.State.start class-attribute instance-attribute
start = StartField()
busylight_core.vendors.thingm.implementation.state.State.stop class-attribute instance-attribute
stop = StopField()
busylight_core.vendors.thingm.implementation.state.State.count class-attribute instance-attribute
count = CountField()
busylight_core.vendors.thingm.implementation.state.State.fade class-attribute instance-attribute
fade = FadeField()
busylight_core.vendors.thingm.implementation.state.State.leds class-attribute instance-attribute
leds = LedsField()
busylight_core.vendors.thingm.implementation.state.State.line class-attribute instance-attribute
line = LinesField()
busylight_core.vendors.thingm.implementation.state.State.color property writable
color

Get the current RGB color as a tuple.

busylight_core.vendors.thingm.implementation.state.State.initial_value instance-attribute
initial_value = value
busylight_core.vendors.thingm.implementation.state.State.length instance-attribute
length = length
busylight_core.vendors.thingm.implementation.state.State.bits instance-attribute
bits = array('B', [value >> n & 1 for n in range])
busylight_core.vendors.thingm.implementation.state.State.value property
value

Return the integer value of the word.

busylight_core.vendors.thingm.implementation.state.State.range property
range

Return the range of bit offsets for this word.

busylight_core.vendors.thingm.implementation.state.State.hex property
hex

Return a string hexadecimal representation of the word.

busylight_core.vendors.thingm.implementation.state.State.bin property
bin

Return a string binary representation of the word.

Functions
busylight_core.vendors.thingm.implementation.state.State.fade_to_color
fade_to_color(color, fade_ms=10, leds=All)

Configure device to fade to specified color.

:param color: RGB color tuple (red, green, blue) with values 0-255 :param fade_ms: Fade duration in milliseconds :param leds: Which LEDs to control (All, Top, or Bottom)

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def fade_to_color(
    self,
    color: tuple[int, int, int],
    fade_ms: int = 10,
    leds: LEDS = LEDS.All,
) -> None:
    """Configure device to fade to specified color.

    :param color: RGB color tuple (red, green, blue) with values 0-255
    :param fade_ms: Fade duration in milliseconds
    :param leds: Which LEDs to control (All, Top, or Bottom)
    """
    self.clear()
    self.report = Report.One
    self.action = Action.FadeColor
    self.color = color
    self.fade = fade_ms
    self.leds = leds
busylight_core.vendors.thingm.implementation.state.State.write_pattern_line
write_pattern_line(color, fade_ms, index)

Write a single line to the device's pattern memory.

:param color: RGB color tuple for this pattern line :param fade_ms: Fade duration for this pattern step :param index: Pattern line index (0-15)

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def write_pattern_line(
    self,
    color: tuple[int, int, int],
    fade_ms: int,
    index: int,
) -> None:
    """Write a single line to the device's pattern memory.

    :param color: RGB color tuple for this pattern line
    :param fade_ms: Fade duration for this pattern step
    :param index: Pattern line index (0-15)
    """
    self.clear()
    self.report = Report.One
    self.action = Action.SetColorPattern
    self.color = color
    self.fade = fade_ms
    self.line = index
busylight_core.vendors.thingm.implementation.state.State.save_patterns
save_patterns()

Save current pattern memory to device flash storage.

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def save_patterns(self) -> None:
    """Save current pattern memory to device flash storage."""
    self.clear()
    self.report = Report.One
    self.action = Action.SaveColorPatterns
    self.color = (0xBE, 0xEF, 0xCA)
    self.count = 0xFE
busylight_core.vendors.thingm.implementation.state.State.play_loop
play_loop(play, start, stop, count=0)

Start pattern playback loop.

:param play: Play mode (0=stop, 1=play) :param start: Starting pattern line index :param stop: Ending pattern line index :param count: Number of loops (0=infinite)

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def play_loop(self, play: int, start: int, stop: int, count: int = 0) -> None:
    """Start pattern playback loop.

    :param play: Play mode (0=stop, 1=play)
    :param start: Starting pattern line index
    :param stop: Ending pattern line index
    :param count: Number of loops (0=infinite)
    """
    self.clear()
    self.report = Report.One
    self.action = Action.PlayLoop
    self.play = play
    self.start = start
    self.stop = stop
    self.count = count
busylight_core.vendors.thingm.implementation.state.State.clear_patterns
clear_patterns(start=0, count=16)

Clear pattern memory by writing black to specified range.

:param start: Starting pattern line index :param count: Number of pattern lines to clear

Source code in src/busylight_core/vendors/thingm/implementation/state.py
def clear_patterns(self, start: int = 0, count: int = 16) -> None:
    """Clear pattern memory by writing black to specified range.

    :param start: Starting pattern line index
    :param count: Number of pattern lines to clear
    """
    for index in range(start, start + count):
        self.write_pattern_line((0, 0, 0), 0, index)
busylight_core.vendors.thingm.implementation.state.State.clear
clear()

Clear all bits in the word.

Source code in src/busylight_core/word.py
def clear(self) -> None:
    """Clear all bits in the word."""
    self.bits = array.array("B", [0] * self.length)