Prechádzať zdrojové kódy

Added conformance test 002, force EventSignal interval uids to be consecutive

Stan Janssen 4 rokov pred
rodič
commit
b26969a024

+ 2 - 2
pyopenadr/templates/parts/eiEventSignal.xml

@@ -6,7 +6,7 @@
                 <duration>{{ interval.duration|timedeltaformat }}</duration>
             </duration>
             <uid xmlns="urn:ietf:params:xml:ns:icalendar-2.0">
-                <text>{{ interval.uid }}</text>
+                <text>{{ loop.index0 }}</text>
             </uid>
             <ei:signalPayload>
                 <ei:payloadFloat>
@@ -19,7 +19,7 @@
     <ei:signalName>{{ signal.signal_name }}</ei:signalName>
     <ei:signalType>{{ signal.signal_type }}</ei:signalType>
     <ei:signalID>{{ signal.signal_id }}</ei:signalID>
-    {% if signal.current_value is not none %}
+    {% if signal.current_value and signal.current_value is not none %}
     <ei:currentValue>
         <ei:payloadFloat>
             <ei:value>{{ signal.current_value }}</ei:value>

+ 4 - 1
pyopenadr/utils.py

@@ -227,7 +227,10 @@ def normalize_dict(ordered_dict):
 
         # Promote the 'text' item
         elif isinstance(d[key], dict) and "text" in d[key] and len(d[key]) == 1:
-            d[key] = d[key]["text"]
+            if key == 'uid':
+                d[key] = int(d[key]["text"])
+            else:
+                d[key] = d[key]["text"]
 
         # Promote a 'date-time' item
         elif isinstance(d[key], dict) and "date_time" in d[key] and len(d[key]) == 1:

+ 65 - 0
test/conformance/test_conformance_002.py

@@ -0,0 +1,65 @@
+import pytest
+
+from pyopenadr import OpenADRClient, OpenADRServer, enums
+from pyopenadr.utils import generate_id, create_message, parse_message
+from datetime import datetime, timezone, timedelta
+
+from pprint import pprint
+
+
+@pytest.mark.asyncio
+async def test_conformance_002():
+    """
+    The uid element is REQUIRED for each eiEventSignal interval. Within a sin-
+    gle oadrDistributeEvent eiEventSignal, uid MUST be expressed as an inter-
+    val number with a base of 0 and an increment of 1 for each subsequent in-
+    terval.
+    """
+    event_id = generate_id()
+    event = {'event_descriptor':
+                {'event_id': event_id,
+                 'modification_number': 0,
+                 'modification_date': datetime.now(),
+                 'priority': 0,
+                 'market_context': 'MarketContext001',
+                 'created_date_time': datetime.now(),
+                 'event_status': enums.EVENT_STATUS.FAR,
+                 'test_event': False,
+                 'vtn_comment': 'No Comment'},
+            'active_period':
+                {'dtstart': datetime.now(),
+                 'duration': timedelta(minutes=5)},
+            'event_signals':
+                [{'intervals': [{'duration': timedelta(minutes=10),
+                                 'signal_payload': 100},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 200},
+                                {'duration': timedelta(minutes=10),
+                                 'signal_payload': 300}],
+                  'signal_name': enums.SIGNAL_NAME.SIMPLE,
+                  'signal_type': enums.SIGNAL_TYPE.DELTA,
+                  'signal_id': generate_id()
+                }]
+        }
+
+    # Create a message with this event
+    msg = create_message('oadrDistributeEvent',
+                         response={'response_code': 200,
+                                   'response_description': 'OK',
+                                   'request_id': generate_id()},
+                         request_id=generate_id(),
+                         vtn_id=generate_id(),
+                         events=[event])
+
+    # Parse the message
+    parsed_type, parsed_msg = parse_message(msg)
+    assert parsed_type == 'oadrDistributeEvent'
+    intervals = parsed_msg['events'][0]['event_signals'][0]['intervals']
+
+    # Verify that the interval uid's are numbered consecutively and starting at 0
+    assert intervals[0]['uid'] == 0
+    assert intervals[0]['signal_payload'] == 100
+    assert intervals[1]['uid'] == 1
+    assert intervals[1]['signal_payload'] == 200
+    assert intervals[2]['uid'] == 2
+    assert intervals[2]['signal_payload'] == 300