Browse Source

[app] create the main API routes and mount the routers

Maxime Alves LIRMM@home 3 years ago
parent
commit
a77428547b
2 changed files with 57 additions and 4 deletions
  1. 18
    4
      pyheatpump/app.py
  2. 39
    0
      pyheatpump/index.html

+ 18
- 4
pyheatpump/app.py View File

@@ -1,10 +1,24 @@
1 1
 #!/usr/bin/env python3
2 2
 
3
-from starlette.routing import Router
4
-from starlette.mounting import Mount
3
+from starlette.routing import Router, Mount, Route
4
+from starlette.responses import HTMLResponse
5
+from starlette.exceptions import HTTPException
5 6
 
6
-app = Router(routes=[
7
+from pyheatpump.config import config
8
+from pyheatpump.heatpump import app as heatpump
9
+from pyheatpump.variable_types import app as types
10
+from pyheatpump.variables import app as variables
11
+from pyheatpump.variable_values import app as values
12
+
13
+async def index(request):
14
+    with open('index.html') as html:
15
+        return HTMLResponse(html.read())
16
+    raise HTTPException(404)
17
+
18
+application = Router(routes=[
7 19
     Route('/', index),
8
-    Mount('/heatpump', heatpump),
9 20
     Mount('/config', config),
21
+    Mount('/heatpump', heatpump),
22
+    Mount('/variables', types),
23
+    Mount('/values', values)
10 24
 ])

+ 39
- 0
pyheatpump/index.html View File

@@ -0,0 +1,39 @@
1
+<!DOCTYPE html>
2
+<html>
3
+	<head>
4
+		<meta charset="utf-8">
5
+		<title>pyHeatpump API index</title>
6
+	</head>
7
+	<body>
8
+		<h1>pyHeatpump API</h1>
9
+		<p>
10
+			Welcome to the pyHeatpump API.
11
+		</p>
12
+		<hr />
13
+		<h2>Routes</h2>
14
+		<p>
15
+			List of the GET routes.
16
+
17
+			<i>All of these routes return JSON-formatted dictionaries.</i>
18
+		</p>
19
+
20
+		<h3>Heatpump</h3>
21
+		<ul>
22
+			<li><a href="/heatpump">/heatpump</a> Get all variable values of a heatpump</li>
23
+		</ul>
24
+		<h3>Variable types</h3>
25
+		<ul>
26
+			<li><a href="/types">/types</a> Get all variable types</li>
27
+		</ul>
28
+		<h3>Variables</h3>
29
+		<ul>
30
+			<li><a href="/variables">/variables</a> Get all variables</li>
31
+		</ul>
32
+		<h3>Variables values</h3>
33
+		<ul>
34
+			<li><a href="/values">/values</a> Get all variables (not implemented)</li>
35
+			<li><a href="/values/A/1">/values/{TYPE}/{ADDRESS}</a> Get current variable value</li>
36
+			<li><a href="/values/A/1/2020-08-02T13:21:42">/values/{TYPE}/{ADDRESS}/{TIMESTAMP}</a> Get variable value at specified time (in iso format, e.g. : 2020-08-02T13:21:42)</li>
37
+		</ul>
38
+	</body>
39
+</html>

Loading…
Cancel
Save