File: exceptions.py

package info (click to toggle)
python-aioshelly 11.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 2,583; makefile: 8; sh: 3
file content (57 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Shelly exceptions."""

from __future__ import annotations

# Internal or run time errors:
#    Errors not needed to be handled by the caller
#    'NotInitialized' & 'WrongShellyGen' indicate runtime errors


class ShellyError(Exception):
    """Base class for aioshelly errors."""


class ConnectionClosed(ShellyError):
    """Exception raised when the connection is closed."""


class InvalidMessage(ShellyError):
    """Exception raised when an invalid message is received."""


class NotInitialized(ShellyError):
    """Raised if device is not initialized."""


class WrongShellyGen(ShellyError):
    """Exception raised to indicate wrong Shelly generation."""


# Errors to be handled by the caller:
#    Errors that are expected to happen and should be handled by the caller.


class DeviceConnectionError(ShellyError):
    """Exception indicates device connection errors."""


class InvalidAuthError(ShellyError):
    """Raised to indicate invalid or missing authentication error."""


class MacAddressMismatchError(ShellyError):
    """Raised if input MAC address does not match the device MAC address."""


class CustomPortNotSupported(ShellyError):
    """Raise if GEN1 devices are access with custom port."""


class RpcCallError(ShellyError):
    """Raised to indicate errors in RPC call."""

    def __init__(self, code: int, message: str = "") -> None:
        """Initialize JSON RPC errors."""
        self.code = code
        self.message = message
        super().__init__(code, message)