-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp-fast.py
73 lines (57 loc) · 1.88 KB
/
app-fast.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
71
72
import io
import os
import pathlib
from fastapi import FastAPI, Request
from fastapi.responses import Response
from pyhon import Hon
from pyhon.appliance import HonAppliance
from pyhon.commands import HonCommand
app = FastAPI()
g = {}
async def async_initialize():
hon = await Hon(
email=os.getenv("USERNAME"),
password=os.getenv("PASSWORD"),
mobile_id=os.getenv("MOBILE_ID", 'loxone'),
session=None,
test_data_path=None,
refresh_token='refresh_token',
).create()
return hon
async def run(command, device, args):
acs = g["hon"].appliances
for ac in acs:
if ac.nick_name == device:
start_command: HonCommand = ac.commands[command]
for name, setting in start_command.parameters.items():
# name = settings.windSpeed
print(args)
if args is not None and args.get(name) is not None:
print(args.get(name))
setting.value = args.get(name)
await ac.commands[command].send()
@app.on_event("startup")
async def startup_event():
g["hon"] = await async_initialize()
print("done")
@app.get("/status")
def get_image(device: str):
extracted_values = {}
for acc in g["hon"].appliances:
if acc.nick_name == device:
deviceLocal: HonAppliance = acc
for key, honValue in deviceLocal.attributes['parameters'].items():
extracted_values[key] = str(honValue)
print(extracted_values)
return {"result": extracted_values}
@app.get("/settings")
async def settings(device: str, request: Request):
await run('settings', device, request.query_params)
return {"result": 'done'}
@app.get('/devices')
def devices_http(): # put
acs = g["hon"].appliances
current = list()
for ac in acs:
current.append(ac.nick_name)
return current