Skip to content

Commit f25eed5

Browse files
committed
v1.3.0 (divoom api calls, dependency upgrade, minor improvements)
1 parent 0010bf9 commit f25eed5

11 files changed

+124
-16
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.3.0 (2023-01-06)
4+
5+
* new: 'divoom' section (query official [API](https://app.divoom-gz.com))
6+
* dependency updates
7+
* other minor improvements
8+
39
## 1.2.0 (2022-10-29)
410

511
* new environment settings `PIXOO_REST_HOST` and `PIXOO_REST_DEBUG` (see [README](README.md))

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ cd pixoo-rest
6565

6666
### Init
6767

68-
Initialize the _pixoo_ submodule:
68+
Update/initialize the _pixoo_ submodule:
6969
```bash
70-
git submodule init
71-
git submodule update
70+
git submodule update --init
7271
```
7372

7473
### Configure

_helpers.py

+37
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import requests
2+
import json
23

34
from datetime import datetime
45
from pathlib import Path
56

7+
divoom_api_url = 'https://app.divoom-gz.com'
8+
69

710
def parse_bool_value(value):
811
if isinstance(value, bool):
@@ -24,6 +27,33 @@ def get_swagger_config():
2427
}
2528

2629

30+
def get_additional_swagger_template():
31+
return {
32+
'tags': [
33+
{
34+
'name': 'draw',
35+
'description': 'draw lines, pixels, rectangles, etc. on your Pixoo'
36+
},
37+
{
38+
'name': 'send',
39+
'description': 'send text, GIFs, etc. to your Pixoo'
40+
},
41+
{
42+
'name': 'set',
43+
'description': 'set brightness, channel, clock, etc. on your Pixoo'
44+
},
45+
{
46+
'name': 'pass-through',
47+
'description': "directly pass commands to your Pixoo's built-in HTTP-API"
48+
},
49+
{
50+
'name': 'divoom',
51+
'description': f'send requests to the external vendor API ({divoom_api_url})'
52+
}
53+
]
54+
}
55+
56+
2757
def try_to_request(url):
2858
try:
2959
print(f'[ {datetime.now().strftime("%Y-%m-%d (%H:%M:%S)")} ] Trying to request "{url}" ... ', end='')
@@ -34,3 +64,10 @@ def try_to_request(url):
3464
except:
3565
print('FAILED.')
3666
return False
67+
68+
69+
def divoom_api_call(endpoint, payload=None):
70+
return requests.post(
71+
f'{divoom_api_url}/{endpoint}',
72+
json.dumps(payload)
73+
)

app.py

+35-10
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,32 @@
1313
from swag import definitions
1414
from swag import passthrough
1515

16-
from _helpers import parse_bool_value, get_swagger_config, try_to_request
16+
import _helpers
1717

1818
load_dotenv()
1919

2020
pixoo_host = os.environ.get('PIXOO_HOST', 'Pixoo64')
21-
pixoo_debug = parse_bool_value(os.environ.get('PIXOO_DEBUG', 'false'))
21+
pixoo_screen = int(os.environ.get('PIXOO_SCREEN_SIZE', 64))
22+
pixoo_debug = _helpers.parse_bool_value(os.environ.get('PIXOO_DEBUG', 'false'))
2223

23-
while not try_to_request(f'http://{pixoo_host}/get'):
24+
while not _helpers.try_to_request(f'http://{pixoo_host}/get'):
2425
time.sleep(30)
2526

2627
pixoo = Pixoo(
2728
pixoo_host,
28-
int(os.environ.get('PIXOO_SCREEN_SIZE', 64)),
29+
pixoo_screen,
2930
pixoo_debug
3031
)
3132

3233
app = Flask(__name__)
33-
app.config['SWAGGER'] = get_swagger_config()
34+
app.config['SWAGGER'] = _helpers.get_swagger_config()
3435

35-
swagger = Swagger(app)
36+
swagger = Swagger(app, template=_helpers.get_additional_swagger_template())
3637
definitions.create(swagger)
3738

3839

3940
def _push_immediately(_request):
40-
if parse_bool_value(_request.form.get('push_immediately', default=True)):
41+
if _helpers.parse_bool_value(_request.form.get('push_immediately', default=True)):
4142
pixoo.push()
4243

4344

@@ -76,7 +77,7 @@ def generic_set_number(number):
7677
@swag_from('swag/set/generic_boolean.yml')
7778
def generic_set_boolean(boolean):
7879
if request.path.startswith('/screen/on/'):
79-
pixoo.set_screen(parse_bool_value(boolean))
80+
pixoo.set_screen(_helpers.parse_bool_value(boolean))
8081

8182
return 'OK'
8283

@@ -235,7 +236,7 @@ def _send_gif(num, offset, width, speed, data):
235236
def send_gif():
236237
gif = Image.open(request.files['gif'].stream)
237238
speed = int(request.form.get('speed'))
238-
skip_first_frame = parse_bool_value(request.form.get('skip_first_frame', default=False))
239+
skip_first_frame = _helpers.parse_bool_value(request.form.get('skip_first_frame', default=False))
239240

240241
if gif.is_animated:
241242
_reset_gif()
@@ -312,9 +313,33 @@ def passthrough_{list(passthrough_routes.keys()).index(_route)}():
312313
""")
313314

314315

316+
@app.route('/divoom/device/lan', methods=['POST'])
317+
@swag_from('swag/divoom/device/return_same_lan_device.yml')
318+
def divoom_return_same_lan_device():
319+
return _helpers.divoom_api_call('Device/ReturnSameLANDevice').json()
320+
321+
322+
@app.route('/divoom/channel/dial/types', methods=['POST'])
323+
@swag_from('swag/divoom/channel/get_dial_type.yml')
324+
def divoom_get_dial_type():
325+
return _helpers.divoom_api_call('Channel/GetDialType').json()
326+
327+
328+
@app.route('/divoom/channel/dial/list', methods=['POST'])
329+
@swag_from('swag/divoom/channel/get_dial_list.yml')
330+
def divoom_get_dial_list():
331+
return _helpers.divoom_api_call(
332+
'Channel/GetDialList',
333+
{
334+
'DialType': request.form.get('dial_type', default='Game'),
335+
'Page': int(request.form.get('page_number', default='1'))
336+
}
337+
).json()
338+
339+
315340
if __name__ == '__main__':
316341
app.run(
317-
debug=parse_bool_value(os.environ.get('PIXOO_REST_DEBUG', 'false')),
342+
debug=_helpers.parse_bool_value(os.environ.get('PIXOO_REST_DEBUG', 'false')),
318343
host=os.environ.get('PIXOO_REST_HOST', '127.0.0.1'),
319344
port=os.environ.get('PIXOO_REST_PORT', '5000')
320345
)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ python-dotenv==0.21.0
22
Flask==2.2.2
33
flasgger==0.9.5
44
requests==2.28.1
5-
Pillow==9.2.0
5+
Pillow==9.4.0
66
gunicorn==20.1.0

swag/divoom/channel/get_dial_list.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
description: Get a list of all 'dial' elements.
2+
3+
parameters:
4+
- name: dial_type
5+
description: The dial type.
6+
in: formData
7+
type: string
8+
default: Game
9+
required: true
10+
- name: page_number
11+
description: 'The page number. (Note: Each page contains 30 items.)'
12+
in: formData
13+
type: integer
14+
minimum: 1
15+
default: 1
16+
required: true
17+
18+
responses:
19+
'200':
20+
description: OK
21+
22+
tags:
23+
- divoom

swag/divoom/channel/get_dial_type.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description: Get a list of all 'dial' types.
2+
3+
responses:
4+
'200':
5+
description: OK
6+
7+
tags:
8+
- divoom
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description: Get a list of all (Pixoo-)devices in your local network.
2+
3+
responses:
4+
'200':
5+
description: OK
6+
7+
tags:
8+
- divoom

swag/send/gif.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
description: "NOTE: The GIF should have max 60 animation frames."
1+
description: 'NOTE: The GIF should have max 60 animation frames.'
2+
23
parameters:
34
- name: gif
45
description: The animated GIF image to display. (Automatically gets resized.)

swag/send/text.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
description: "NOTE: This way of sending text to the device seems unreliable atm. The 'draw text' method is a better alternative."
2+
23
parameters:
34
- name: text
45
description: The text to display.

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.0
1+
1.3.0

0 commit comments

Comments
 (0)