errors.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. OUT_OF_SEQUENCE = 450
  2. NOT_ALLOWED = 451
  3. INVALID_ID = 452
  4. NOT_RECOGNIZED = 453
  5. INVALID_DATA = 454
  6. COMPLIANCE_ERROR = 459
  7. SIGNAL_NOT_SUPPORTED = 460
  8. REPORT_NOT_SUPPORTED = 461
  9. TARGET_MISMATCH = 462
  10. NOT_REGISTERED_OR_AUTHORIZED = 463
  11. DEPLOYMENT_ERROR_OTHER = 469
  12. class OpenADRError(Exception):
  13. status_codes = {450: "OUT_OF_SEQUENCE",
  14. 451: "NOT_ALLOWED",
  15. 452: "INVALID_ID",
  16. 453: "NOT_RECOGNIZED",
  17. 454: "INVALID_DATA",
  18. 459: "COMPLIANCE_ERROR",
  19. 460: "SIGNAL_NOT_SUPPORTED",
  20. 461: "REPORT_NOT_SUPPORTED",
  21. 462: "TARGET_MISMATCH",
  22. 463: "NOT_REGISTERED_OR_AUTHORIZED",
  23. 469: "DEPLOYMENT_ERROR_OTHER"}
  24. def __init__(self, status, description):
  25. assert status in self.status_codes, f"Invalid status code {status} while raising OpenADRError"
  26. super().__init__()
  27. self.status = status
  28. self.description = description
  29. def __str__(self):
  30. return f'Error {self.status} {self.status_codes[self.status]}: {self.description}'