-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.py
70 lines (45 loc) · 1.29 KB
/
webhook.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
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
62
63
64
65
66
67
68
69
70
import logging
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from pydantic import BaseModel
from globals import read_config, read_presents
from api import execute_routine
async def receive_call(present):
present = PRESENTS[present]
try:
return execute_routine(present, "webhook")
except KeyError:
return "That present does not exist. Check /presents/ for options."
DEVICE_IPS, COLOR_VALUES, SCHEDULES, ROUTINES = read_config()
PRESENTS = read_presents()
class Present(BaseModel):
present: str
app = FastAPI(
title="Kasa-Control Webhook Server",
description="A control server and repository of configuration information",
version="1.2.1",
)
@app.get("/")
async def redirect():
return RedirectResponse("/docs/")
@app.post("/")
async def root(present: Present):
return await receive_call(dict(present)["present"])
@app.get("/p/")
async def parse_query(present: str):
return await receive_call(present)
@app.get("/colors/")
async def root():
return COLOR_VALUES
@app.get("/devices/")
async def root():
return DEVICE_IPS
@app.get("/presents/")
async def root():
return PRESENTS
@app.get("/routines/")
async def root():
return ROUTINES
@app.get("/schedules/")
async def root():
return SCHEDULES