Explorar o código

Make sure there is a valid value for oadrResponseRequired

Stan Janssen %!s(int64=4) %!d(string=hai) anos
pai
achega
82c2b92cf1
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      openleadr/preflight.py

+ 8 - 0
openleadr/preflight.py

@@ -61,3 +61,11 @@ def preflight_oadrDistributeEvent(message_payload):
                 if event_signal['signal_name'] == "SIMPLE" and event['event_descriptor']['event_status'] != "ACTIVE":
                     warnings.warn("The current_value for a SIMPLE event that is not yet active must be 0. This will be corrected.")
                     event_signal['current_value'] = 0
+
+    # Check that there is a valid oadrResponseRequired value for each Event
+    for event in message_payload['events']:
+        if 'response_required' not in event:
+            event['response_required'] = 'always'
+        elif event['response_required'] not in ('never', 'always'):
+            warnings.warn(f"The response_required property in an Event should be 'never' or 'always', not {event['response_required']}. Changing to 'always'.")
+            event['response_required'] = 'always'