Browse Source

[routes][heatpump] use the Heatpump model

Maxime Alves LIRMM@home 4 years ago
parent
commit
5c42ff849d
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      pyheatpump/heatpump.py

+ 9
- 6
pyheatpump/heatpump.py View File

@@ -1,4 +1,5 @@
1 1
 #!/usr/bin/env python3
2
+from datetime import datetime
2 3
 from starlette.routing import Router, Route
3 4
 from starlette.responses import JSONResponse
4 5
 from .config import config
@@ -8,16 +9,18 @@ from pyheatpump.models import *
8 9
 
9 10
 def get_variable_values(request):
10 11
     res = {}
11
-    for var_type_id, var_type in VariableType.getall().items():
12
-        res[var_type_id] = {}
13
-        for address, value in var_type.get_variables_values().items():
14
-            res[var_type_id][address] = value
12
+    if 'time' not in request.path_params.keys():
13
+        h = Heatpump(config.get('heatpump', 'mac_address', None))
14
+    else:
15
+        time = datetime.fromisoformat(request.params['time'])
16
+        h = Heatpump(config.get('heatpump', 'mac_address', request.params['time']))
15 17
 
16
-    return JSONResponse(res)
18
+    return JSONResponse(h.__dict__())
17 19
 
18 20
 
19 21
 ROUTES=[
20
-    Route('/', get_variable_values, methods=['GET'])
22
+    Route('/', get_variable_values, methods=['GET']),
23
+    Route('/{time}', get_variable_values, methods=['GET'])
21 24
 ]
22 25
 
23 26
 app = Router(routes=ROUTES)

Loading…
Cancel
Save