From 47b088d949f55d02db727b7dbfabb71a71a4d0fd Mon Sep 17 00:00:00 2001 From: "Maxime Alves LIRMM@home" Date: Sun, 2 Aug 2020 14:58:27 +0200 Subject: [PATCH] [heatpump] fix the heatpump routes --- pyheatpump/heatpump.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pyheatpump/heatpump.py b/pyheatpump/heatpump.py index 1085bd5..8ae8b15 100644 --- a/pyheatpump/heatpump.py +++ b/pyheatpump/heatpump.py @@ -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)