123456789101112131415161718192021222324252627282930 |
- #!/usr/bin/env python3
- from datetime import datetime
- from starlette.routing import Router, Route
- from starlette.responses import JSONResponse
- from .config import config
-
- from pyheatpump.models import *
-
- def get_variable_values(request):
- res = {}
- if 'time' not in request.path_params.keys():
- h = Heatpump(config.get('heatpump', 'mac_address'), None)
- else:
- time = datetime.fromisoformat(request.params['time'])
- h = Heatpump(config.get('heatpump', 'mac_address'), request.params['time'])
-
- return JSONResponse(h.__dict__())
-
-
- ROUTES=[
- Route('/', get_variable_values, methods=['GET']),
- Route('/{time}', get_variable_values, methods=['GET'])
- ]
-
- app = Router(routes=ROUTES)
-
- if __name__ == '__main__':
- uvicorn.run('pyHeatpump:heatpump.app',
- host='127.0.0.1',
- port=8000)
|