Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

variables.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 starlette.responses import PlainTextResponse, JSONResponse
  7. from pprint import pprint
  8. import uvicorn
  9. import json
  10. # pyHeatpump modules
  11. from pyheatpump.db import sql
  12. from pyheatpump.models.variable import Variable
  13. async def get_variables(request):
  14. return JSONResponse(dict([
  15. (key, dict(
  16. [
  17. (add, var.__dict__)
  18. for add, var in var_type.items()
  19. ])
  20. )
  21. for key, var_type in Variable.getall().items()
  22. ]))
  23. async def set_variables(request):
  24. body = json.loads(await request.json())
  25. """
  26. for var_type_label, var_type_values in body.items():
  27. vt = VariableType(label=var_type_label)
  28. for key, val in var_type_values.items():
  29. if key in [ 'start_address', 'end_address' ]:
  30. setattr(vt, key, val)
  31. vt.save()
  32. """
  33. return PlainTextResponse('OK')
  34. async def variables_routes(request, *args, **kwargs):
  35. if request['method'] == 'GET':
  36. return await get_variables(request)
  37. elif request['method'] == 'POST':
  38. return await set_variables(request)
  39. ROUTES=[
  40. Route('/', variables_routes, methods=['GET', 'POST'])
  41. ]
  42. app = Router(routes=ROUTES)
  43. if __name__ == '__main__':
  44. uvicorn.run('pyHeatpump:conf.app',
  45. host='127.0.0.1',
  46. port=8000)