enums.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. """
  13. A collection of useful enumerations that you can use to construct or
  14. interpret OpenADR messages. Can also be useful during testing.
  15. """
  16. from openleadr.objects import Measurement, PowerAttributes
  17. class Enum(type):
  18. def __getitem__(self, item):
  19. return getattr(self, item)
  20. @property
  21. def members(self):
  22. return sorted([item for item in list(set(dir(self)) - set(dir(Enum)))
  23. if not item.startswith("_")])
  24. @property
  25. def values(self):
  26. return [self[item] for item in self.members]
  27. class EVENT_STATUS(metaclass=Enum):
  28. NONE = "none"
  29. FAR = "far"
  30. NEAR = "near"
  31. ACTIVE = "active"
  32. COMPLETED = "completed"
  33. CANCELLED = "cancelled"
  34. class SIGNAL_TYPE(metaclass=Enum):
  35. DELTA = "delta"
  36. LEVEL = "level"
  37. MULTIPLIER = "multiplier"
  38. PRICE = "price"
  39. PRICE_MULTIPLIER = "priceMultiplier"
  40. PRICE_RELATIVE = "priceRelative"
  41. SETPOINT = "setpoint"
  42. X_LOAD_CONTROL_CAPACITY = "x-loadControlCapacity"
  43. X_LOAD_CONTROL_LEVEL_OFFSET = "x-loadControlLevelOffset"
  44. X_LOAD_CONTROL_PERCENT_OFFSET = "x-loadControlPercentOffset"
  45. X_LOAD_CONTROL_SETPOINT = "x-loadControlSetpoint"
  46. class SIGNAL_NAME(metaclass=Enum):
  47. SIMPLE = "SIMPLE"
  48. simple = "simple"
  49. ELECTRICITY_PRICE = "ELECTRICITY_PRICE"
  50. ENERGY_PRICE = "ENERGY_PRICE"
  51. DEMAND_CHARGE = "DEMAND_CHARGE"
  52. BID_PRICE = "BID_PRICE"
  53. BID_LOAD = "BID_LOAD"
  54. BID_ENERGY = "BID_ENERGY"
  55. CHARGE_STATE = "CHARGE_STATE"
  56. LOAD_DISPATCH = "LOAD_DISPATCH"
  57. LOAD_CONTROL = "LOAD_CONTROL"
  58. class SI_SCALE_CODE(metaclass=Enum):
  59. p = "p"
  60. n = "n"
  61. micro = "micro"
  62. m = "m"
  63. c = "c"
  64. d = "d"
  65. k = "k"
  66. M = "M"
  67. G = "G"
  68. T = "T"
  69. none = "none"
  70. class OPT(metaclass=Enum):
  71. OPT_IN = "optIn"
  72. OPT_OUT = "optOut"
  73. class OPT_REASON(metaclass=Enum):
  74. ECONOMIC = "economic"
  75. EMERGENCY = "emergency"
  76. MUST_RUN = "mustRun"
  77. NOT_PARTICIPATING = "notParticipating"
  78. OUTAGE_RUN_STATUS = "outageRunStatus"
  79. OVERRIDE_STATUS = "overrideStatus"
  80. PARTICIPATING = "participating"
  81. X_SCHEDULE = "x-schedule"
  82. class READING_TYPE(metaclass=Enum):
  83. DIRECT_READ = "Direct Read"
  84. NET = "Net"
  85. ALLOCATED = "Allocated"
  86. ESTIMATED = "Estimated"
  87. SUMMED = "Summed"
  88. DERIVED = "Derived"
  89. MEAN = "Mean"
  90. PEAK = "Peak"
  91. HYBRID = "Hybrid"
  92. CONTRACT = "Contract"
  93. PROJECTED = "Projected"
  94. X_RMS = "x-RMS"
  95. X_NOT_APPLICABLE = "x-notApplicable"
  96. class REPORT_TYPE(metaclass=Enum):
  97. READING = "reading"
  98. USAGE = "usage"
  99. DEMAND = "demand"
  100. SET_POINT = "setPoint"
  101. DELTA_USAGE = "deltaUsage"
  102. DELTA_SET_POINT = "deltaSetPoint"
  103. DELTA_DEMAND = "deltaDemand"
  104. BASELINE = "baseline"
  105. DEVIATION = "deviation"
  106. AVG_USAGE = "avgUsage"
  107. AVG_DEMAND = "avgDemand"
  108. OPERATING_STATE = "operatingState"
  109. UP_REGULATION_CAPACITY_AVAILABLE = "upRegulationCapacityAvailable"
  110. DOWN_REGULATION_CAPACITY_AVAILABLE = "downRegulationCapacityAvailable"
  111. REGULATION_SETPOINT = "regulationSetpoint"
  112. STORED_ENERGY = "storedEnergy"
  113. TARGET_ENERGY_STORAGE = "targetEnergyStorage"
  114. AVAILABLE_ENERGY_STORAGE = "availableEnergyStorage"
  115. PRICE = "price"
  116. LEVEL = "level"
  117. POWER_FACTOR = "powerFactor"
  118. PERCENT_USAGE = "percentUsage"
  119. PERCENT_DEMAND = "percentDemand"
  120. X_RESOURCE_STATUS = "x-resourceStatus"
  121. class REPORT_NAME(metaclass=Enum):
  122. METADATA_HISTORY_USAGE = "METADATA_HISTORY_USAGE"
  123. HISTORY_USAGE = "HISTORY_USAGE"
  124. METADATA_HISTORY_GREENBUTTON = "METADATA_HISTORY_GREENBUTTON"
  125. HISTORY_GREENBUTTON = "HISTORY_GREENBUTTON"
  126. METADATA_TELEMETRY_USAGE = "METADATA_TELEMETRY_USAGE"
  127. TELEMETRY_USAGE = "TELEMETRY_USAGE"
  128. METADATA_TELEMETRY_STATUS = "METADATA_TELEMETRY_STATUS"
  129. TELEMETRY_STATUS = "TELEMETRY_STATUS"
  130. class STATUS_CODES(metaclass=Enum):
  131. OUT_OF_SEQUENCE = 450
  132. NOT_ALLOWED = 451
  133. INVALID_ID = 452
  134. NOT_RECOGNIZED = 453
  135. INVALID_DATA = 454
  136. COMPLIANCE_ERROR = 459
  137. SIGNAL_NOT_SUPPORTED = 460
  138. REPORT_NOT_SUPPORTED = 461
  139. TARGET_MISMATCH = 462
  140. NOT_REGISTERED_OR_AUTHORIZED = 463
  141. DEPLOYMENT_ERROR_OR_OTHER_ERROR = 469
  142. class SECURITY_LEVEL:
  143. STANDARD = 'STANDARD'
  144. HIGH = 'HIGH'
  145. _CURRENCIES = ("AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM",
  146. "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL",
  147. "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW",
  148. "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK",
  149. "DJF", "DKK", "DOP", "DZD", "EEK", "EGP", "ERN", "ETB", "EUR", "FJD",
  150. "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GWP", "GYD",
  151. "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR",
  152. "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW",
  153. "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL",
  154. "LYD", "MAD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO",
  155. "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO",
  156. "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN",
  157. "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG",
  158. "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "STD", "SVC", "SYP", "SZL",
  159. "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH",
  160. "UGX", "USD", "USN", "USS", "UYI", "UYU", "UZS", "VEF", "VND", "VUV",
  161. "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR",
  162. "XFU", "XOF", "XPD", "XPF", "XPF", "XPF", "XPT", "XTS", "XXX", "YER",
  163. "ZAR", "ZMK", "ZWL")
  164. _ACCEPTABLE_UNITS = {'currency': _CURRENCIES,
  165. 'currencyPerKW': _CURRENCIES,
  166. 'currencyPerKWh': _CURRENCIES,
  167. 'currencyPerThm': _CURRENCIES,
  168. 'current': ('A',),
  169. 'energyApparent': ('VAh',),
  170. 'energyReactive': ('VARh',),
  171. 'energyReal': ('Wh',),
  172. 'frequency': ('Hz',),
  173. 'powerApparent': ('VA',),
  174. 'powerReactive': ('VAR',),
  175. 'powerReal': ('W',),
  176. 'pulseCount': ('count',),
  177. 'temperature': ('celsius', 'fahrenheit'),
  178. 'Therm': ('thm',),
  179. 'voltage': ('V',)}
  180. _MEASUREMENT_DESCRIPTIONS = {'currency': 'currency',
  181. 'currencyPerKW': 'currencyPerKW',
  182. 'currencyPerKWh': 'currencyPerKWh',
  183. 'currencyPerThm': 'currency',
  184. 'current': 'Current',
  185. 'energyApparent': 'ApparentEnergy',
  186. 'energyReactive': 'ReactiveEnergy',
  187. 'energyReal': 'RealEnergy',
  188. 'frequency': 'Frequency',
  189. 'powerApparent': 'ApparentPower',
  190. 'powerReactive': 'ReactivePower',
  191. 'powerReal': 'RealPower',
  192. 'pulseCount': 'pulse count',
  193. 'temperature': 'temperature',
  194. 'Therm': 'Therm',
  195. 'voltage': 'Voltage'}
  196. _MEASUREMENT_NAMESPACES = {'currency': 'oadr',
  197. 'currencyPerWK': 'oadr',
  198. 'currencyPerKWh': 'oadr',
  199. 'currencyPerThm': 'oadr',
  200. 'current': 'oadr',
  201. 'energyApparent': 'power',
  202. 'energyReactive': 'power',
  203. 'energyReal': 'power',
  204. 'frequency': 'oadr',
  205. 'powerApparent': 'power',
  206. 'powerReactive': 'power',
  207. 'powerReal': 'power',
  208. 'pulseCount': 'oadr',
  209. 'temperature': 'oadr',
  210. 'Therm': 'oadr',
  211. 'voltage': 'power',
  212. 'customUnit': 'oadr'}
  213. class MEASUREMENTS(metaclass=Enum):
  214. VOLTAGE = Measurement(name='voltage',
  215. description=_MEASUREMENT_DESCRIPTIONS['voltage'],
  216. unit=_ACCEPTABLE_UNITS['voltage'][0],
  217. acceptable_units=_ACCEPTABLE_UNITS['voltage'],
  218. scale='none')
  219. CURRENT = Measurement(name='current',
  220. description=_MEASUREMENT_DESCRIPTIONS['current'],
  221. unit=_ACCEPTABLE_UNITS['current'][0],
  222. acceptable_units=_ACCEPTABLE_UNITS['current'],
  223. scale='none')
  224. ENERGY_REAL = Measurement(name='energyReal',
  225. description=_MEASUREMENT_DESCRIPTIONS['energyReal'],
  226. unit=_ACCEPTABLE_UNITS['energyReal'][0],
  227. acceptable_units=_ACCEPTABLE_UNITS['energyReal'],
  228. scale='none')
  229. REAL_ENERGY = Measurement(name='energyReal',
  230. description=_MEASUREMENT_DESCRIPTIONS['energyReal'],
  231. unit=_ACCEPTABLE_UNITS['energyReal'][0],
  232. acceptable_units=_ACCEPTABLE_UNITS['energyReal'],
  233. scale='none')
  234. ACTIVE_ENERGY = Measurement(name='energyReal',
  235. description=_MEASUREMENT_DESCRIPTIONS['energyReal'],
  236. unit=_ACCEPTABLE_UNITS['energyReal'][0],
  237. acceptable_units=_ACCEPTABLE_UNITS['energyReal'],
  238. scale='none')
  239. ENERGY_REACTIVE = Measurement(name='energyReactive',
  240. description=_MEASUREMENT_DESCRIPTIONS['energyReactive'],
  241. unit=_ACCEPTABLE_UNITS['energyReactive'][0],
  242. acceptable_units=_ACCEPTABLE_UNITS['energyReactive'],
  243. scale='none')
  244. REACTIVE_ENERGY = Measurement(name='energyReactive',
  245. description=_MEASUREMENT_DESCRIPTIONS['energyReactive'],
  246. unit=_ACCEPTABLE_UNITS['energyReactive'][0],
  247. acceptable_units=_ACCEPTABLE_UNITS['energyReactive'],
  248. scale='none')
  249. ENERGY_APPARENT = Measurement(name='energyApparent',
  250. description=_MEASUREMENT_DESCRIPTIONS['energyApparent'],
  251. unit=_ACCEPTABLE_UNITS['energyApparent'][0],
  252. acceptable_units=_ACCEPTABLE_UNITS['energyApparent'],
  253. scale='none')
  254. APPARENT_ENERGY = Measurement(name='energyApparent',
  255. description=_MEASUREMENT_DESCRIPTIONS['energyApparent'],
  256. unit=_ACCEPTABLE_UNITS['energyApparent'][0],
  257. acceptable_units=_ACCEPTABLE_UNITS['energyApparent'],
  258. scale='none')
  259. ACTIVE_POWER = Measurement(name='powerReal',
  260. description=_MEASUREMENT_DESCRIPTIONS['powerReal'],
  261. unit=_ACCEPTABLE_UNITS['powerReal'][0],
  262. acceptable_units=_ACCEPTABLE_UNITS['powerReal'],
  263. scale='none',
  264. power_attributes=PowerAttributes(hertz=50,
  265. voltage=230,
  266. ac=True))
  267. REAL_POWER = Measurement(name='powerReal',
  268. description=_MEASUREMENT_DESCRIPTIONS['powerReal'],
  269. unit=_ACCEPTABLE_UNITS['powerReal'][0],
  270. acceptable_units=_ACCEPTABLE_UNITS['powerReal'],
  271. scale='none',
  272. power_attributes=PowerAttributes(hertz=50,
  273. voltage=230,
  274. ac=True))
  275. POWER_REAL = Measurement(name='powerReal',
  276. description=_MEASUREMENT_DESCRIPTIONS['powerReal'],
  277. unit=_ACCEPTABLE_UNITS['powerReal'][0],
  278. acceptable_units=_ACCEPTABLE_UNITS['powerReal'],
  279. scale='none',
  280. power_attributes=PowerAttributes(hertz=50,
  281. voltage=230,
  282. ac=True))
  283. REACTIVE_POWER = Measurement(name='powerReactive',
  284. description=_MEASUREMENT_DESCRIPTIONS['powerReactive'],
  285. unit=_ACCEPTABLE_UNITS['powerReactive'][0],
  286. acceptable_units=_ACCEPTABLE_UNITS['powerReactive'],
  287. scale='none',
  288. power_attributes=PowerAttributes(hertz=50,
  289. voltage=230,
  290. ac=True))
  291. POWER_REACTIVE = Measurement(name='powerReactive',
  292. description=_MEASUREMENT_DESCRIPTIONS['powerReactive'],
  293. unit=_ACCEPTABLE_UNITS['powerReactive'][0],
  294. acceptable_units=_ACCEPTABLE_UNITS['powerReactive'],
  295. scale='none',
  296. power_attributes=PowerAttributes(hertz=50,
  297. voltage=230,
  298. ac=True))
  299. APPARENT_POWER = Measurement(name='powerApparent',
  300. description=_MEASUREMENT_DESCRIPTIONS['powerApparent'],
  301. unit=_ACCEPTABLE_UNITS['powerApparent'][0],
  302. acceptable_units=_ACCEPTABLE_UNITS['powerApparent'],
  303. scale='none',
  304. power_attributes=PowerAttributes(hertz=50,
  305. voltage=230,
  306. ac=True))
  307. POWER_APPARENT = Measurement(name='powerApparent',
  308. description=_MEASUREMENT_DESCRIPTIONS['powerApparent'],
  309. unit=_ACCEPTABLE_UNITS['powerApparent'][0],
  310. acceptable_units=_ACCEPTABLE_UNITS['powerApparent'],
  311. scale='none',
  312. power_attributes=PowerAttributes(hertz=50,
  313. voltage=230,
  314. ac=True))
  315. FREQUENCY = Measurement(name='frequency',
  316. description=_MEASUREMENT_DESCRIPTIONS['frequency'],
  317. unit=_ACCEPTABLE_UNITS['frequency'][0],
  318. acceptable_units=_ACCEPTABLE_UNITS['frequency'],
  319. scale='none')
  320. PULSE_COUNT = Measurement(name='pulseCount',
  321. description=_MEASUREMENT_DESCRIPTIONS['pulseCount'],
  322. unit=_ACCEPTABLE_UNITS['pulseCount'][0],
  323. acceptable_units=_ACCEPTABLE_UNITS['pulseCount'],
  324. pulse_factor=1000)
  325. TEMPERATURE = Measurement(name='temperature',
  326. description=_MEASUREMENT_DESCRIPTIONS['temperature'],
  327. unit=_ACCEPTABLE_UNITS['temperature'][0],
  328. acceptable_units=_ACCEPTABLE_UNITS['temperature'],
  329. scale='none')
  330. THERM = Measurement(name='Therm',
  331. description=_MEASUREMENT_DESCRIPTIONS['Therm'],
  332. unit=_ACCEPTABLE_UNITS['Therm'][0],
  333. acceptable_units=_ACCEPTABLE_UNITS['Therm'],
  334. scale='none')
  335. CURRENCY = Measurement(name='currency',
  336. description=_MEASUREMENT_DESCRIPTIONS['currency'],
  337. unit=_CURRENCIES[0],
  338. acceptable_units=_CURRENCIES,
  339. scale='none')
  340. CURRENCY_PER_KW = Measurement(name='currencyPerKW',
  341. description=_MEASUREMENT_DESCRIPTIONS['currencyPerKW'],
  342. unit=_CURRENCIES[0],
  343. acceptable_units=_CURRENCIES,
  344. scale='none')
  345. CURRENCY_PER_KWH = Measurement(name='currencyPerKWh',
  346. description=_MEASUREMENT_DESCRIPTIONS['currencyPerKWh'],
  347. unit=_CURRENCIES[0],
  348. acceptable_units=_CURRENCIES,
  349. scale='none')
  350. CURRENCY_PER_THM = Measurement(name='currencyPerThm',
  351. description=_MEASUREMENT_DESCRIPTIONS['currencyPerThm'],
  352. unit=_CURRENCIES[0],
  353. acceptable_units=_CURRENCIES,
  354. scale='none')