12345678910111213141516171819202122232425262728293031 |
- #!/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.db import sql
-
- 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)
|