Skip to content

💡 Led API

linuxpy.led

Human friendly interface to linux LED subsystem.

from linuxpy.led import find

caps_lock = find(function="capslock")
print(caps_lock.brightness)
caps_lock.brightness = caps_lock.max_brightness
ULED
from linuxpy.led import LED, ULED

with ULED("uled::simulation") as uled:
    led = LED.from_name("uled::simulation")
    print()

Streaming example:

from time import monotonic

from linuxpy.led import ULED

with ULED("uled::simulation", max_brightness=100) as uled:
    # Open another terminal and type:
    # echo 10 > /sys/class/leds/uled::simulation/brightness
    for brightness in uled.stream():
        print(f"[{monotonic():.6f}]: {brightness}")

LED(syspath: os.PathLike)

Bases: Device

Main LED class

name: str property

LED name from the naming

devicename: str property

LED device name from the naming

color: str property

LED color from the naming

function: str property

LED function from the naming

trigger_enabled: bool property

Tells if the LED trigger is enabled

from_name(name) -> LED classmethod

Create a LED from the name that corresponds /sys/class/leds/

ULED(name: str, max_brightness: int = 1, **kwargs)

Bases: BaseDevice

LED class for th userspace LED. This can be useful for testing triggers and can also be used to implement virtual LEDs.

brightness: int property

Read new brightness. Blocks until brightness changes

read() -> bytes

Read new brightness. Blocks until brightness changes

stream() -> Iterable[int]

Infinite stream of brightness change events

iter_device_paths() -> Iterable[pathlib.Path]

Iterable of all LED syspaths (/sys/class/leds)

iter_devices() -> Iterable[LED]

Iterable over all LED devices

find(find_all: bool = False, custom_match: Optional[Callable] = None, **kwargs) -> Union[LED, Iterable[LED], None]

If find_all is False:

Find a LED follwing the criteria matched by custom_match and kwargs. If no LED is found matching the criteria it returns None. Default is to return a random LED device.

If find_all is True:

The result is an iterator. Find all LEDs that match the criteria custom_match and kwargs. If no LED is found matching the criteria it returns an empty iterator. Default is to return an iterator over all LEDs found on the system.