Thingm base
busylight_core.vendors.thingm.thingm_base
¶
ThingM vendor base class.
Classes¶
busylight_core.vendors.thingm.thingm_base.ThingMBase
¶
Bases: Light
Base class for ThingM Blink(1) devices.
Provides common functionality for all ThingM devices, primarily the Blink(1) product line. Use this as a base class when implementing new Blink(1) variants.
Initialize a Light instance with the specified hardware device.
Creates a Light instance bound to the given hardware device and configures it for use. The hardware should be obtained from Hardware.enumerate() and verified with the class's claims() method.
Use this constructor when you have specific hardware and want to create a Light instance for direct device control.
:param hardware: Hardware instance representing the device to control :param reset: Reset the device to a known state during initialization :param exclusive: Acquire exclusive access to prevent interference :raises HardwareUnsupportedError: If Light class cannot control hardware
Source code in src/busylight_core/light.py
Attributes¶
busylight_core.vendors.thingm.thingm_base.ThingMBase.event_loop
cached
property
¶
The default event loop.
Returns the currently running event loop, or creates a new one if no event loop is currently running.
busylight_core.vendors.thingm.thingm_base.ThingMBase.tasks
cached
property
¶
Active asyncio tasks that are associated with this instance.
Dictionary mapping task names to their corresponding asyncio.Task objects.
busylight_core.vendors.thingm.thingm_base.ThingMBase.task_info
cached
property
¶
Enhanced task information with priority and status tracking.
Dictionary mapping task names to TaskInfo objects containing metadata about priority, creation time, and current status.
busylight_core.vendors.thingm.thingm_base.ThingMBase.task_strategy
cached
property
¶
Return the appropriate task instantiation function based on environment.
Automatically detects if we're in an asyncio context and returns the corresponding task creation function. Both functions have identical call signatures for transparent usage.
:return: Function to create tasks (asyncio or threading based)
busylight_core.vendors.thingm.thingm_base.ThingMBase.supported_device_ids
class-attribute
¶
busylight_core.vendors.thingm.thingm_base.ThingMBase.hardware
instance-attribute
¶
busylight_core.vendors.thingm.thingm_base.ThingMBase.path
cached
property
¶
The path to the hardware device.
busylight_core.vendors.thingm.thingm_base.ThingMBase.platform
cached
property
¶
The discovered operating system platform name.
busylight_core.vendors.thingm.thingm_base.ThingMBase.exclusive
property
¶
Return True if the light has exclusive access to the hardware.
busylight_core.vendors.thingm.thingm_base.ThingMBase.was_reset
property
¶
Return True if the light was reset when the hardware was initialized.
busylight_core.vendors.thingm.thingm_base.ThingMBase.sort_key
cached
property
¶
Return a tuple used for sorting lights.
The tuple consists of: - vendor name in lowercase - device name in lowercase - hardware path
busylight_core.vendors.thingm.thingm_base.ThingMBase.name
cached
property
¶
The human-readable marketing name of this light.
busylight_core.vendors.thingm.thingm_base.ThingMBase.hex
property
¶
The hexadecimal representation of the light's state.
busylight_core.vendors.thingm.thingm_base.ThingMBase.read_strategy
property
¶
The read method used by this light.
busylight_core.vendors.thingm.thingm_base.ThingMBase.write_strategy
property
¶
The write method used by this light.
busylight_core.vendors.thingm.thingm_base.ThingMBase.color
abstractmethod
property
writable
¶
Get the current RGB color of the light.
busylight_core.vendors.thingm.thingm_base.ThingMBase.is_lit
property
¶
Check if the light is currently lit.
Functions¶
busylight_core.vendors.thingm.thingm_base.ThingMBase.vendor
staticmethod
¶
Return the vendor name for ThingM devices.
Provides the official vendor branding for user interfaces and device identification.
:return: Official vendor name string
Source code in src/busylight_core/vendors/thingm/thingm_base.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.add_task
¶
add_task(
name,
func,
priority=NORMAL,
replace=False,
interval=None,
)
Create a task using environment-appropriate strategy.
The environment (asyncio vs non-asyncio) automatically determines whether to use asyncio tasks or threading timers. Both strategies support the same function signatures and periodic execution.
:param name: Unique identifier for the task :param func: Function to execute (sync or async) :param priority: Task priority (used for asyncio tasks only) :param replace: Whether to replace existing task with same name :param interval: For periodic tasks, repeat interval in seconds :return: Created asyncio.Task or threading.Timer
Source code in src/busylight_core/mixins/taskable.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.cancel_task
¶
Cancel task regardless of which strategy created it.
:param name: Name of task to cancel :return: The cancelled task/timer or None if not found
Source code in src/busylight_core/mixins/taskable.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.cancel_tasks
¶
Cancel all tasks or tasks of specific priority.
Cancels either all tasks or only tasks matching the specified priority level.
:param priority: If specified, only cancel tasks of this priority level
Source code in src/busylight_core/mixins/taskable.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.get_task_status
¶
Get detailed status information for a task.
Returns comprehensive status information including running state, exceptions, priority, and creation time.
:param name: Name of task to check :return: Dictionary with task status details or None if not found
Source code in src/busylight_core/mixins/taskable.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.list_active_tasks
¶
Get list of currently active task names.
Returns sorted list of task names that are currently running.
:return: List of task names that are currently running
Source code in src/busylight_core/mixins/taskable.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.unique_device_names
cached
classmethod
¶
Get all unique marketing names for devices supported by this class.
Returns the human-readable product names from the supported_device_ids mapping, with duplicates removed. Use this to display available device types to users or for device capability documentation.
:return: Sorted list of unique device marketing names
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.unique_device_ids
cached
classmethod
¶
Get all unique vendor/product ID pairs supported by this class.
Returns the USB vendor and product ID combinations that this class can control. Use this for hardware enumeration, udev rule generation, or debugging device detection issues.
:return: Sorted list of (vendor_id, product_id) tuples
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.claims
classmethod
¶
Check if this class can control the given hardware device.
Determines whether this Light subclass supports the specific hardware by checking if the device's vendor/product ID pair matches any entry in the supported_device_ids mapping. Use this during device discovery to find the appropriate Light subclass for each detected device.
:param hardware: Hardware instance to test for compatibility :return: True if this class can control the hardware device
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.subclasses
cached
classmethod
¶
Return a list of all subclasses of this class.
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.supported_lights
cached
classmethod
¶
Return a dictionary of supported lights by vendor.
Keys are vendor names, values are a list of product names.
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.available_hardware
classmethod
¶
Discover all compatible hardware devices available for control.
Scans the system for USB devices that match known vendor/product ID combinations and groups them by the Light subclass that can control them. Use this for device discovery, inventory management, or when you need to present users with available device options.
The returned Hardware instances represent devices that were found and claimed by Light subclasses, but may still be in use by other processes. Actual device acquisition occurs during Light initialization.
:return: Mapping from Light subclass to list of compatible Hardware instances
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.all_lights
classmethod
¶
Create initialized Light instances for all available compatible devices.
Discovers all compatible hardware and returns Light instances ready for immediate use. Each light is initialized with the specified configuration and can be used to control its device without further setup.
Use this when you want to control all connected lights simultaneously, such as for synchronized effects or system-wide status indication.
:param reset: Reset devices to known state during initialization :param exclusive: Acquire exclusive access to prevent interference :return: List of initialized Light instances, empty if none found
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.first_light
classmethod
¶
Create the first available Light instance ready for immediate use.
Discovers compatible devices and returns the first successfully initialized Light instance. Use this when you need a single light for simple status indication and don't care about the specific device type or vendor.
:param reset: Reset device to known state during initialization :param exclusive: Acquire exclusive access to prevent interference :return: Initialized Light instance ready for control :raises NoLightsFoundError: If no compatible devices found or init fails
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.udev_rules
classmethod
¶
Return a dictionary of udev rules for the light subclass.
The keys of the dictionary are device ID tuples, while the values are lists of udev rules for a particular light. If duplicate device IDs are encountered, the first device ID wins and subsequent device IDs are ignored.
:param mode: int - file permissions for the device, defaults to 0o666
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.release
¶
Release the light's exclusive access to the hardware.
If the light was acquired in exclusive mode, this method releases the hardware resource, allowing other processes to access it. If the light was not acquired in exclusive mode, no action is taken.
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.exclusive_access
¶
Manage exclusive access to the light.
If the device is not acquired in exclusive mode, it will be acquired and released automatically.
No actions are taken if the light is already acquired in exclusive mode.
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.update
¶
Send the current light state to the physical device.
Serializes the light's current state and transmits it to the hardware device using the appropriate platform-specific protocol. Call this method after making changes to light properties to apply them to the physical device.
The method handles platform-specific protocol differences automatically, such as adding leading zero bytes on Windows 10.
:raises LightUnavailableError: If device communication fails
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.batch_update
¶
Defer device updates until multiple properties are changed.
Context manager that accumulates multiple property changes and sends them to the device in a single update operation when exiting the context. Use this when changing multiple light properties (color, brightness, effects) to reduce USB communication overhead and improve performance.
:return: Context manager for batching multiple property updates
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.on
abstractmethod
¶
Activate the light with the specified RGB color.
Sets the light to display the given color immediately. This is the primary method for controlling light appearance and should be implemented by all device-specific subclasses.
For devices with multiple LEDs, use led parameter to target specific LEDs or set to 0 to affect all LEDs simultaneously. Single-LED devices should ignore the led parameter.
:param color: RGB intensity values from 0-255 for each color component :param led: Target LED index, 0 affects all LEDs on the device
Source code in src/busylight_core/light.py
busylight_core.vendors.thingm.thingm_base.ThingMBase.off
¶
Turn off the light by setting it to black.
Deactivates the specified LED(s) by setting their color to black (0, 0, 0). Use this to turn off status indication while keeping the device available for future color changes.
For multi-LED devices, specify the LED index or use 0 to turn off all LEDs. Single-LED devices ignore the led parameter.
:param led: Target LED index, 0 affects all LEDs on the device