Browse Source

Moved ERROR_CODES to enums

Stan Janssen 4 years ago
parent
commit
c53e15e3e6
2 changed files with 15 additions and 24 deletions
  1. 13 0
      pyopenadr/enums.py
  2. 2 24
      pyopenadr/errors.py

+ 13 - 0
pyopenadr/enums.py

@@ -126,3 +126,16 @@ class REPORT_NAME(metaclass=Enum):
     TELEMETRY_USAGE = "TELEMETRY_USAGE"
     TELEMETRY_USAGE = "TELEMETRY_USAGE"
     METADATA_TELEMETRY_STATUS = "METADATA_TELEMETRY_STATUS"
     METADATA_TELEMETRY_STATUS = "METADATA_TELEMETRY_STATUS"
     TELEMETRY_STATUS = "TELEMETRY_STATUS"
     TELEMETRY_STATUS = "TELEMETRY_STATUS"
+
+class STATUS_CODES(metaclass=Enum):
+    OUT_OF_SEQUENCE  = 450
+    NOT_ALLOWED      = 451
+    INVALID_ID       = 452
+    NOT_RECOGNIZED   = 453
+    INVALID_DATA     = 454
+    COMPLIANCE_ERROR = 459
+    SIGNAL_NOT_SUPPORTED = 460
+    REPORT_NOT_SUPPORTED = 461
+    TARGET_MISMATCH = 462
+    NOT_REGISTERED_OR_AUTHORIZED = 463
+    DEPLOYMENT_ERROR_OTHER = 469

+ 2 - 24
pyopenadr/errors.py

@@ -1,30 +1,8 @@
-OUT_OF_SEQUENCE  = 450
-NOT_ALLOWED      = 451
-INVALID_ID       = 452
-NOT_RECOGNIZED   = 453
-INVALID_DATA     = 454
-COMPLIANCE_ERROR = 459
-SIGNAL_NOT_SUPPORTED = 460
-REPORT_NOT_SUPPORTED = 461
-TARGET_MISMATCH = 462
-NOT_REGISTERED_OR_AUTHORIZED = 463
-DEPLOYMENT_ERROR_OTHER = 469
+from .enums import STATUS_CODES
 
 
 class OpenADRError(Exception):
 class OpenADRError(Exception):
-    status_codes = {450: "OUT_OF_SEQUENCE",
-                    451: "NOT_ALLOWED",
-                    452: "INVALID_ID",
-                    453: "NOT_RECOGNIZED",
-                    454: "INVALID_DATA",
-                    459: "COMPLIANCE_ERROR",
-                    460: "SIGNAL_NOT_SUPPORTED",
-                    461: "REPORT_NOT_SUPPORTED",
-                    462: "TARGET_MISMATCH",
-                    463: "NOT_REGISTERED_OR_AUTHORIZED",
-                    469: "DEPLOYMENT_ERROR_OTHER"}
-
     def __init__(self, status, description):
     def __init__(self, status, description):
-        assert status in self.status_codes, f"Invalid status code {status} while raising OpenADRError"
+        assert status in self.status_codes.values, f"Invalid status code {status} while raising OpenADRError"
         super().__init__()
         super().__init__()
         self.status = status
         self.status = status
         self.description = description
         self.description = description