Home Assistant Unofficial Reference 2024.12.1
errors.py
Go to the documentation of this file.
1 """Alexa related errors."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, Literal
6 
7 from homeassistant.core import HomeAssistant
8 from homeassistant.exceptions import HomeAssistantError
9 
10 from .const import API_TEMP_UNITS
11 
12 
14  """Does not support the requested Smart Home API property."""
15 
16 
18  """There is no access token available."""
19 
20 
21 class RequireRelink(Exception):
22  """The skill needs to be relinked."""
23 
24 
25 class AlexaError(Exception):
26  """Base class for errors that can be serialized for the Alexa API.
27 
28  A handler can raise subclasses of this to return an error to the request.
29  """
30 
31  namespace: str | None = None
32  error_type: str | None = None
33 
34  def __init__(
35  self, error_message: str, payload: dict[str, Any] | None = None
36  ) -> None:
37  """Initialize an alexa error."""
38  Exception.__init__(self)
39  self.error_messageerror_message = error_message
40  self.payloadpayload = None
41 
42 
44  """The endpoint in the request does not exist."""
45 
46  namespace = "Alexa"
47  error_type = "NO_SUCH_ENDPOINT"
48 
49  def __init__(self, endpoint_id: str) -> None:
50  """Initialize invalid endpoint error."""
51  msg = f"The endpoint {endpoint_id} does not exist"
52  AlexaError.__init__(self, msg)
53  self.endpoint_idendpoint_id = endpoint_id
54 
55 
57  """Class to represent InvalidValue errors."""
58 
59  namespace = "Alexa"
60  error_type = "INVALID_VALUE"
61 
62 
64  """Class to represent internal errors."""
65 
66  namespace = "Alexa"
67  error_type = "INTERNAL_ERROR"
68 
69 
71  """The device is not in the correct mode to support this command."""
72 
73  namespace = "Alexa"
74  error_type = "NOT_SUPPORTED_IN_CURRENT_MODE"
75 
76  def __init__(
77  self,
78  endpoint_id: str,
79  current_mode: Literal["COLOR", "ASLEEP", "NOT_PROVISIONED", "OTHER"],
80  ) -> None:
81  """Initialize invalid endpoint error."""
82  msg = f"Not supported while in {current_mode} mode"
83  AlexaError.__init__(self, msg, {"currentDeviceMode": current_mode})
84  self.endpoint_idendpoint_id = endpoint_id
85 
86 
88  """Class to represent UnsupportedThermostatMode errors."""
89 
90  namespace = "Alexa.ThermostatController"
91  error_type = "UNSUPPORTED_THERMOSTAT_MODE"
92 
93 
95  """Class to represent unsupported climate target state error."""
96 
97  namespace = "Alexa.ThermostatController"
98  error_type = "INVALID_TARGET_STATE"
99 
100 
102  """Class to represent TempRange errors."""
103 
104  namespace = "Alexa"
105  error_type = "TEMPERATURE_VALUE_OUT_OF_RANGE"
106 
107  def __init__(
108  self, hass: HomeAssistant, temp: float, min_temp: float, max_temp: float
109  ) -> None:
110  """Initialize TempRange error."""
111  unit = hass.config.units.temperature_unit
112  temp_range = {
113  "minimumValue": {"value": min_temp, "scale": API_TEMP_UNITS[unit]},
114  "maximumValue": {"value": max_temp, "scale": API_TEMP_UNITS[unit]},
115  }
116  payload = {"validRange": temp_range}
117  msg = f"The requested temperature {temp} is out of range"
118 
119  AlexaError.__init__(self, msg, payload)
120 
121 
123  """Class to represent BridgeUnreachable errors."""
124 
125  namespace = "Alexa"
126  error_type = "BRIDGE_UNREACHABLE"
127 
128 
130  """Class to represent SecurityPanelController Unauthorized errors."""
131 
132  namespace = "Alexa.SecurityPanelController"
133  error_type = "UNAUTHORIZED"
134 
135 
137  """Class to represent SecurityPanelController AuthorizationRequired errors."""
138 
139  namespace = "Alexa.SecurityPanelController"
140  error_type = "AUTHORIZATION_REQUIRED"
141 
142 
144  """Class to represent AlreadyInOperation errors."""
145 
146  namespace = "Alexa"
147  error_type = "ALREADY_IN_OPERATION"
148 
149 
151  """Class to represent InvalidDirective errors."""
152 
153  namespace = "Alexa"
154  error_type = "INVALID_DIRECTIVE"
155 
156 
158  """Class to represent action not permitted for content errors."""
159 
160  namespace = "Alexa.Video"
161  error_type = "ACTION_NOT_PERMITTED_FOR_CONTENT"
None __init__(self, str error_message, dict[str, Any]|None payload=None)
Definition: errors.py:36
None __init__(self, str endpoint_id, Literal["COLOR", "ASLEEP", "NOT_PROVISIONED", "OTHER"] current_mode)
Definition: errors.py:80
None __init__(self, HomeAssistant hass, float temp, float min_temp, float max_temp)
Definition: errors.py:109