examples.rst 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .. _examples:
  2. Examples
  3. ========
  4. This page contains examples for pyOpenADR:
  5. .. _client_example:
  6. Client Example
  7. ==============
  8. This example sets up a minimal OpenADR Client (Virtual End Node):
  9. .. code-block:: python3
  10. from pyopenadr import OpenADRClient
  11. import asyncio
  12. async def main():
  13. client = OpenADRClient(ven_name="Device001", vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
  14. client.on_event = handle_event
  15. client.on_report = handle_report
  16. await client.run()
  17. async def handle_event(event):
  18. """
  19. This coroutine will be called
  20. whenever there is an event to be handled.
  21. """
  22. print("There is an event!")
  23. print(event)
  24. return 'optIn'
  25. async def handle_report(report):
  26. """
  27. This coroutine will be called
  28. whenever there is a report from the VTN.
  29. """
  30. print("There is a report!")
  31. print(report)
  32. loop = asyncio.get_event_loop()
  33. loop.create_task(main())
  34. loop.run_forever()
  35. .. _server_example:
  36. Server Example
  37. ==============
  38. .. _server_with_gui_example:
  39. Server with GUI Example
  40. =======================