Browse Source

[heatpump] fix the heatpump routes

Maxime Alves LIRMM@home 3 years ago
parent
commit
47b088d949
1 changed files with 14 additions and 9 deletions
  1. 14
    9
      pyheatpump/heatpump.py

+ 14
- 9
pyheatpump/heatpump.py View File

@@ -1,23 +1,28 @@
1 1
 #!/usr/bin/env python3
2
-from modbus.client.serial import rtu
3
-from starlette.routing import Router
2
+from starlette.routing import Router, Route
4 3
 from starlette.responses import JSONResponse
5
-from conf import config
6
-from db.db import sql
4
+from .config import config
5
+from pyheatpump.db import sql
7 6
 
8 7
 from pyheatpump.models import *
9 8
 
10 9
 def get_variable_values(request):
11 10
     res = {}
12
-    for var_type_id, var_type in VariableType.getall():
11
+    for var_type_id, var_type in VariableType.getall().items():
13 12
         res[var_type_id] = {}
14
-        for address, value in var_type.get_variables_values():
15
-            res[address] = value
13
+        for address, value in var_type.get_variables_values().items():
14
+            res[var_type_id][address] = value
16 15
 
17 16
     return JSONResponse(res)
18 17
 
19 18
 
20
-heatpump = [
21
-    Route('/', get_all_variable_values, methods=['GET'])
19
+ROUTES=[
20
+    Route('/', get_variable_values, methods=['GET'])
22 21
 ]
23 22
 
23
+app = Router(routes=ROUTES)
24
+
25
+if __name__ == '__main__':
26
+    uvicorn.run('pyHeatpump:heatpump.app',
27
+        host='127.0.0.1',
28
+        port=8000)

Loading…
Cancel
Save