index.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. .. pyOpenAdr documentation master file, created by
  2. sphinx-quickstart on Thu Jul 9 14:09:27 2020.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. ====================
  6. Welcome to pyOpenADR
  7. ====================
  8. Dead-simple Python implementation of an OpenADR client and server.
  9. Key Features
  10. ============
  11. - Fully compliant OpenADR 2.0b implementation for both servers (Virtual Top Node) and clients (Virtual End Node)
  12. - Fully asyncio: you set up the coroutines that can handle certain events, and they get called when needed.
  13. - All messages are represented as simple Python dictionaries. All XML parsing and generation is done for you.
  14. - You only have to deal with your own logic.
  15. Library Installation
  16. ====================
  17. .. code-block:: bash
  18. $ pip install pyopenadr
  19. pyOpenADR is compatible with Python 3.6+
  20. Getting Started
  21. ===============
  22. Client example::
  23. from pyopenadr import OpenADRClient
  24. import asyncio
  25. async def main():
  26. client = OpenADRClient(ven_name="Device001",
  27. vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
  28. client.on_event = handle_event
  29. client.on_report = handle_report
  30. await client.run()
  31. async def handle_event(event):
  32. """
  33. This coroutine will be called
  34. when there is an event to be handled.
  35. """
  36. print("There is an event!")
  37. print(event)
  38. # Do something to determine whether to Opt In or Opt Out
  39. return 'optIn'
  40. async def handle_report(report):
  41. """
  42. This coroutine will be called
  43. when there is a report from the VTN.
  44. """
  45. print("There is a report!")
  46. print(report)
  47. loop = asyncio.get_event_loop()
  48. loop.create_task(main())
  49. loop.run_forever()
  50. This will connect to an OpenADR server (indicated by the vtn_url parameter), handle registration, start polling for events and reports, and will call your coroutines whenever an event or report is created for you.
  51. We have more examples available over at the :ref:`examples` page.
  52. Source Code
  53. ===========
  54. The source code for this project is hosted at GitHub.
  55. Table of Contents
  56. =================
  57. We have prepared some ready-to-run examples for you to get started with OpenADR:
  58. .. toctree::
  59. :name: mastertoc
  60. :maxdepth: 2
  61. openadr
  62. client
  63. server
  64. representations
  65. examples
  66. Representations of OpenADR payloads
  67. ===================================
  68. PyOpenADR uses Python dictionaries and vanilla Python types (like datetime and timedelta) to represent the OpenADR payloads. These pages serve as a reference to these representations.
  69. For example, this XML payload:
  70. .. code-block:: xml
  71. <?xml version="1.0" encoding="utf-8"?>
  72. <oadrPayload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://openadr.org/oadr-2.0b/2012/07" xsi:schemaLocation="http://openadr.org/oadr-2.0b/2012/07 oadr_20b.xsd">
  73. <oadrSignedObject>
  74. <oadrResponse ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
  75. <ei:eiResponse>
  76. <ei:responseCode>200</ei:responseCode>
  77. <ei:responseDescription>OK</ei:responseDescription>
  78. <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads" />
  79. </ei:eiResponse>
  80. <ei:venID>o57b65be83</ei:venID>
  81. </oadrResponse>
  82. </oadrSignedObject>
  83. </oadrPayload>
  84. is represented in pyOpenADR as:
  85. .. code-block:: python3
  86. {'response': {'response_code': 200,
  87. 'response_description': 'OK'},
  88. 'ven_id': 'o57b65be83'}
  89. Read more about the representations at :ref:`representations`
  90. Indices and tables
  91. ==================
  92. * :ref:`genindex`
  93. * :ref:`modindex`
  94. * :ref:`search`