[heatpump] fix the heatpump routes
This commit is contained in:
parent
6133b81b05
commit
47b088d949
1 changed files with 14 additions and 9 deletions
|
|
@ -1,23 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
from modbus.client.serial import rtu
|
||||
from starlette.routing import Router
|
||||
from starlette.routing import Router, Route
|
||||
from starlette.responses import JSONResponse
|
||||
from conf import config
|
||||
from db.db import sql
|
||||
from .config import config
|
||||
from pyheatpump.db import sql
|
||||
|
||||
from pyheatpump.models import *
|
||||
|
||||
def get_variable_values(request):
|
||||
res = {}
|
||||
for var_type_id, var_type in VariableType.getall():
|
||||
for var_type_id, var_type in VariableType.getall().items():
|
||||
res[var_type_id] = {}
|
||||
for address, value in var_type.get_variables_values():
|
||||
res[address] = value
|
||||
for address, value in var_type.get_variables_values().items():
|
||||
res[var_type_id][address] = value
|
||||
|
||||
return JSONResponse(res)
|
||||
|
||||
|
||||
heatpump = [
|
||||
Route('/', get_all_variable_values, methods=['GET'])
|
||||
ROUTES=[
|
||||
Route('/', get_variable_values, methods=['GET'])
|
||||
]
|
||||
|
||||
app = Router(routes=ROUTES)
|
||||
|
||||
if __name__ == '__main__':
|
||||
uvicorn.run('pyHeatpump:heatpump.app',
|
||||
host='127.0.0.1',
|
||||
port=8000)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue