Themes API Reference¶
The theme system provides professionally-curated color palettes for coordinated lighting across LIFX devices.
Theme Class¶
The Theme class represents a collection of HSBK colors forming a coordinated palette.
Theme
¶
A collection of colors representing a theme or color palette.
Themes can be applied to LIFX devices to coordinate colors across multiple lights. Supports both single-zone and multi-zone devices.
| ATTRIBUTE | DESCRIPTION |
|---|---|
colors |
List of HSBK colors in the theme |
Example
# Create a theme with specific colors
theme = Theme(
[
HSBK(hue=0, saturation=1.0, brightness=1.0, kelvin=3500), # Red
HSBK(hue=120, saturation=1.0, brightness=1.0, kelvin=3500), # Green
HSBK(hue=240, saturation=1.0, brightness=1.0, kelvin=3500), # Blue
]
)
# Access colors
for color in theme:
print(f"Color: {color.hue}°")
# Get a specific color
first_color = theme[0]
# Add more colors
theme.add_color(HSBK(hue=180, saturation=1.0, brightness=1.0, kelvin=3500))
| PARAMETER | DESCRIPTION |
|---|---|
colors
|
List of HSBK colors (defaults to white if None or empty) |
Example
| METHOD | DESCRIPTION |
|---|---|
add_color |
Add a color to the theme. |
random |
Get a random color from the theme. |
shuffled |
Get a new theme with colors in random order. |
get_next_bounds_checked |
Get the next color after index or the last color if at end. |
ensure_color |
Ensure the theme has at least one color. |
__len__ |
Get the number of colors in the theme. |
__iter__ |
Iterate over colors in the theme. |
__getitem__ |
Get a color by index. |
__contains__ |
Check if a color is in the theme. |
__repr__ |
Return a string representation of the theme. |
Source code in src/lifx/theme/theme.py
Functions¶
add_color
¶
add_color(color: HSBK) -> None
Add a color to the theme.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
HSBK color to add
TYPE:
|
Source code in src/lifx/theme/theme.py
random
¶
random() -> HSBK
Get a random color from the theme.
| RETURNS | DESCRIPTION |
|---|---|
HSBK
|
A random HSBK color from the theme |
Source code in src/lifx/theme/theme.py
shuffled
¶
shuffled() -> Theme
Get a new theme with colors in random order.
| RETURNS | DESCRIPTION |
|---|---|
Theme
|
New Theme instance with shuffled colors |
Source code in src/lifx/theme/theme.py
get_next_bounds_checked
¶
Get the next color after index or the last color if at end.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
Index of current color
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HSBK
|
Next HSBK color or the last color if index is at the end |
Example
Source code in src/lifx/theme/theme.py
ensure_color
¶
Ensure the theme has at least one color.
If the theme is empty, adds a default white color.
Source code in src/lifx/theme/theme.py
__iter__
¶
__getitem__
¶
Get a color by index.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
Index of the color (0-based)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HSBK
|
HSBK color at the given index |
| RAISES | DESCRIPTION |
|---|---|
IndexError
|
If index is out of range |
Source code in src/lifx/theme/theme.py
__contains__
¶
Check if a color is in the theme.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
HSBK color to check
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if color is in theme (by value comparison) |
Source code in src/lifx/theme/theme.py
ThemeLibrary Class¶
The ThemeLibrary provides access to 42 official LIFX app themes organized into 6 categories.
ThemeLibrary
¶
Collection of built-in color themes for LIFX devices.
Provides access to 60+ professionally designed themes organized by mood, season, occasion, and time of day.
Example
| METHOD | DESCRIPTION |
|---|---|
get |
Get a theme by name. |
list |
List all available theme names. |
get_by_category |
Get all themes in a category. |
Functions¶
get
classmethod
¶
Get a theme by name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Theme name (case-insensitive)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Theme
|
Theme object |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If theme name is not found |
Example
Source code in src/lifx/theme/library.py
list
classmethod
¶
get_by_category
classmethod
¶
Get all themes in a category.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
Category name (seasonal, mood, holiday, time, etc.)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Theme]
|
Dictionary of Theme objects in the category |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If category is not recognized |
Source code in src/lifx/theme/library.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
Canvas Class¶
The Canvas class provides 2D sparse grid functionality for tile device color interpolation.
Canvas
¶
A Canvas is a collection of points with methods for interacting with those points
The points are stored as (i, j) in a dictionary. The value for each point is an HSBK color.
| METHOD | DESCRIPTION |
|---|---|
add_points_for_tile |
Create points on the canvas around where a tile is. |
surrounding_colors |
Return the colors that surround this (i, j) point. |
has_neighbour |
Return whether there are any points around this (i, j) position. |
shuffle_points |
Take all the points and move them around a random amount. |
blur |
For each point, find the average colour of that point plus all surrounding |
blur_by_distance |
Similar to blur but will find the 8 closest points as opposed to the 8 |
points_for_tile |
Return a list of HSBK values for this tile. |
fill_in_points |
Fill in the gaps on this canvas by blurring the points on the provided canvas |
closest_points |
Return [(distance, color), ...] for the closest consider amount of |
__iter__ |
Yield ((i, j), color) pairs for all our points. |
__getitem__ |
Return the color at point where point is (i, j). |
__setitem__ |
Set the color at point where point is (i, j). |
__contains__ |
Return whether this point has a color where point is (i, j). |
__repr__ |
Return string representation. |
Source code in src/lifx/theme/canvas.py
Functions¶
add_points_for_tile
¶
Create points on the canvas around where a tile is.
We create an area that's half the tile width/height beyond the boundary of the tile. We also spread the points out in a random manner and try to avoid having points next to each other.
Multiple calls to this function will not override existing points on the canvas.
| PARAMETER | DESCRIPTION |
|---|---|
tile
|
Tile coordinates (x, y) or None for single tile |
theme
|
Theme containing colors to distribute
TYPE:
|
Source code in src/lifx/theme/canvas.py
surrounding_colors
¶
Return the colors that surround this (i, j) point.
This will only return points that exist.
has_neighbour
¶
shuffle_points
¶
Take all the points and move them around a random amount.
blur
¶
For each point, find the average colour of that point plus all surrounding points.
Source code in src/lifx/theme/canvas.py
blur_by_distance
¶
Similar to blur but will find the 8 closest points as opposed to the 8 surrounding points.
Source code in src/lifx/theme/canvas.py
points_for_tile
¶
Return a list of HSBK values for this tile.
For any point on the tile that doesn't have a corresponding point on the canvas return a grey value. This is useful for when we tell the applier to not fill in the gaps.
| PARAMETER | DESCRIPTION |
|---|---|
tile
|
Tile coordinates (x, y) or None for single tile |
width
|
Grid width (typically 8)
TYPE:
|
height
|
Grid height (typically 8)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors in row-major order |
Source code in src/lifx/theme/canvas.py
fill_in_points
¶
fill_in_points(
canvas: Canvas, left_x: int, top_y: int, tile_width: int, tile_height: int
) -> None
Fill in the gaps on this canvas by blurring the points on the provided canvas
We blur by finding the 4 closest points for each point on our tile and averaging them.
| PARAMETER | DESCRIPTION |
|---|---|
canvas
|
Source canvas to interpolate from
TYPE:
|
left_x
|
Left x coordinate of tile
TYPE:
|
top_y
|
Top y coordinate of tile
TYPE:
|
tile_width
|
Width of tile
TYPE:
|
tile_height
|
Height of tile
TYPE:
|
Source code in src/lifx/theme/canvas.py
closest_points
¶
Return [(distance, color), ...] for the closest consider amount of points to (i, j).
Source code in src/lifx/theme/canvas.py
__iter__
¶
__getitem__
¶
__setitem__
¶
__contains__
¶
Convenience Function¶
get_theme
¶
Get a theme by name.
Convenience function equivalent to ThemeLibrary.get(name).
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Theme name (case-insensitive)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Theme
|
Theme object |
Example
Source code in src/lifx/theme/library.py
Available Themes (42 Total)¶
Seasonal (3 themes)¶
- spring, autumn, winter
Holiday (9 themes)¶
- christmas, halloween, hanukkah, kwanzaa, shamrock, thanksgiving, calaveras, pumpkin, santa
Mood (16 themes)¶
- peaceful, serene, relaxing, mellow, gentle, soothing, blissful, cheerful, romantic, romance, love, energizing, exciting, epic, intense, powerful, warming
Ambient (6 themes)¶
- dream, fantasy, spacey, stardust, zombie, party
Functional (3 themes)¶
- focusing, evening, bias_lighting
Atmosphere (3 themes)¶
- hygge, tranquil, sports