working speed increase and decrease endpoints
This commit is contained in:
parent
eb4a70a7b1
commit
1c8980f3a5
|
@ -75,51 +75,11 @@ class Headwind:
|
|||
try:
|
||||
async with self.fanClient as client:
|
||||
await client.write_gatt_char(CHARACTERISTIC, value)
|
||||
# print("flag")
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
async def writeIncreaseSpeed(self):
|
||||
try:
|
||||
async with self.fanClient as client:
|
||||
currentSpeed = await client.read_gatt_char(CHARACTERISTIC)[2]
|
||||
newSpeed = 0
|
||||
if currentSpeed < 25:
|
||||
newSpeed = 25
|
||||
elif currentSpeed < 50:
|
||||
newSpeed = 50
|
||||
elif currentSpeed < 75:
|
||||
newSpeed = 75
|
||||
elif currentSpeed < 100:
|
||||
newSpeed = 100
|
||||
value = [0x2, newSpeed]
|
||||
await client.write_gatt_char(CHARACTERISTIC, value)
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
async def writeDecreaseSpeed(self):
|
||||
try:
|
||||
async with self.fanClient as client:
|
||||
currentSpeed = await client.read_gatt_char(CHARACTERISTIC)[2]
|
||||
newSpeed = 0
|
||||
if currentSpeed == 100:
|
||||
newSpeed = 75
|
||||
elif currentSpeed >= 75:
|
||||
newSpeed = 50
|
||||
elif currentSpeed >= 50:
|
||||
newSpeed = 25
|
||||
elif currentSpeed > 25:
|
||||
newSpeed = 25
|
||||
elif currentSpeed <= 25:
|
||||
return True
|
||||
value = [0x2, newSpeed]
|
||||
await client.write_gatt_char(CHARACTERISTIC, value)
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
return False
|
||||
|
||||
async def writeOff(self):
|
||||
try:
|
||||
|
|
|
@ -22,6 +22,44 @@ async def setSpeed(speed):
|
|||
return f"Failed to set headwind speed to {speed}", 503
|
||||
return f"Setting headwind speed to {speed}", 200
|
||||
|
||||
@app.route("/speed/increase", methods=["POST"])
|
||||
async def setIncreaseSpeed():
|
||||
print("increase speed")
|
||||
currentSpeed = await fan.readSpeed()
|
||||
newSpeed = 0
|
||||
if currentSpeed < 25:
|
||||
newSpeed = 25
|
||||
elif currentSpeed < 50:
|
||||
newSpeed = 50
|
||||
elif currentSpeed < 75:
|
||||
newSpeed = 75
|
||||
elif currentSpeed < 100:
|
||||
newSpeed = 100
|
||||
fan_status = await fan.writeSpeed(newSpeed)
|
||||
if not fan_status:
|
||||
return f"Failed to increase speed by 25%", 503
|
||||
return f"Increased speed by 25%", 200
|
||||
|
||||
@app.route("/speed/decrease", methods=["POST"])
|
||||
async def setDecreaseSpeed():
|
||||
print("decrease speed")
|
||||
currentSpeed = await fan.readSpeed()
|
||||
newSpeed = 0
|
||||
if currentSpeed == 100:
|
||||
newSpeed = 75
|
||||
elif currentSpeed >= 75:
|
||||
newSpeed = 50
|
||||
elif currentSpeed >= 50:
|
||||
newSpeed = 25
|
||||
elif currentSpeed > 25:
|
||||
newSpeed = 25
|
||||
elif currentSpeed <= 25:
|
||||
newSpeed = 1
|
||||
fan_status = await fan.writeSpeed(newSpeed)
|
||||
if not fan_status:
|
||||
return f"Failed to decrease speed by 25%", 503
|
||||
return f"Decreased speed by 25%", 200
|
||||
|
||||
@app.route("/speed", methods=["GET"])
|
||||
async def getSpeed():
|
||||
speed = await fan.readSpeed()
|
||||
|
|
Loading…
Reference in New Issue