1 """Alexa related errors."""
3 from __future__
import annotations
5 from typing
import Any, Literal
10 from .const
import API_TEMP_UNITS
14 """Does not support the requested Smart Home API property."""
18 """There is no access token available."""
22 """The skill needs to be relinked."""
26 """Base class for errors that can be serialized for the Alexa API.
28 A handler can raise subclasses of this to return an error to the request.
31 namespace: str |
None =
None
32 error_type: str |
None =
None
35 self, error_message: str, payload: dict[str, Any] |
None =
None
37 """Initialize an alexa error."""
38 Exception.__init__(self)
44 """The endpoint in the request does not exist."""
47 error_type =
"NO_SUCH_ENDPOINT"
50 """Initialize invalid endpoint error."""
51 msg = f
"The endpoint {endpoint_id} does not exist"
52 AlexaError.__init__(self, msg)
57 """Class to represent InvalidValue errors."""
60 error_type =
"INVALID_VALUE"
64 """Class to represent internal errors."""
67 error_type =
"INTERNAL_ERROR"
71 """The device is not in the correct mode to support this command."""
74 error_type =
"NOT_SUPPORTED_IN_CURRENT_MODE"
79 current_mode: Literal[
"COLOR",
"ASLEEP",
"NOT_PROVISIONED",
"OTHER"],
81 """Initialize invalid endpoint error."""
82 msg = f
"Not supported while in {current_mode} mode"
83 AlexaError.__init__(self, msg, {
"currentDeviceMode": current_mode})
88 """Class to represent UnsupportedThermostatMode errors."""
90 namespace =
"Alexa.ThermostatController"
91 error_type =
"UNSUPPORTED_THERMOSTAT_MODE"
95 """Class to represent unsupported climate target state error."""
97 namespace =
"Alexa.ThermostatController"
98 error_type =
"INVALID_TARGET_STATE"
102 """Class to represent TempRange errors."""
105 error_type =
"TEMPERATURE_VALUE_OUT_OF_RANGE"
108 self, hass: HomeAssistant, temp: float, min_temp: float, max_temp: float
110 """Initialize TempRange error."""
111 unit = hass.config.units.temperature_unit
113 "minimumValue": {
"value": min_temp,
"scale": API_TEMP_UNITS[unit]},
114 "maximumValue": {
"value": max_temp,
"scale": API_TEMP_UNITS[unit]},
116 payload = {
"validRange": temp_range}
117 msg = f
"The requested temperature {temp} is out of range"
119 AlexaError.__init__(self, msg, payload)
123 """Class to represent BridgeUnreachable errors."""
126 error_type =
"BRIDGE_UNREACHABLE"
130 """Class to represent SecurityPanelController Unauthorized errors."""
132 namespace =
"Alexa.SecurityPanelController"
133 error_type =
"UNAUTHORIZED"
137 """Class to represent SecurityPanelController AuthorizationRequired errors."""
139 namespace =
"Alexa.SecurityPanelController"
140 error_type =
"AUTHORIZATION_REQUIRED"
144 """Class to represent AlreadyInOperation errors."""
147 error_type =
"ALREADY_IN_OPERATION"
151 """Class to represent InvalidDirective errors."""
154 error_type =
"INVALID_DIRECTIVE"
158 """Class to represent action not permitted for content errors."""
160 namespace =
"Alexa.Video"
161 error_type =
"ACTION_NOT_PERMITTED_FOR_CONTENT"
None __init__(self, str error_message, dict[str, Any]|None payload=None)
None __init__(self, str endpoint_id)
None __init__(self, str endpoint_id, Literal["COLOR", "ASLEEP", "NOT_PROVISIONED", "OTHER"] current_mode)
None __init__(self, HomeAssistant hass, float temp, float min_temp, float max_temp)