Browse Source

[conf] created first route for configuration #8

Maxime Alves LIRMM@home 3 years ago
parent
commit
6a7223cb7d
1 changed files with 59 additions and 0 deletions
  1. 59
    0
      pyheatpump/conf.py

+ 59
- 0
pyheatpump/conf.py View File

@@ -0,0 +1,59 @@
1
+#!/usr/bin/env python3
2
+import os
3
+from datetime import datetime
4
+from configparser import ConfigParser
5
+from starlette.routing import Route, Router
6
+from pprint import pprint
7
+import uvicorn
8
+
9
+default_config = {
10
+    'heatpump': {
11
+        'serial_port': '/dev/ttyUSB0',
12
+        'baudrate': 19200,
13
+        'mac_address': '00:00:00:00:00:00',
14
+        'ip_address': 'dhcp',
15
+        'read_only': False,
16
+        'database': '/var/run/pyheatpump/pyheatpump.sqlite3'
17
+    },
18
+    'supervisor': {
19
+        'scheme': 'http',
20
+        'host': '127.0.0.1:8000',
21
+        'get_path': '/',
22
+        'post_path': '/',
23
+        'interval': 10000,
24
+        'auth': None,
25
+        'initialization': datetime.now(),
26
+        'heatpump_id': None
27
+    }
28
+}
29
+
30
+CONFIG_FILES=[
31
+    './pyheatpump.ini',
32
+    '/etc/pyheatpump.ini']
33
+
34
+config = ConfigParser(
35
+    defaults=default_config,
36
+    default_section='heatpump')
37
+config.read(filenames=CONFIG_FILES)
38
+
39
+async def get_config(request):
40
+    pprint(request)
41
+
42
+async def set_config(request):
43
+    pass
44
+
45
+async def config_route(request, *args, **kwargs):
46
+    if request['method'] == 'GET':
47
+        return await get_config(request)
48
+    elif request['method'] == 'POST':
49
+        return await set_config(request)
50
+
51
+ROUTES=[Route('/', config_route, methods=['GET', 'POST'])]
52
+
53
+app = Router(routes=ROUTES)
54
+
55
+if __name__ == '__main__':
56
+    uvicorn.run('pyHeatpump:conf.app',
57
+        host='127.0.0.1',
58
+        port=8000)
59
+

Loading…
Cancel
Save