2023-02-23 11:07:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from flask import Flask
|
|
|
|
from headwind import Headwind as Headwind
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_prefixed_env()
|
|
|
|
|
2023-11-10 22:30:00 +00:00
|
|
|
@app.route("/on", methods=["POST"])
|
2023-02-23 11:07:26 +00:00
|
|
|
async def on():
|
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
2023-11-10 22:30:00 +00:00
|
|
|
fan_status = await fan.writeOn()
|
2023-02-23 11:07:26 +00:00
|
|
|
if not fan_status:
|
2023-11-10 22:30:00 +00:00
|
|
|
return "Failed to turn headwind on", 503
|
|
|
|
return "Turning headwind on", 200
|
2023-02-23 11:07:26 +00:00
|
|
|
|
2023-11-10 22:30:00 +00:00
|
|
|
@app.route("/sleep", methods=["POST"])
|
2023-02-23 11:07:26 +00:00
|
|
|
async def sleep():
|
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
2023-11-10 22:30:00 +00:00
|
|
|
fan_status = await fan.writeSleep()
|
2023-02-23 11:07:26 +00:00
|
|
|
if not fan_status:
|
2023-11-10 22:30:00 +00:00
|
|
|
return "Failed to put headwind to sleep", 503
|
|
|
|
return "Putting headwind to sleep", 200
|
2023-02-23 11:07:26 +00:00
|
|
|
|
2023-11-10 22:30:00 +00:00
|
|
|
@app.route("/speed/<int:speed>", methods=["POST"])
|
2023-02-23 11:07:26 +00:00
|
|
|
async def speed(speed):
|
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
2023-11-10 22:30:00 +00:00
|
|
|
fan_status = await fan.writeSpeed(speed)
|
2023-02-23 11:07:26 +00:00
|
|
|
if not fan_status:
|
2023-11-10 22:30:00 +00:00
|
|
|
return f"Failed to set headwind speed to {speed}", 503
|
|
|
|
return f"Setting headwind speed to {speed}", 200
|
2023-02-23 11:07:26 +00:00
|
|
|
|
2023-11-10 22:30:00 +00:00
|
|
|
@app.route("/speed", methods=["GET"])
|
|
|
|
async def getSpeed():
|
2023-02-23 11:07:26 +00:00
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
2023-11-10 22:30:00 +00:00
|
|
|
speed = await fan.readSpeed()
|
|
|
|
return f"{speed}", 200
|
|
|
|
|
|
|
|
@app.route("/hr", methods=["POST"])
|
|
|
|
async def writeHr():
|
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
|
|
|
fan_status = await fan.writeHr()
|
2023-02-23 11:07:26 +00:00
|
|
|
if not fan_status:
|
2023-11-10 22:30:00 +00:00
|
|
|
return "Failed to set headwind to HR mode", 503
|
|
|
|
return "Setting headwind to HR mode", 200
|
2023-02-23 11:07:26 +00:00
|
|
|
|
2023-11-10 22:30:00 +00:00
|
|
|
@app.route("/off", methods=["POST"])
|
|
|
|
async def writeOff():
|
2023-02-23 11:07:26 +00:00
|
|
|
fan = Headwind(app, app.config["ADDRESS"])
|
|
|
|
fan_status = await fan.off()
|
|
|
|
if not fan_status:
|
2023-11-10 22:30:00 +00:00
|
|
|
return "Failed to turn headwind off", 503
|
|
|
|
return "Turning headwind off", 200
|