1
2

3 Commits 2e2b3286e1 ... 11344f2b4d

Autor SHA1 Mensagem Data
  Stan Janssen 11344f2b4d Clean up accessibility in messaging.py 4 anos atrás
  Stan Janssen cc7a7c6807 Tweak preflight documentation and accessibility 4 anos atrás
  Stan Janssen f8dfcf6118 Updated examples 4 anos atrás
5 arquivos alterados com 14 adições e 29 exclusões
  1. 0 9
      docs/examples.rst
  2. 0 9
      docs/index.rst
  3. 1 1
      docs/server.rst
  4. 2 3
      openleadr/messaging.py
  5. 11 7
      openleadr/preflight.py

+ 0 - 9
docs/examples.rst

@@ -21,7 +21,6 @@ This example sets up a minimal OpenADR Client (Virtual End Node):
     async def main():
         client = OpenADRClient(ven_name="Device001", vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
         client.on_event = handle_event
-        client.on_report = handle_report
         await client.run()
 
     async def handle_event(event):
@@ -33,14 +32,6 @@ This example sets up a minimal OpenADR Client (Virtual End Node):
         print(event)
         return 'optIn'
 
-    async def handle_report(report):
-        """
-        This coroutine will be called
-        whenever there is a report from the VTN.
-        """
-        print("There is a report!")
-        print(report)
-
     loop = asyncio.get_event_loop()
     loop.create_task(main())
     loop.run_forever()

+ 0 - 9
docs/index.rst

@@ -51,7 +51,6 @@ Client example::
         client = OpenADRClient(ven_name="Device001",
                                vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
         client.on_event = handle_event
-        client.on_report = handle_report
         await client.run()
 
     async def handle_event(event):
@@ -64,14 +63,6 @@ Client example::
         # Do something to determine whether to Opt In or Opt Out
         return 'optIn'
 
-    async def handle_report(report):
-        """
-        This coroutine will be called
-        when there is a report from the VTN.
-        """
-        print("There is a report!")
-        print(report)
-
     loop = asyncio.get_event_loop()
     loop.create_task(main())
     loop.run_forever()

+ 1 - 1
docs/server.rst

@@ -166,7 +166,7 @@ Example implementation:
                            cert='/path/to/cert.pem',
                            key='/path/to/private/key.pem',
                            passphrase='mypassphrase',
-                           validation_handler=fingerprint_lookup)
+                           fingerprint_lookup=fingerprint_lookup)
 
 The VEN's fingerprint should be obtained from the VEN outside of OpenADR.
 

+ 2 - 3
openleadr/messaging.py

@@ -36,7 +36,7 @@ def parse_message(data, fingerprint=None, fingerprint_lookup=None):
     message_dict = xmltodict.parse(data, process_namespaces=True, namespaces=NAMESPACES)
     message_type, message_payload = message_dict['oadrPayload']['oadrSignedObject'].popitem()
     if 'ven_id' in message_payload:
-        validate_and_authenticate_message(data, message_dict, fingerprint, fingerprint_lookup)
+        _validate_and_authenticate_message(data, message_dict, fingerprint, fingerprint_lookup)
     return message_type, normalize_dict(message_payload)
 
 def create_message(message_type, cert=None, key=None, passphrase=None, **message_payload):
@@ -72,7 +72,7 @@ def create_message(message_type, cert=None, key=None, passphrase=None, **message
                           signed_object=signed_object)
     return msg
 
-def validate_and_authenticate_message(data, message_dict, fingerprint=None, fingerprint_lookup=None):
+def _validate_and_authenticate_message(data, message_dict, fingerprint=None, fingerprint_lookup=None):
     if not fingerprint and not fingerprint_lookup:
         return
     tree = etree.fromstring(ensure_bytes(data))
@@ -125,7 +125,6 @@ def _update_nonce_cache(timestamp, nonce):
 REPLAY_PROTECT_MAX_TIME_DELTA = timedelta(seconds=5)
 NONCE_CACHE = set()
 
-
 # Settings for jinja2
 TEMPLATES = Environment(loader=PackageLoader('openleadr', 'templates'))
 TEMPLATES.filters['datetimeformat'] = datetimeformat

+ 11 - 7
openleadr/preflight.py

@@ -14,19 +14,23 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""
-Tests message contents before sending them. It will correct benign errors and
-warn you about them. Uncorrectable errors will raise an Exception.
-"""
 from datetime import datetime, timedelta, timezone
 import warnings
 
 def preflight_message(message_type, message_payload):
-    if f'preflight_{message_type}' in globals():
-        globals()[f'preflight_{message_type}'](message_payload)
+    """
+    Tests message contents before sending them. It will correct benign errors
+    and warn you about them. Uncorrectable errors will raise an Exception. It
+    changes the message_payload dict in-place.
+
+    :param message_type string: The type of message you are sending
+    :param message_payload dict: The contents of the message
+    """
+    if f'_preflight_{message_type}' in globals():
+        globals()[f'_preflight_{message_type}'](message_payload)
     return message_type, message_payload
 
-def preflight_oadrDistributeEvent(message_payload):
+def _preflight_oadrDistributeEvent(message_payload):
     if 'parse_duration' not in globals():
         from .utils import parse_duration
     # Check that the total event_duration matches the sum of the interval durations (rule 8)