Skip to content

Commit b29b56c

Browse files
committed
Add change-brightness endpoint
1 parent a3947b0 commit b29b56c

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44

55
Just an API for turning a unicorn hat on and off. Default color is white and default brightness is 1
66

7-
# Installing dependencies
7+
## Installing dependencies
88

99
```bash
1010
sudo pip3 install -r requirements.txt
1111
```
1212

13-
# Running
13+
## Running
1414

15-
## Locally
15+
### Locally
1616

1717
```bash
18-
sudo uvicorn main:app --host=0.0.0.0
18+
sudo venv/bin/uvicorn main:app --host=0.0.0.0
1919
```
2020

21-
## As a demon
21+
### As a demon
2222

2323
```bash
2424
sudo gunicorn -b 0.0.0.0:8000 -w 3 -k uvicorn.workers.UvicornH11Worker main:app --daemon
2525
```
2626

27-
## With systemd
27+
### With systemd
2828

2929
Move content of `unicorn-lamp-api.service` file to `/etc/systemd/system/unicorn-lamp-api.service`
3030

@@ -33,8 +33,5 @@ sudo systemctl start unicorn-lamp-api
3333
sudo systemctl enable unicorn-lamp-api
3434
```
3535

36-
TODO: Try/catch importing unicornhat
3736
TODO: Add authentication
38-
TODO: Add capacity to change colors
39-
TODO: Add capacity to change brightness
4037
TODO: Research about supervisord

lamps/lamp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ def off():
5050
docstring
5151
"""
5252
unicorn.off()
53+
54+
@staticmethod
55+
def brightness(b):
56+
"""
57+
docstring
58+
"""
59+
unicorn.brightness(b)

main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def change_color(r: str, g:str, b:str, response: Response):
4646

4747
return {"status": "on"}
4848

49+
@app.get("/change-brightness", status_code=200)
50+
def change_brightness(b:str, response: Response):
51+
brightness = float(b)
52+
lamp.brightness(brightness)
53+
lamp.show()
54+
55+
return {"status": "on"}
56+
4957
# @app.get("/toggle", status_code=200)
5058
# def toggle(response: Response):
5159
# status = None

0 commit comments

Comments
 (0)