-
Notifications
You must be signed in to change notification settings - Fork 337
/
alexa_change_report.py
66 lines (55 loc) · 3 KB
/
alexa_change_report.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
# -*- coding: utf-8 -*-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use this file except in
# compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import uuid
from .alexa_utils import get_utc_timestamp
class AlexaChangeReport:
def __init__(self, **kwargs):
self.namespace = kwargs.get('namespace', 'Alexa')
self.name = kwargs.get('name', 'ChangeReport')
self.payload_version = kwargs.get('payload_version', '3')
self.message_id = kwargs.get('message_id', str(uuid.uuid4()))
self.type = "BearerToken"
self.token = kwargs.get('token', 'INVALID')
self.endpoint_id = kwargs.get('endpoint_id', 'INVALID')
self.cause_type = kwargs.get('cause_type', 'PHYSICAL_INTERACTION')
def create_property(self, **kwargs):
p = {}
p['namespace'] = kwargs.get('namespace', 'Alexa')
p['name'] = kwargs.get('name', 'powerState')
p['value'] = kwargs.get('value', 'ON')
p['timeOfSample'] = get_utc_timestamp()
p['uncertaintyInMilliseconds'] = kwargs.get('uncertainty_in_milliseconds', 0)
return p
def get_response(self):
response = {}
response['context'] = {}
response['context']['properties'] = []
response['context']['properties'].append(self.create_property(namespace='Alexa.PowerController', name='powerState', value='ON'))
response['context']['properties'].append(self.create_property(namespace='Alexa.EndpointHealth', name='connectivity', value={'value': 'OK'}))
response['event'] = {}
response['event']['header'] = {}
response['event']['header']['namespace'] = self.namespace
response['event']['header']['name'] = self.name
response['event']['header']['payloadVersion'] = self.payload_version
response['event']['header']['messageId'] = self.message_id
response['event']['endpoint'] = {}
response['event']['endpoint']['scope'] = {}
response['event']['endpoint']['scope']['type'] = self.type
response['event']['endpoint']['scope']['token'] = self.token
response['event']['endpoint']['endpointId'] = self.endpoint_id
response['event']['payload'] = {}
response['event']['payload']['change'] = {}
response['event']['payload']['change']['cause'] = {}
response['event']['payload']['change']['cause']['type'] = self.cause_type
response['event']['payload']['change']['properties'] = []
response['event']['payload']['change']['properties'].append(self.create_property(namespace='Alexa.BrightnessController', name='brightness', value=65))
return response