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 831B

123456789101112131415161718192021222324252627282930
  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. from pyheatpump.models import *
  7. def get_variable_values(request):
  8. res = {}
  9. if 'time' not in request.path_params.keys():
  10. h = Heatpump(config.get('heatpump', 'mac_address'), None)
  11. else:
  12. time = datetime.fromisoformat(request.params['time'])
  13. h = Heatpump(config.get('heatpump', 'mac_address'), request.params['time'])
  14. return JSONResponse(h.__dict__())
  15. ROUTES=[
  16. Route('/', get_variable_values, methods=['GET']),
  17. Route('/{time}', get_variable_values, methods=['GET'])
  18. ]
  19. app = Router(routes=ROUTES)
  20. if __name__ == '__main__':
  21. uvicorn.run('pyHeatpump:heatpump.app',
  22. host='127.0.0.1',
  23. port=8000)