This repository has been archived by the owner on Jul 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alexa_response_error.py
90 lines (71 loc) · 3.58 KB
/
alexa_response_error.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import little_helpers
class GenericErrorResponse(object):
# object representing the base generic error response, do not use directly!
# use any of the subclassess TemperatureOutOfRangeErrorResponse, ThermostatIsOffErrorResponse, InvalidDirectiveErrorResponse,
# InvalidValueErrorResponse, BridgeUnreachableErrorResponse, NoSuchEndpointErrorResponse, InternalErrorResponse
def __init__(self, request_object, error_type, error_message, namespace='Alexa', **kwargs):
self.response_header = {
"namespace": namespace,
"name": "ErrorResponse",
"messageId": little_helpers.get_uuid_str(),
"correlationToken": request_object.correlationToken,
"payloadVersion": "3"
}
self.response_endpoint = {
"endpointId": request_object.endpointId
}
self.response_payload = {
"type": error_type,
"message": error_message
}
if kwargs is not None:
for key, value in kwargs.items():
self.response_payload[str(key)] = value
def create_response(self):
return {
"event": {
"header": self.response_header,
"endpoint": self.response_endpoint,
"payload": self.response_payload
}
}
class TemperatureOutOfRangeErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the requested temperature is out of range
def __init__(self, request_object, message, min_value, max_value, scale="CELSIUS"):
kwargs = {
"validRange": {
"minimumValue": {
"value": min_value,
"scale": scale
},
"maximumValue": {
"value": max_value,
"scale": scale
}
}
}
super(TemperatureOutOfRangeErrorResponse, self).__init__(request_object, "TEMPERATURE_VALUE_OUT_OF_RANGE", message, "Alexa", **kwargs)
class ThermostatIsOffErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the requested thermostat is off and not responding
def __init__(self, request_object, message):
super(ThermostatIsOffErrorResponse, self).__init__(request_object, 'THERMOSTAT_IS_OFF', message, 'Alexa.ThermostatController')
class InvalidDirectiveErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the request's directive is invalid
def __init__(self, request_object, message):
super(InvalidDirectiveErrorResponse, self).__init__(request_object, 'INVALID_DIRECTIVE', message)
class InvalidValueErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the requested value is not supported
def __init__(self, request_object, message):
super(InvalidValueErrorResponse, self).__init__(request_object, 'INVALID_VALUE', message)
class BridgeUnreachableErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the destination bridge is unreachable
def __init__(self, request_object, message):
super(BridgeUnreachableErrorResponse, self).__init__(request_object, 'BRIDGE_UNREACHABLE', message)
class NoSuchEndpointErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the requested endpoint doesn't exist
def __init__(self, request_object, message):
super(NoSuchEndpointErrorResponse, self).__init__(request_object, 'NO_SUCH_ENDPOINT', message)
class InternalErrorResponse(GenericErrorResponse):
# object represnting the error response sent back when the requested endpoint doesn't exist
def __init__(self, request_object, message):
super(InternalErrorResponse, self).__init__(request_object, 'INTERNAL_ERROR', message)