-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
36 lines (28 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import json
import logging
from atmosphuer import AtmosphuerBridge
from flask import Flask, render_template, request, jsonify
from flask_navigation import Navigation
app = Flask(__name__)
nav = Navigation(app)
bridge = AtmosphuerBridge()
@app.route('/')
def index():
logging.debug("/index")
return render_template('index.html', lights=bridge.get_lights(), scenes=bridge.get_scenes(), sounds=bridge.get_sounds())
@app.route('/togglelight', methods=["POST"])
def togglelight():
logging.debug("/togglelight")
response = request.get_json()
bridge.bridge.set_light(int(response['id']), 'on', response['on'], CONFIG['transition'])
return jsonify(success=True)
@app.route('/applyscene', methods=["POST"])
def applyscene():
logging.debug("/applyscene")
for s in bridge.bridge.scenes:
if s.name == request.get_json()['name']:
bridge.bridge.activate_scene(0, s.scene_id) # use group_id 0 to activate all lights of the scene
return jsonify(success=True)
if __name__ == '__main__':
app.run(host='0.0.0.0')