File: errors.py

package info (click to toggle)
python-aiohue 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 612 kB
  • sloc: python: 4,444; sh: 30; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download | duplicates (2)
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
"""Aiohue errors.

https://developers.meethue.com/documentation/error-messages
"""


class AiohueException(Exception):
    """Base exception for aiohue."""


class Unauthorized(AiohueException):
    """Username is not authorized."""


class LinkButtonNotPressed(AiohueException):
    """Raised when trying to create a user but link button not pressed."""


class InvalidEvent(AiohueException):
    """Raised when we receive an event that we can not (yet) handle."""


class InvalidAPIVersion(AiohueException):
    """Raised when we're trying to connect to an unsupported bridge version."""


class BridgeBusy(AiohueException):
    """Raised when multiple requests to the bridge failed."""


class BridgeSoftwareOutdated(AiohueException):
    """Raised when the software version of the bridge is (too) outdated."""


ERRORS = {1: Unauthorized, 101: LinkButtonNotPressed}


def raise_from_error(error: dict) -> AiohueException:
    """Raise Exception based on Hue error."""
    _type = error.get("type")
    cls = ERRORS.get(_type, AiohueException)
    raise cls(error["description"])