-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdecaf.py
More file actions
61 lines (46 loc) · 1.64 KB
/
decaf.py
File metadata and controls
61 lines (46 loc) · 1.64 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, request, abort
from flask_restful import Resource, Api
import models
app = Flask(__name__)
api = Api(app)
# query brew settings by user id
class BrewSettings(Resource):
def get(self, userId):
return {"brewSettings": models.BrewSettings.get(userId)}
# get info about coffee by coffeeTypeID
class CoffeeInfo(Resource):
def get(self, coffeeTypeId):
return {"coffeeInfo": models.CoffeeInfo.get(coffeeTypeId)}
# get coffee info by using the barcode scanner
class BarCode(Resource):
def post(self):
return {"barcodeScanner": models.BarcodeScanner.get()}
class RelayController(Resource):
def post(self, hardware):
req = request.get_json(force=True)
if req is None:
return abort(400)
try:
return {
"relayControl": models.RelayControl.get(
req["pin"],
req["channel"],
req["timeOn"],
req["repeat"],
req["repeatDelay"],
hardware,
)
}
except KeyError:
return abort(400)
class PinInfo(Resource):
def get(self, hardwareType):
return {"pinMappings": models.PinMappings.get(hardwareType)}
api.add_resource(BrewSettings, "/brewSettings/<int:userId>")
api.add_resource(CoffeeInfo, "/coffeeInfo/<int:coffeeTypeId>")
api.add_resource(BarCode, "/barcodeScanner")
api.add_resource(PinInfo, "/pinInfo/<hardwareType>")
api.add_resource(RelayController, "/relayControl/<hardware>")
if __name__ == "__main__":
# remove in production
app.run(host="0.0.0.0", debug=True)