index.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 OpenLEADR
  7. ====================
  8. Super-convenient 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. Take a :ref:`feature_tour`!
  16. Project Status
  17. ==============
  18. The current version is |release|.
  19. This project is still a work in progress. Please see our :ref:`roadmap` for information.
  20. License
  21. =======
  22. This project is licensed under the Apache 2.0 license.
  23. Library Installation
  24. ====================
  25. .. code-block:: bash
  26. $ pip install openleadr
  27. OpenLEADR is compatible with Python 3.6+
  28. Getting Started
  29. ===============
  30. Client example::
  31. from openleadr import OpenADRClient
  32. import asyncio
  33. async def main():
  34. client = OpenADRClient(ven_name="Device001",
  35. vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
  36. client.on_event = handle_event
  37. client.on_report = handle_report
  38. await client.run()
  39. async def handle_event(event):
  40. """
  41. This coroutine will be called
  42. when there is an event to be handled.
  43. """
  44. print("There is an event!")
  45. print(event)
  46. # Do something to determine whether to Opt In or Opt Out
  47. return 'optIn'
  48. async def handle_report(report):
  49. """
  50. This coroutine will be called
  51. when there is a report from the VTN.
  52. """
  53. print("There is a report!")
  54. print(report)
  55. loop = asyncio.get_event_loop()
  56. loop.create_task(main())
  57. loop.run_forever()
  58. 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.
  59. We have more examples available over at the :ref:`examples` page.
  60. Table of Contents
  61. =================
  62. .. toctree::
  63. :name: mastertoc
  64. :maxdepth: 2
  65. features
  66. openadr
  67. client
  68. server
  69. examples
  70. roadmap
  71. representations
  72. message_signing
  73. API Reference <api/modules>
  74. Representations of OpenADR payloads
  75. ===================================
  76. 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.
  77. For example, this XML payload:
  78. .. code-block:: xml
  79. <?xml version="1.0" encoding="utf-8"?>
  80. <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">
  81. <oadrSignedObject>
  82. <oadrResponse ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
  83. <ei:eiResponse>
  84. <ei:responseCode>200</ei:responseCode>
  85. <ei:responseDescription>OK</ei:responseDescription>
  86. <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads" />
  87. </ei:eiResponse>
  88. <ei:venID>o57b65be83</ei:venID>
  89. </oadrResponse>
  90. </oadrSignedObject>
  91. </oadrPayload>
  92. is represented in OpenLEADR as:
  93. .. code-block:: python3
  94. {'response': {'response_code': 200,
  95. 'response_description': 'OK'},
  96. 'ven_id': 'o57b65be83'}
  97. Read more about the representations at :ref:`representations`
  98. Indices and tables
  99. ==================
  100. * :ref:`genindex`
  101. * :ref:`modindex`
  102. * :ref:`search`