فهرست منبع

Added UpdateReport and UpdatedReport messages

Stan Janssen 5 سال پیش
والد
کامیت
61680d83ba

+ 2 - 72
pyopenadr/templates/oadrRegisterReport.xml

@@ -6,78 +6,8 @@
 {% for report in reports %}
       <oadrReport>
         <ei:eiReportID>{{ report.report_id }}</ei:eiReportID>
-    {% for rd in report.report_descriptions %}
-        <oadrReportDescription>
-          <ei:rID>{{ rd.r_id }}</ei:rID>
-          {% if rd.report_subject %}
-          <ei:reportSubject>
-            {% set target = rd.report_subject %}
-            {% if target.emix_interfaces %}
-                {% for emix_interface in target.emix_interface %}
-                    {% include 'parts/emixInterface.xml' %}
-                {% endfor %}
-            {% endif %}
-
-            {% if target.group_id %}
-                <ei:groupID>{{ target.group_id }}</ei:groupID>
-            {% endif %}
-
-            {% if target.group_name %}
-                <ei:groupName>{{ target.group_name }}</ei:groupName>
-            {% endif %}
-
-            {% if target.resource_id %}
-                <ei:resourceID>{{ target.resource_id }}</ei:resourceID>
-            {% endif %}
-
-            {% if target.ven_id %}
-                <ei:venID>{{ target.ven_id }}</ei:venID>
-            {% endif %}
-
-            {% if target.party_id %}
-                <ei:partyID>{{ target.party_id }}</ei:partyID>
-            {% endif %}
-          </ei:reportSubject>
-          {% endif %}
-          {% if rd.report_data_source %}
-          <ei:reportDataSource>
-              {% set target = rd.report_data_source %}
-              {% if target.emix_interfaces %}
-                  {% for emix_interface in target.emix_interface %}
-                      {% include 'parts/emixInterface.xml' %}
-                  {% endfor %}
-              {% endif %}
-
-              {% if target.group_id %}
-                  <ei:groupID>{{ target.group_id }}</ei:groupID>
-              {% endif %}
-
-              {% if target.group_name %}
-                  <ei:groupName>{{ target.group_name }}</ei:groupName>
-              {% endif %}
-
-              {% if target.resource_id %}
-                  <ei:resourceID>{{ target.resource_id }}</ei:resourceID>
-              {% endif %}
-
-              {% if target.ven_id %}
-                  <ei:venID>{{ target.ven_id }}</ei:venID>
-              {% endif %}
-
-              {% if target.party_id %}
-                  <ei:partyID>{{ target.party_id }}</ei:partyID>
-              {% endif %}
-          </ei:reportDataSource>
-          {% endif %}
-          <ei:reportType>{{ rd.report_type }}</ei:reportType>
-          <ei:readingType>{{ rd.reading_type }}</ei:readingType>
-          <marketContext xmlns="http://docs.oasis-open.org/ns/emix/2011/06">{{ rd.market_context }}</marketContext>
-          <oadrSamplingRate>
-            <oadrMinPeriod>{{ rd.sampling_rate.min_period|timedeltaformat }}</oadrMinPeriod>
-            <oadrMaxPeriod>{{ rd.sampling_rate.max_period|timedeltaformat }}</oadrMaxPeriod>
-            <oadrOnChange>{{ rd.sampling_rate.on_change|booleanformat }}</oadrOnChange>
-          </oadrSamplingRate>
-        </oadrReportDescription>
+    {% for report_description in report.report_descriptions %}
+        {% include 'parts/oadrReportDescription.xml' %}
     {% endfor %}
         <ei:reportRequestID>{{ report.report_request_id }}</ei:reportRequestID>
         <ei:reportSpecifierID>{{ report.report_specifier_id }}</ei:reportSpecifierID>

+ 29 - 0
pyopenadr/templates/oadrUpdateReport.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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" xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads" xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xsi:schemaLocation="http://openadr.org/oadr-2.0b/2012/07 oadr_20b.xsd">
+  <oadrSignedObject>
+    <oadrUpdateReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
+      <pyld:requestID>{{ request_id }}</pyld:requestID>
+      {% if reports %}
+      {% for report in reports %}
+      <oadrReport>
+        <ei:eiReportID>{{ report.report_id }}</ei:eiReportID>
+        {% if report.report_descriptions %}
+        {% for report_description in report.report_descriptions %}
+        {% include 'parts/oadrReportDescription.xml' %}
+        <ei:reportRequestID>{{ report.report_request_id }}</ei:reportRequestID>
+        <ei:reportSpecifierID>{{ report.report_specifier_id }}</ei:reportSpecifierID>
+        {% if report.report_name %}
+        <ei:reportName>{{ report.report_name }}</ei:reportName>
+        {% endif %}
+        <ei:createdDateTime>{{ report.created_date_time|datetimeformat }}</ei:createdDateTime>
+        {% endfor %}
+        {% endif %}
+      </oadrReport>
+      {% endfor %}
+      {% endif %}
+      {% if ven_id %}
+      <ei:venID>{{ ven_id }}</ei:venID>
+      {% endif %}
+    </oadrUpdateReport>
+  </oadrSignedObject>
+</oadrPayload>

+ 31 - 0
pyopenadr/templates/oadrUpdatedReport.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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" xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads" xsi:schemaLocation="http://openadr.org/oadr-2.0b/2012/07 oadr_20b.xsd">
+  <oadrSignedObject>
+    <oadrUpdatedReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
+      <ei:eiResponse>
+        <ei:responseCode>{{ response.response_code }}</ei:responseCode>
+        <ei:responseDescription>{{ response.response_description }}</ei:responseDescription>
+        {% if response.request_id %}
+        <pyld:requestID>{{ response.request_id }}</pyld:requestID>
+        {% else %}
+        <pyld:requestID />
+        {% endif %}
+      </ei:eiResponse>
+      {% if cancel_report %}
+      <oadrCancelReport>
+        <pyld:requestID>{{ cancel_report.request_id }}</pyld:requestID>
+        {% for report_request_id in cancel_report.report_request_id %}
+        <ei:reportRequestID>{{ report_request_id }}</ei:reportRequestID>
+        {% endfor %}
+        <pyld:reportToFollow>{{ cancel_report.report_to_follow|booleanformat }}</pyld:reportToFollow>
+        {% if cancel_report.ven_id %}
+        <ei:venID>{{ cancel_report.ven_id }}</ei:venID>
+        {% endif %}
+      </oadrCancelReport>
+      {% endif %}
+      {% if ven_id %}
+      <ei:venID>{{ ven_id }}</ei:venID>
+      {% endif %}
+    </oadrUpdatedReport>
+  </oadrSignedObject>
+</oadrPayload>

+ 100 - 0
pyopenadr/templates/parts/oadrReportDescription.xml

@@ -0,0 +1,100 @@
+<oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06">
+  <ei:rID>{{ report_description.r_id }}</ei:rID>
+  {% if report_description.report_subjects %}
+  <ei:reportSubject>
+  {% for target in report_description.report_subjects %}
+    {% if target.emix_interfaces %}
+        {% for emix_interface in target.emix_interface %}
+            {% include 'parts/emixInterface.xml' %}
+        {% endfor %}
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_subjects %}
+    {% if target.group_id %}
+        <ei:groupID>{{ target.group_id }}</ei:groupID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_subjects %}
+    {% if target.group_name %}
+        <ei:groupName>{{ target.group_name }}</ei:groupName>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_subjects %}
+    {% if target.resource_id %}
+        <ei:resourceID>{{ target.resource_id }}</ei:resourceID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_subjects %}
+    {% if target.ven_id %}
+        <ei:venID>{{ target.ven_id }}</ei:venID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_subjects %}
+    {% if target.party_id %}
+        <ei:partyID>{{ target.party_id }}</ei:partyID>
+    {% endif %}
+  {% endfor %}
+  </ei:reportSubject>
+  {% endif %}
+  {% if report_description.report_data_sources %}
+  <ei:reportDataSource>
+  {% for target in report_description.report_data_sources %}
+    {% if target.emix_interfaces %}
+        {% for emix_interface in target.emix_interface %}
+            {% include 'parts/emixInterface.xml' %}
+        {% endfor %}
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_data_sources %}
+    {% if target.group_id %}
+        <ei:groupID>{{ target.group_id }}</ei:groupID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_data_sources %}
+    {% if target.group_name %}
+        <ei:groupName>{{ target.group_name }}</ei:groupName>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_data_sources %}
+    {% if target.resource_id %}
+        <ei:resourceID>{{ target.resource_id }}</ei:resourceID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_data_sources %}
+    {% if target.ven_id %}
+        <ei:venID>{{ target.ven_id }}</ei:venID>
+    {% endif %}
+  {% endfor %}
+
+  {% for target in report_description.report_data_sources %}
+    {% if target.party_id %}
+        <ei:partyID>{{ target.party_id }}</ei:partyID>
+    {% endif %}
+  {% endfor %}
+  </ei:reportDataSource>
+  {% endif %}
+  <ei:reportType>{{ report_description.report_type }}</ei:reportType>
+  <!--           {% if report_description.item_base %}
+  <emix:itemBase>{{ report_description.item_base }}</emix:itemBase>
+  {% endif %} -->
+  <ei:readingType>{{ report_description.reading_type }}</ei:readingType>
+  {% if report_description.market_context %}
+  <emix:marketContext>{{ report_description.market_context }}</emix:marketContext>
+  {% endif %}
+  {% if report_description.sampling_rate %}
+  <oadrSamplingRate>
+    <oadrMinPeriod>{{ report_description.sampling_rate.min_period|timedeltaformat }}</oadrMinPeriod>
+    <oadrMaxPeriod>{{ report_description.sampling_rate.max_period|timedeltaformat }}</oadrMaxPeriod>
+    <oadrOnChange>{{ report_description.sampling_rate.on_change|booleanformat }}</oadrOnChange>
+  </oadrSamplingRate>
+  {% endif %}
+</oadrReportDescription>

+ 8 - 19
pyopenadr/utils.py

@@ -131,16 +131,16 @@ def normalize_dict(ordered_dict):
             key = key[5:]
 
         # Group all targets as a list of dicts under the key "target"
-        if key == "target":
-            targets = d.pop("target")
+        if key in ("target", "report_subject", "report_data_source"):
+            targets = d.pop(key)
             new_targets = []
             for ikey in targets:
                 if isinstance(targets[ikey], list):
                     new_targets.extend([{ikey: value} for value in targets[ikey]])
                 else:
                     new_targets.append({ikey: targets[ikey]})
-            d["targets"] = new_targets
-            key = "targets"
+            d[key + "s"] = new_targets
+            key = key + "s"
 
         # Group all reports as a list of dicts under the key "pending_reports"
         if key == "pending_reports":
@@ -167,23 +167,12 @@ def normalize_dict(ordered_dict):
         elif key in ("request_event", "created_event") and isinstance(d[key], dict):
             d = d[key]
 
-        elif key == 'report_request':
+        # Plurarize some lists
+        elif key in ('report_request', 'report_description', 'report'):
             if isinstance(d[key], list):
-                d['report_requests'] = d.pop('report_request')
+                d[key + 's'] = d.pop(key)
             else:
-                d['report_requests'] = [d.pop('report_request')]
-
-        elif key == 'report_description':
-            if isinstance(d[key], list):
-                d['report_descriptions'] = d.pop('report_description')
-            else:
-                d['report_descriptions'] = [d.pop('report_description')]
-
-        elif key == 'report':
-            if isinstance(d[key], list):
-                d['reports'] = d.pop('report')
-            else:
-                d['reports'] = [d.pop('report')]
+                d[key + 's'] = [d.pop(key)]
 
         # Promote the contents of the Qualified Event ID
         elif key == "qualified_event_id" and isinstance(d['qualified_event_id'], dict):

+ 1 - 1
setup.py

@@ -4,7 +4,7 @@ with open("README.md", "r") as fh:
     long_description = fh.read()
 
 setup(name="pyopenadr",
-      version="0.2.2",
+      version="0.2.4",
       description="Python library for dealing with OpenADR",
       long_description=long_description,
       long_description_content_type="text/markdown",