|
13 | 13 | from swag import definitions
|
14 | 14 | from swag import passthrough
|
15 | 15 |
|
16 |
| -from _helpers import parse_bool_value, get_swagger_config, try_to_request |
| 16 | +import _helpers |
17 | 17 |
|
18 | 18 | load_dotenv()
|
19 | 19 |
|
20 | 20 | 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')) |
22 | 23 |
|
23 |
| -while not try_to_request(f'http://{pixoo_host}/get'): |
| 24 | +while not _helpers.try_to_request(f'http://{pixoo_host}/get'): |
24 | 25 | time.sleep(30)
|
25 | 26 |
|
26 | 27 | pixoo = Pixoo(
|
27 | 28 | pixoo_host,
|
28 |
| - int(os.environ.get('PIXOO_SCREEN_SIZE', 64)), |
| 29 | + pixoo_screen, |
29 | 30 | pixoo_debug
|
30 | 31 | )
|
31 | 32 |
|
32 | 33 | app = Flask(__name__)
|
33 |
| -app.config['SWAGGER'] = get_swagger_config() |
| 34 | +app.config['SWAGGER'] = _helpers.get_swagger_config() |
34 | 35 |
|
35 |
| -swagger = Swagger(app) |
| 36 | +swagger = Swagger(app, template=_helpers.get_additional_swagger_template()) |
36 | 37 | definitions.create(swagger)
|
37 | 38 |
|
38 | 39 |
|
39 | 40 | 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)): |
41 | 42 | pixoo.push()
|
42 | 43 |
|
43 | 44 |
|
@@ -76,7 +77,7 @@ def generic_set_number(number):
|
76 | 77 | @swag_from('swag/set/generic_boolean.yml')
|
77 | 78 | def generic_set_boolean(boolean):
|
78 | 79 | if request.path.startswith('/screen/on/'):
|
79 |
| - pixoo.set_screen(parse_bool_value(boolean)) |
| 80 | + pixoo.set_screen(_helpers.parse_bool_value(boolean)) |
80 | 81 |
|
81 | 82 | return 'OK'
|
82 | 83 |
|
@@ -235,7 +236,7 @@ def _send_gif(num, offset, width, speed, data):
|
235 | 236 | def send_gif():
|
236 | 237 | gif = Image.open(request.files['gif'].stream)
|
237 | 238 | 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)) |
239 | 240 |
|
240 | 241 | if gif.is_animated:
|
241 | 242 | _reset_gif()
|
@@ -312,9 +313,33 @@ def passthrough_{list(passthrough_routes.keys()).index(_route)}():
|
312 | 313 | """)
|
313 | 314 |
|
314 | 315 |
|
| 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 | + |
315 | 340 | if __name__ == '__main__':
|
316 | 341 | 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')), |
318 | 343 | host=os.environ.get('PIXOO_REST_HOST', '127.0.0.1'),
|
319 | 344 | port=os.environ.get('PIXOO_REST_PORT', '5000')
|
320 | 345 | )
|
|
0 commit comments