12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/env python3
- import os
- from datetime import datetime
- from configparser import ConfigParser
- from starlette.routing import Route, Router
- from starlette.responses import PlainTextResponse, JSONResponse
- from pprint import pprint
- import uvicorn
- import json
-
- # pyHeatpump modules
- from pyheatpump.db import sql
- from pyheatpump.models.variable import Variable
-
-
- async def get_variables(request):
- return JSONResponse(dict([
- (key, dict(
- [
- (add, var.__dict__)
- for add, var in var_type.items()
- ])
- )
- for key, var_type in Variable.getall().items()
- ]))
-
-
- async def set_variables(request):
-
- body = json.loads(await request.json())
-
- """
- for var_type_label, var_type_values in body.items():
- vt = VariableType(label=var_type_label)
- for key, val in var_type_values.items():
- if key in [ 'start_address', 'end_address' ]:
- setattr(vt, key, val)
-
- vt.save()
-
- """
- return PlainTextResponse('OK')
-
-
- async def variables_routes(request, *args, **kwargs):
- if request['method'] == 'GET':
- return await get_variables(request)
- elif request['method'] == 'POST':
- return await set_variables(request)
-
-
- ROUTES=[
- Route('/', variables_routes, methods=['GET', 'POST'])
- ]
-
- app = Router(routes=ROUTES)
-
- if __name__ == '__main__':
- uvicorn.run('pyHeatpump:conf.app',
- host='127.0.0.1',
- port=8000)
|