Skip to content

Commit 9d24ca1

Browse files
committed
cancel opt function
1 parent f93f2d2 commit 9d24ca1

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

openleadr/client.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ async def create_opt(self, opt_type, opt_reason, targets, vavailability=None, ev
625625
targets=targets
626626
)
627627
self.opts.append(opt)
628-
# TODO: this is set to grow and grow and grow. Maybe add some method to remove expired opts
629628

630629
# Send opt
631630
request_id = request_id or utils.generate_id()
@@ -646,11 +645,33 @@ async def create_opt(self, opt_type, opt_reason, targets, vavailability=None, ev
646645
# TODO: what to do if the VTN sends an error or does not acknowledge the opt?
647646
...
648647

649-
async def cancel_opt(self):
648+
async def cancel_opt(self, opt_id):
650649
"""
651650
Tell the VTN to cancel a previously acknowledged opt message
651+
652+
:param str opt_id: The id of the opt to cancel
652653
"""
653-
...
654+
655+
# Check if this report opt exists
656+
report = utils.find_by(
657+
self.reports, 'opt_id', opt_id)
658+
if not report:
659+
logger.error(f"A non-existant opt with opt_id "
660+
f"{opt_id} was requested for cancellation.")
661+
return False
662+
663+
payload = {
664+
'opt_id': opt_id,
665+
'ven_id': self.ven_id
666+
}
667+
668+
service = 'EiOpt'
669+
message = self._create_message('oadrCancelOpt', **payload)
670+
response_type, response_payload = await self._perform_request(service, message)
671+
672+
if 'opt_id' in response_payload:
673+
# VTN acknowledged the opt cancelation
674+
return True
654675

655676
###########################################################################
656677
# #

0 commit comments

Comments
 (0)