Add compatibility for python 3.9

This commit is contained in:
2023-02-28 23:17:25 +01:00
parent e78fd7df13
commit 0045cccf2c
4 changed files with 106 additions and 266 deletions

View File

@@ -1,7 +1,7 @@
from fastapi import FastAPI, Path, HTTPException, status
from projectorpi.cli import ProjectorSerial, ExtronSerial
from pydantic import BaseModel
from requests import Response
from time import sleep
app = FastAPI()
@@ -15,7 +15,7 @@ class Response(BaseModel):
@app.post("/sleep", response_model=Response)
async def sleep() -> Response:
async def sleep_post() -> Response:
extron.sleep()
projector.power_off()
@@ -26,7 +26,7 @@ async def sleep() -> Response:
async def select(
input_id: int = Path(title="The input to select", ge=1, le=4),
) -> Response:
if extron.check_sleep():
if extron.is_sleeping():
extron.wake()
sleep(1)
extron.change_input(input_id)
@@ -39,24 +39,22 @@ async def select(
@app.post("/control/{direction}", response_model=Response)
async def control(direction: str) -> Response:
match direction:
case "vol_up":
extron.volume_up()
case "vol_down":
extron.volume_down()
case "up":
extron.menu_up()
case "right":
extron.menu_right()
case "down":
extron.menu_down()
case "left":
extron.menu_left()
case "enter":
extron.menu_enter()
case "menu":
extron.menu_toggle()
case _:
raise HTTPException(status.HTTP_400_BAD_REQUEST, "invalid control")
directions = {
"vol_up": extron.volume_up,
"vol_down": extron.volume_down,
"up": extron.menu_up,
"right": extron.menu_right,
"down": extron.menu_down,
"left": extron.menu_left,
"enter": extron.menu_enter,
"menu": extron.menu_toggle,
}
runnable = directions.get(direction)
if not runnable:
raise HTTPException(status.HTTP_400_BAD_REQUEST, "invalid control")
runnable()
return Response(status="ok")