objects.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 dataclasses import dataclass
  13. from typing import List
  14. from datetime import datetime, timezone, timedelta
  15. class objdict(dict):
  16. def __getattr__(self, name):
  17. if name in self:
  18. return self[name]
  19. else:
  20. raise AttributeError("No such attribute: " + name)
  21. def __setattr__(self, name, value):
  22. self[name] = value
  23. def __delattr__(self, name):
  24. if name in self:
  25. del self[name]
  26. else:
  27. raise AttributeError("No such attribute: " + name)
  28. @dataclass
  29. class AggregatedPNode(objdict):
  30. node: str
  31. @dataclass
  32. class EndDeviceAsset(objdict):
  33. mrid: str
  34. @dataclass
  35. class MeterAsset(objdict):
  36. mrid: str
  37. @dataclass
  38. class PNode(objdict):
  39. node: str
  40. @dataclass
  41. class FeatureCollection(objdict):
  42. id: str
  43. location: dict
  44. @dataclass
  45. class ServiceArea(objdict):
  46. feature_collection: FeatureCollection
  47. @dataclass
  48. class ServiceDeliveryPoint(objdict):
  49. node: str
  50. @dataclass
  51. class ServiceLocation(objdict):
  52. node: str
  53. @dataclass
  54. class TransportInterface(objdict):
  55. point_of_receipt: str
  56. point_of_delivery: str
  57. @dataclass
  58. class Target(objdict):
  59. aggregated_p_node: AggregatedPNode = None
  60. end_device_asset: EndDeviceAsset = None
  61. meter_asset: MeterAsset = None
  62. p_node: PNode = None
  63. service_area: ServiceArea = None
  64. service_delivery_point: ServiceDeliveryPoint = None
  65. service_location: ServiceLocation = None
  66. transport_interface: TransportInterface = None
  67. group_id: str = None
  68. group_name: str = None
  69. resource_id: str = None
  70. ven_id: str = None
  71. party_id: str = None
  72. @dataclass
  73. class EventDescriptor(objdict):
  74. event_id: int
  75. modification_number: int
  76. market_context: str
  77. event_status: str
  78. created_date_time: datetime = None
  79. modification_date_time: datetime = None
  80. priority: int = 0
  81. test_event: bool = False
  82. vtn_comment: str = None
  83. def __post_init__(self):
  84. if self.modification_date_time is None:
  85. self.modification_date_time = datetime.now(timezone.utc)
  86. if self.created_date_time is None:
  87. self.created_date_time = datetime.now(timezone.utc)
  88. if self.modification_number is None:
  89. self.modification_number = 0
  90. if not isinstance(self.test_event, bool):
  91. self.test_event = False
  92. @dataclass
  93. class ActivePeriod(objdict):
  94. dtstart: datetime
  95. duration: timedelta
  96. tolerance: dict = None
  97. notification: dict = None
  98. ramp_up: dict = None
  99. recovery: dict = None
  100. @dataclass
  101. class Interval(objdict):
  102. dtstart: datetime
  103. duration: timedelta
  104. signal_payload: float
  105. uid: int = None
  106. @dataclass
  107. class EventSignal(objdict):
  108. intervals: List[Interval]
  109. target: Target
  110. signal_name: str
  111. signal_type: str
  112. signal_id: str
  113. current_value: float
  114. @dataclass
  115. class Event(objdict):
  116. event_descriptor: EventDescriptor
  117. active_period: ActivePeriod
  118. event_signals: EventSignal
  119. target: Target
  120. @dataclass
  121. class Response(objdict):
  122. response_code: int
  123. response_description: str
  124. request_id: str