registration_service.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # SPDX-License-Identifier: Apache-2.0
  2. # Copyright 2020 Contributors to OpenLEADR
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. from . import service, handler, VTNService
  13. from datetime import timedelta
  14. from asyncio import iscoroutine
  15. # ╔══════════════════════════════════════════════════════════════════════════╗
  16. # ║ REGISTRATION SERVICE ║
  17. # ╚══════════════════════════════════════════════════════════════════════════╝
  18. # ┌──────────────────────────────────────────────────────────────────────────┐
  19. # │ The VEN can explore some information about the VTN: │
  20. # │ │
  21. # │ ┌────┐ ┌────┐ │
  22. # │ │VEN │ │VTN │ │
  23. # │ └─┬──┘ └─┬──┘ │
  24. # │ │─────────────────────oadrQueryRegistration()────────────────────▶│ │
  25. # │ │ │ │
  26. # │ │◀ ─ ─ ─ ─ ─ ─ oadrCreatedPartyRegistration(VTN Info)─ ─ ─ ─ ─ ─ ─│ │
  27. # │ │ │ │
  28. # │ │
  29. # └──────────────────────────────────────────────────────────────────────────┘
  30. # ┌──────────────────────────────────────────────────────────────────────────┐
  31. # │ The VEN can then go on and register with the VTN │
  32. # │ │
  33. # │ ┌────┐ ┌────┐ │
  34. # │ │VEN │ │VTN │ │
  35. # │ └─┬──┘ └─┬──┘ │
  36. # │ │───────────────oadrCreatePartyRegistration(VEN Info)────────────▶│ │
  37. # │ │ │ │
  38. # │ │◀ ─ ─ oadrCreatedPartyRegistration(VTN Info, registrationID)─ ─ ─│ │
  39. # │ │ │ │
  40. # │ │
  41. # └──────────────────────────────────────────────────────────────────────────┘
  42. # ┌──────────────────────────────────────────────────────────────────────────┐
  43. # │ The VEN can also choose to cancel the registration │
  44. # │ │
  45. # │ ┌────┐ ┌────┐ │
  46. # │ │VEN │ │VTN │ │
  47. # │ └─┬──┘ └─┬──┘ │
  48. # │ │──────────oadrCancelPartyRegistration(registrationID)───────────▶│ │
  49. # │ │ │ │
  50. # │ │◀ ─ ─ ─ ─ ─ ─ ─ ─oadrCanceledPartyRegistration()─ ─ ─ ─ ─ ─ ─ ─ ─│ │
  51. # │ │ │ │
  52. # │ │
  53. # └──────────────────────────────────────────────────────────────────────────┘
  54. @service('EiRegisterParty')
  55. class RegistrationService(VTNService):
  56. @handler('oadrQueryRegistration')
  57. async def query_registration(self, payload):
  58. """
  59. Return the profiles we support.
  60. """
  61. if hasattr(self, 'on_query_registration'):
  62. result = self.on_query_registration(payload)
  63. if iscoroutine(result):
  64. result = await result
  65. return result
  66. # If you don't provide a default handler, just give out the info
  67. response_payload = {'response': {'response_code': 200, 'response_description': 'OK', 'request_id': payload['request_id']},
  68. 'request_id': payload['request_id'],
  69. 'vtn_id': self.vtn_id,
  70. 'profiles': [{'profile_name': '2.0b',
  71. 'transports': {'transport_name': 'simpleHttp'}}],
  72. 'requested_oadr_poll_freq': timedelta(seconds=5)}
  73. return 'oadrCreatedPartyRegistration', response_payload
  74. @handler('oadrCreatePartyRegistration')
  75. async def create_party_registration(self, payload):
  76. """
  77. Handle the registration of a VEN party.
  78. """
  79. result = self.on_create_party_registration(payload)
  80. if iscoroutine(result):
  81. result = await result
  82. response_type, response_payload = result
  83. response_payload['response'] = {'response_code': 200,
  84. 'response_description': 'OK',
  85. 'request_id': payload['request_id']}
  86. response_payload['vtn_id'] = self.vtn_id
  87. return response_type, response_payload
  88. @handler('oadrCancelPartyRegistration')
  89. async def cancel_party_registration(self, payload):
  90. """
  91. Cancel the registration of a party.
  92. """
  93. result = self.on_cancel_party_registration(payload)
  94. if iscoroutine(result):
  95. result = await result
  96. return result