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.

heatpump.py 842B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. from datetime import datetime
  3. from starlette.routing import Router, Route
  4. from starlette.responses import JSONResponse
  5. from .config import config
  6. import uvicorn
  7. from pyheatpump.models import *
  8. def get_variable_values(request):
  9. res = {}
  10. if 'time' not in request.path_params.keys():
  11. h = Heatpump(config.get('heatpump', 'mac_address'), None)
  12. else:
  13. time = datetime.fromisoformat(request.params['time'])
  14. h = Heatpump(config.get('heatpump', 'mac_address'), request.params['time'])
  15. return JSONResponse(h.packet)
  16. ROUTES=[
  17. Route('/', get_variable_values, methods=['GET']),
  18. Route('/{time}', get_variable_values, methods=['GET'])
  19. ]
  20. app = Router(routes=ROUTES)
  21. if __name__ == '__main__':
  22. uvicorn.run('pyHeatpump:heatpump.app',
  23. host='127.0.0.1',
  24. port=8000)