Skip to content

Commit 523955a

Browse files
committed
Finish Nostromo-energy Opt service VEN client
1 parent 0e09490 commit 523955a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

openleadr/client.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ async def create_party_reregistration(self, registration_id=None):
483483
Take the neccessary steps to re-register this client with the server.
484484
"""
485485

486+
if registration_id is None:
487+
registration_id = self.registration_id
486488
await self.create_party_registration(ven_id=self.ven_id, registration_id=registration_id)
487489

488490
if not self.registration_id:
@@ -632,10 +634,15 @@ async def create_opt(self, opt_type, opt_reason, targets, vavailability=None, ev
632634
service = 'EiOpt'
633635
message = self._create_message('oadrCreateOpt', **payload)
634636
response_type, response_payload = await self._perform_request(service, message)
637+
logger.info(response_type, response_payload)
635638

636639
if 'opt_id' in response_payload:
637640
# VTN acknowledged the opt message
641+
logging.info(f"VTN acknowledged the opt message with opt_id {response_payload['opt_id']}")
638642
return response_payload['opt_id']
643+
else:
644+
logging.error(f"VTN did not acknowledge the opt message")
645+
return False
639646

640647
# TODO: what to do if the VTN sends an error or does not acknowledge the opt?
641648

@@ -662,11 +669,16 @@ async def cancel_opt(self, opt_id):
662669
service = 'EiOpt'
663670
message = self._create_message('oadrCancelOpt', **payload)
664671
response_type, response_payload = await self._perform_request(service, message)
672+
logger.info(response_type, response_payload)
665673

666674
if 'opt_id' in response_payload:
667675
# VTN acknowledged the opt cancelation
676+
logging.info(f"VTN acknowledged the opt cancelation with opt_id {response_payload['opt_id']}")
668677
self.opts.remove(opt)
669678
return True
679+
else:
680+
logging.error(f"VTN did not acknowledge the opt cancelation")
681+
return False
670682

671683
###########################################################################
672684
# #
@@ -799,13 +811,12 @@ async def create_report(self, response_payload):
799811
'granularity': granularity,
800812
'job': job})
801813
else:
802-
job = None
803814
self.report_requests.append({'report_request_id': report_request_id,
804815
'report_specifier_id': report_specifier_id,
805816
'report_back_duration': report_back_duration,
806817
'r_ids': requested_r_ids,
807818
'granularity': granularity,
808-
'job': job})
819+
'job': None})
809820

810821
async def report_callback():
811822
await self.update_report(report_request_id)
@@ -823,7 +834,8 @@ async def report_callback():
823834
message = self._create_message(message_type,
824835
response={'response_code': response_code,
825836
'response_description': 'OK' if response_code == 200 else 'ERROR',
826-
'request_id': response_payload['request_id']},
837+
'request_id': response_payload['request_id'] if 'request_id' in response_payload else\
838+
response_payload['response']['request_id']},
827839
ven_id=self.ven_id,
828840
**message_payload)
829841
await self._perform_request(service, message)
@@ -1257,9 +1269,9 @@ async def _poll(self):
12571269
return
12581270

12591271
elif response_type == 'oadrRequestReregistration':
1260-
logger.info("The VTN required us to re-register. Calling the registration procedure.")
1272+
logger.info("The VTN required us to re-register. Calling the re-registration procedure.")
12611273
await self.send_response(service='EiRegisterParty')
1262-
await self.create_party_registration()
1274+
await self.create_party_reregistration()
12631275

12641276
elif response_type == 'oadrDistributeEvent':
12651277
if 'events' in response_payload and len(response_payload['events']) > 0:

openleadr/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class ReportRequest:
313313

314314
@dataclass
315315
class VavailabilityComponent:
316-
dstart: datetime
316+
dtstart: datetime
317317
duration: timedelta
318318

319319

openleadr/templates/oadrCreateOpt.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
<ei:modificationNumber>{{ modification_number }}</ei:modificationNumber>
3232
</ei:qualifiedEventID>
3333
{% endif %}
34+
{% if targets is defined and targets is not none and targets|length > 0 %}
3435
{% for target in targets %}
3536
{% include 'parts/eiTarget.xml' %}
3637
{% endfor %}
38+
{% else %}
39+
<ei:eiTarget/>
40+
{% endif %}
3741
{% if signal_target_mrid is defined and signal_target_mrid is not none %}
3842
<oadr:oadrDeviceClass>
3943
<power:endDeviceAsset>

0 commit comments

Comments
 (0)