Index
busylight_core.mixins
¶
Mixin classes for extending Light functionality.
Classes¶
busylight_core.mixins.ColorableMixin
¶
Mixin providing individual RGB color component access and manipulation.
Extends Light classes with individual red, green, and blue properties alongside the standard color tuple property. Use this mixin when you need fine-grained control over individual color components or when building device state objects that store colors as separate fields.
Attributes¶
busylight_core.mixins.ColorableMixin.red
class-attribute
instance-attribute
¶
red = property(
lambda self: getattr(self, "_red", 0),
lambda self, value: setattr(self, "_red", value),
doc="Red color value.",
)
busylight_core.mixins.ColorableMixin.green
class-attribute
instance-attribute
¶
green = property(
lambda self: getattr(self, "_green", 0),
lambda self, value: setattr(self, "_green", value),
doc="Green color value.",
)
busylight_core.mixins.ColorableMixin.blue
class-attribute
instance-attribute
¶
blue = property(
lambda self: getattr(self, "_blue", 0),
lambda self, value: setattr(self, "_blue", value),
doc="Blue color value.",
)
busylight_core.mixins.ColorableMixin.color
property
writable
¶
Get the current RGB color as a tuple.
Returns the combined RGB color values as a 3-tuple. Use this property to read the complete color state when you need all three components together, such as for device updates or color comparisons.
:return: RGB color values as (red, green, blue) tuple with 0-255 range
busylight_core.mixins.TaskableMixin
¶
Associate and manage asynchronous and synchronous tasks.
Provides enhanced task management with automatic strategy selection (asyncio vs threading), prioritization, error handling, and task monitoring capabilities for Light instances.
The environment automatically determines whether to use asyncio tasks or threading timers based on the presence of a running event loop.
Initialize TaskableMixin with task storage for both strategies.
Source code in src/busylight_core/mixins/taskable.py
Attributes¶
busylight_core.mixins.TaskableMixin.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.mixins.TaskableMixin.tasks
cached
property
¶
Active asyncio tasks that are associated with this instance.
Dictionary mapping task names to their corresponding asyncio.Task objects.
busylight_core.mixins.TaskableMixin.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.mixins.TaskableMixin.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)
Functions¶
busylight_core.mixins.TaskableMixin.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.mixins.TaskableMixin.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.mixins.TaskableMixin.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.mixins.TaskableMixin.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.mixins.TaskableMixin.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