registration_service.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from . import api, handler, VTNService
  2. from datetime import timedelta
  3. from asyncio import iscoroutine
  4. # ╔══════════════════════════════════════════════════════════════════════════╗
  5. # ║ REGISTRATION SERVICE ║
  6. # ╚══════════════════════════════════════════════════════════════════════════╝
  7. # ┌──────────────────────────────────────────────────────────────────────────┐
  8. # │ The VEN can explore some information about the VTN: │
  9. # │ │
  10. # │ ┌────┐ ┌────┐ │
  11. # │ │VEN │ │VTN │ │
  12. # │ └─┬──┘ └─┬──┘ │
  13. # │ │─────────────────────oadrQueryRegistration()────────────────────▶│ │
  14. # │ │ │ │
  15. # │ │◀ ─ ─ ─ ─ ─ ─ oadrCreatedPartyRegistration(VTN Info)─ ─ ─ ─ ─ ─ ─│ │
  16. # │ │ │ │
  17. # │ │
  18. # └──────────────────────────────────────────────────────────────────────────┘
  19. # ┌──────────────────────────────────────────────────────────────────────────┐
  20. # │ The VEN can then go on and register with the VTN │
  21. # │ │
  22. # │ ┌────┐ ┌────┐ │
  23. # │ │VEN │ │VTN │ │
  24. # │ └─┬──┘ └─┬──┘ │
  25. # │ │───────────────oadrCreatePartyRegistration(VEN Info)────────────▶│ │
  26. # │ │ │ │
  27. # │ │◀ ─ ─ oadrCreatedPartyRegistration(VTN Info, registrationID)─ ─ ─│ │
  28. # │ │ │ │
  29. # │ │
  30. # └──────────────────────────────────────────────────────────────────────────┘
  31. # ┌──────────────────────────────────────────────────────────────────────────┐
  32. # │ The VEN can also choose to cancel the registration │
  33. # │ │
  34. # │ ┌────┐ ┌────┐ │
  35. # │ │VEN │ │VTN │ │
  36. # │ └─┬──┘ └─┬──┘ │
  37. # │ │──────────oadrCancelPartyRegistration(registrationID)───────────▶│ │
  38. # │ │ │ │
  39. # │ │◀ ─ ─ ─ ─ ─ ─ ─ ─oadrCanceledPartyRegistration()─ ─ ─ ─ ─ ─ ─ ─ ─│ │
  40. # │ │ │ │
  41. # │ │
  42. # └──────────────────────────────────────────────────────────────────────────┘
  43. @api.route('/OpenADR2/Simple/2.0b/EiRegisterParty')
  44. class RegistrationService(VTNService):
  45. @handler('oadrQueryRegistration')
  46. async def query_registration(self, payload):
  47. """
  48. Return the profiles we support.
  49. """
  50. request_id = payload['request_id']
  51. response_type = "oadrCreatedPartyRegistration"
  52. response_payload = {"request_id": request_id,
  53. "vtn_id": "elaadvtn",
  54. "profiles": [{"profile_name": "2.0a",
  55. "transports": [{"transport_name": "simpleHttp"},
  56. {"transport_name": "xmpp"}]},
  57. {"profile_name": "2.0b",
  58. "transports": [{"transport_name": "simpleHttp"},
  59. {"transport_name": "xmpp"}]}],
  60. "requested_oadr_poll_freq": timedelta(seconds=10)}
  61. return response_type, response_payload
  62. @handler('oadrCreatePartyRegistration')
  63. async def create_party_registration(self, payload):
  64. """
  65. Handle the registration of a VEN party.
  66. """
  67. result = self.on_create_party_registration(payload)
  68. if iscoroutine(result):
  69. result = await result
  70. return result
  71. @handler('oadrCancelPartyRegistration')
  72. async def cancel_party_registration(self, payload):
  73. """
  74. Cancel the registration of a party.
  75. """
  76. result = self.on_cancel_party_registration(payload)
  77. if iscoroutine(result):
  78. result = await result
  79. return result