exceptions.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # exceptions.py/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
  2. # This copyright was auto-generated on Tue Sep 7 21:35:53 UTC 2021
  3. """Exceptions that pertain to Gopro-level functionality."""
  4. from __future__ import annotations
  5. from typing import Callable
  6. class GoProError(Exception):
  7. """Base class for other GoPro-level exceptions."""
  8. class ResponseParseError(GoProError):
  9. """Error when parsing received data."""
  10. def __init__(self, identifier: str, data: bytearray, msg: str = "") -> None:
  11. super().__init__(f"{msg}: Failed to parse {data.hex(':')} from {identifier}")
  12. class InvalidOpenGoProVersion(GoProError):
  13. """Attempt to access an invalid Open GoPro API version"""
  14. def __init__(self, version: str) -> None:
  15. super().__init__(f"{version} is not a valid Open GoPro API version.")
  16. class InvalidConfiguration(GoProError):
  17. """Something was attempted that is not possible for the current configuration."""
  18. def __init__(self, message: str) -> None:
  19. super().__init__(f"Invalid configuration: {message}")
  20. class GoProNotOpened(GoProError):
  21. """A command was attempted without waiting for the GoPro instance to open."""
  22. def __init__(self, message: str) -> None:
  23. super().__init__(f"GoPro is not correctly open: {message}")
  24. class FailedToFindDevice(GoProError):
  25. """The scan failed without finding a device."""
  26. def __init__(self) -> None:
  27. super().__init__("A scan timed out without finding a device")
  28. class ConnectFailed(GoProError):
  29. """A BLE connection failed to establish
  30. Args:
  31. connection (str): type of connection that failed
  32. timeout (float): the timeout used for each attempt
  33. retries (int): how many retries were attempted
  34. """
  35. def __init__(self, connection: str, timeout: float, retries: int):
  36. super().__init__(f"{connection} connection failed to establish after {retries} retries with timeout {timeout}")
  37. class ConnectionTerminated(GoProError):
  38. """A connection that was previously established has terminated."""
  39. def __init__(self, message: str) -> None:
  40. super().__init__(f"Connection terminated: {message}")
  41. class ResponseTimeout(GoProError):
  42. """A response has timed out."""
  43. def __init__(self, timeout: float) -> None:
  44. super().__init__(f"Response timeout occurred of {timeout} seconds")
  45. class InterfaceConfigFailure(GoProError):
  46. """An error has occurred while setting up the communication interface"""
  47. ExceptionHandler = Callable[[Exception], None]
  48. """Exception handler callback type"""