• Stars
    star
    206
  • Rank 189,432 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Control USB connected presence lights from multiple vendors via the command-line or web API.

BusyLight Project Logo
version monthly-downloads visits supported python versions license Code style: black
pytest-linux MacOS pytest-windows

BusyLight for Humans™ gives you control of USB attached LED lights from a variety of vendors. Lights can be controlled via the command-line, using a HTTP API or imported directly into your own Python project.

All Supported Lights Flag1, Busylight Alpha2, Status Indicator3, Blink(1)4, Mute5, Blynclight6. Orb7, BusyLight Omega8, BlinkStick Square9, Blynclight Mini10, MuteMe Original11, fit-statUSB12, MuteSync13, Blynclight Plus14

Features

  • Control lights from the command-line.
  • Control lights via a Web API.
  • Import busylight into your own Python project.
  • Supported on MacOS and Linux
  • Windows support is untested but there are reports that it is working.
  • Supports nine vendors & sixteen devices:
Vendor
Agile Innovative BlinkStick Square
Compulab fit-statUSB
Embrava Blynclight Blynclight Mini Blynclight Plus
Kuando Busylight Alpha BusyLight Omega
Luxafor Bluetooth Flag Mute Orb
Plantronics Status Indicator
MuteMe MuteMe Original Mute Mini
MuteSync MuteSync
ThingM Blink(1)

If you have a USB light that's not on this list open an issue with:

  • the make and model device you want supported
  • where I can get one
  • any public hardware documentation you are aware of

Or even better, open a pull request!

Gratitude

Thank you to @todbot and the very nice people at ThingM who graciously and unexpectedly gifted me with two blink(1) mk3 lights!

Basic Install

Installs only the command-line busylight tool and associated modules.

$ python3 -m pip install busylight-for-humans 

Web API Install

Installs uvicorn and FastAPI in addition to busylight:

$ python3 -m pip install busylight-for-humans[webapi]

Development Install

I use the tool poetry to manage various aspects of this project, including:

  • dependencies
  • pytest configuration
  • versioning
  • optional dependencies
  • virtual environment creation
  • building packages
  • publishing packages to PyPi
$ python3 -m pip install poetry 
$ cd path/to/busylight
$ poetry shell
<venv> $ poetry install -E webapi
<venv> $ which busylight
<venv> $ which busyserve

After installing into the virtual environment, the project is now available in editable mode. Changes made in the source will be reflected in the runtime behavior when running in the poetry initiated shell.

Linux Post-Install Activities

Linux controls access to USB devices via the udev subsystem. By default it denies non-root users access to devices it doesn't recognize. I've got you covered!

You'll need root access to configure the udev rules:

$ busylight udev-rules -o 99-busylights.rules
$ sudo cp 99-busylights.rules /etc/udev/rules.d
$ sudo udevadm control -R
$ # unplug/plug your light
$ busylight on

Command-Line Examples

$ busylight on               # light turns on green
$ busylight on red           # now it's shining a friendly red
$ busylight on 0xff0000      # still red
$ busylight on #00ff00       # now it's blue!
$ busylight blink            # it's slowly blinking on and off with a red color
$ busylight blink green fast # blinking faster green and off
$ busylight --all on         # turn all lights on green
$ busylight --all off        # turn all lights off

HTTP API Examples

First start the busylight API server using the busyserv command line interface:

$ busyserve -D
INFO:     Started server process [40064]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
...

The API is fully documented and available via these URLs:

  • https://localhost:8000/redoc
  • https://localhost:8000/docs

Now you can use the web API endpoints which return JSON payloads:

  $ curl -s http://localhost:8000/lights/status | jq
  ...
  $ curl -s http://localhost:8000/light/0/status | jq
  ...
  $ curl -s http://localhost:8000/light/0/on | jq
  {
    "light_id": 0,
    "action": "on",
    "color": "green",
	"rgb": [0, 128, 0]
  }
  $ curl -s http://localhost:8000/light/0/off | jq
  {
    "light_id": 0,
    "action": "off"
  }
  $ curl -s http://localhost:8000/light/0/on?color=purple | jq
  {
    "light_id": 0,
    "action": "on",
    "color": "purple",
	"rgb": [128, 0, 128]
  }
  $ curl -s http://localhost:8000/lights/on | jq
  {
    "light_id": "all",
    "action": "on",
    "color": "green",
	"rgb", [0, 128, 0]
  }
  $ curl -s http://localhost:8000/lights/off | jq
  {
    "light_id": "all",
    "action": "off"
  }
  $ curl -s http://localhost:8000/lights/rainbow | jq
  {
    "light_id": "all",
    "action": "effect",
    "name": "rainbow"
  }

Authentication

The API can be secured with a simple username and password through HTTP Basic Authentication. To require authentication for all API requests, set the BUSYLIGHT_API_USER and BUSYLIGHT_API_PASS environmental variables before running busyserve.

⚠️ SECURITY WARNING: HTTP Basic Auth sends usernames and passwords in cleartext (i.e., unencrypted). Use of SSL is highly recommended!

Code Examples

Adding light support to your own python applications is easy!

Simple Case: Turn On a Single Light

In this example, we pick an Embrava Blynclight to activate with the color white.

from busylight.lights.embrava import Blynclight

light = Blynclight.first_light()

light.on((255, 255, 255))

Not sure what light you've got?

from busylight.lights import USBLight

light = USBLight.first_light()

light.on((0xff, 0, 0xff))

Slightly More Complicated

The busylight package includes a manager class that's great for working with multiple lights or lights that require a little more direct intervention like the Kuando Busylight family.

from busylight.manager import LightManager
from busylight.effects import Effects

manager = LightManager()
for light in manager.lights:
   print(light.name)
   
rainbow = Effects.for_name("spectrum")(duty_cycle=0.05)

manager.apply_effect(rainbow)
...
manager.off()

More Repositories

1

DungeonGenerator

Procedural Dungeon Generation with Python and Pygame
Python
67
star
2

tokyo60_keymap

Tokyo60 HHKB-Style QMK Keymap
35
star
3

Geometry

Python Geometry Package
Python
25
star
4

blynclight

Python bindings for the Embrava BlyncLight family of products.
Python
21
star
5

meowmeow

MeowMeow - A Toy File Encoder/Decoder
C
20
star
6

GameOfLife

Conway's Game of Life
Python
20
star
7

springer_downloader

Bulk Textbook Download Tool
Python
11
star
8

pyliter

Generate PNG images of syntax highlighted Python.
Python
10
star
9

bitvector

Bit Vector for Humans™
Python
9
star
10

cli-examples

A selection of CLI example code in Python
Python
8
star
11

DungeonGenerator2

Procedural Dungeon Generation with Python and Kivy
Python
8
star
12

KSPManager

KSPManager: Kerbal Space Program Part & Plugin Manager
Objective-C
8
star
13

BetterDungeons

Procedurally created D&D maps using python and arcade.
Python
8
star
14

SimpleCPU

Python
3
star
15

busylight-homebridge-plugin

Bridges the Busylight for Humans™ web API to work with Apple HomeKit.
TypeScript
3
star
16

Pandas-Talk

A quick introduction to using Pandas.
Jupyter Notebook
3
star
17

twod

A Two-Dimensional Geometry Library for Humans™
Python
2
star
18

hackstar

hackstar - rogue like tutorial walkthrough
Python
2
star
19

JnyJny

2
star
20

busyserve

API Server for Busylight for Humans™
Makefile
2
star
21

bites

Python
2
star
22

PyRcon

Call of Duty 4 remote console Python module
Python
1
star
23

bec-scrape

BEC Page Scraper
Python
1
star
24

git-basics

A git repo for doing git things gitly.
1
star
25

git-intro

Repo to learn git.
Python
1
star
26

pacman

Python Pacman implementation using pygame.
Python
1
star
27

client-template

1
star
28

cards

Python
1
star
29

Pomodoros

A collection of Pomodoro timer implementations.
Python
1
star
30

pdm-github-actions

GitHub Actions demonstration
1
star
31

emacs.d

My Emacs Configuration
Emacs Lisp
1
star
32

ShorinRyu

1
star
33

JnyJny.github.io

My Pelican generated blog @
HTML
1
star
34

StatusThing

JSON Configurable Status Icon for OS X - Inspired by AnyBar
Objective-C
1
star
35

elevator-pitch-faker

Generate a elevator pitch for your next novel or movie.
Python
1
star
36

pkgfile-example

Example of how to use importlib.metadata to locate data files in a package.
Python
1
star