http_handler.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from MicroWebSrv.microWebSrv import MicroWebSrv
  2. from module import mod
  3. @MicroWebSrv.route('/status')
  4. def _httpHandlerStatusGet(httpClient, httpResponse) :
  5. content = mod.get_dat()
  6. print("content:", content)
  7. httpResponse.WriteResponseOk( headers = None,
  8. contentType = "text/html",
  9. contentCharset = "UTF-8",
  10. content = content )
  11. @MicroWebSrv.route('/heat/<index>')
  12. def _httpHandlerHeat(httpClient, httpResponse, args={}) :
  13. content = ''
  14. if 'index' in args:
  15. if args['index'] == 'on':
  16. mod.heat_on()
  17. content = str(mod.heat.status)
  18. elif args['index'] == 'off':
  19. mod.heat_off()
  20. content = str(mod.heat.status)
  21. elif args['index'] == 'status':
  22. content = str(mod.heat.status)
  23. print('_httpHandlerHeat:', content)
  24. httpResponse.WriteResponseOk( headers = None,
  25. contentType = "text/html",
  26. contentCharset = "UTF-8",
  27. content = content )
  28. # ----------------------------------------------------------------------------
  29. routeHandlers = [
  30. ( "/status", "GET", _httpHandlerStatusGet ),
  31. ( '/heat/<index>', 'GET', _httpHandlerHeat ),
  32. ]