LED

Code Example

from periphery import LED

# Open LED "led0" with initial state off
led0 = LED("led0", False)
# Open LED "led1" with initial state on
led1 = LED("led1", True)

value = led0.read()
led1.write(value)

# Set custom brightness level
led1.write(led1.max_brightness / 2)

led0.close()
led1.close()

API

class periphery.LED(name, brightness=None)[source]

Bases: object

Instantiate an LED object and open the sysfs LED corresponding to the specified name.

brightness can be a boolean for on/off, integer value for a specific brightness, or None to preserve existing brightness. Default is preserve existing brightness.

Parameters
  • name (str) – Linux led name.

  • brightness (bool, int, None) – Initial brightness.

Returns

LED object.

Return type

LED

Raises
  • LEDError – if an I/O or OS error occurs.

  • TypeError – if name or brightness types are invalid.

  • LookupError – if LED name does not exist.

  • ValueError – if brightness value is invalid.

read()[source]

Read the brightness of the LED.

Returns

Current brightness.

Return type

int

Raises

LEDError – if an I/O or OS error occurs.

write(brightness)[source]

Set the brightness of the LED to brightness.

brightness can be a boolean for on/off, or integer value for a specific brightness.

Parameters

brightness (bool, int) – Brightness value to set.

Raises
  • LEDError – if an I/O or OS error occurs.

  • TypeError – if brightness type is not bool or int.

close()[source]

Close the sysfs LED.

Raises

LEDError – if an I/O or OS error occurs.

property devpath

Get the device path of the underlying sysfs LED device.

Type

str

property fd

Get the file descriptor for the underlying sysfs LED “brightness” file of the LED object.

Type

int

property name

Get the sysfs LED name.

Type

str

property max_brightness

Get the LED’s max brightness.

Type

int

property brightness

Get or set the LED’s brightness.

Value can be a boolean for on/off, or integer value a for specific brightness.

Raises
  • LEDError – if an I/O or OS error occurs.

  • TypeError – if brightness type is not bool or int.

  • ValueError – if brightness value is invalid.

Type

int

class periphery.LEDError[source]

Bases: OSError

Base class for LED errors.