Skip to content

Commit

Permalink
Updates to improve discovery and cleanup
Browse files Browse the repository at this point in the history
This commit includes changes to the discovery process by having discovery information stored and retrieved from the SampleEndpointDetails with a reference to AWS IoT via thingName. Additionally, there is cleanup on the Alexa response handling and initial considerations for the cooking capabilities.
  • Loading branch information
mikemaas authored and mikemaas-amazon committed Feb 2, 2018
1 parent ded74d2 commit 835e2a7
Show file tree
Hide file tree
Showing 13 changed files with 800 additions and 705 deletions.
26 changes: 24 additions & 2 deletions sample_backend/cloud-formation/backend.template.us
Expand Up @@ -372,6 +372,8 @@
"Effect": "Allow",
"Action": [
"iot:CreateThing",
"iot:CreateThingType",
"iot:DeleteThing",
"iot:DescribeThing",
"iot:ListThings",
"iot:UpdateThing"
Expand Down Expand Up @@ -495,6 +497,26 @@
}
}
},
"EndpointsMethodDelete": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"RestApiId": {
"Ref": "EndpointRestApi"
},
"ResourceId": {
"Ref": "EndpointsResource"
},
"HttpMethod": "DELETE",
"AuthorizationType": "NONE",
"Integration": {
"Type": "AWS_PROXY",
"IntegrationHttpMethod": "POST",
"Uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EndpointLambda.Arn}/invocations"
}
}
}
},
"DirectivesMethodPost": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
Expand Down Expand Up @@ -525,13 +547,13 @@
"Properties": {
"AttributeDefinitions": [
{
"AttributeName": "DetailsId",
"AttributeName": "EndpointId",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": "DetailsId",
"AttributeName": "EndpointId",
"KeyType": "HASH"
}
],
Expand Down
@@ -1,7 +1,16 @@
from .alexa_acceptgrant_response import AlexaAcceptGrantResponse
from .alexa_change_report import AlexaChangeReport
# -*- coding: utf-8 -*-

# Copyright 2018 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.

from .alexa_discover_response import AlexaDiscoverResponse
from .alexa_error import AlexaError
from .alexa_power_controller import AlexaPowerController
from .alexa_response import AlexaResponse
from .alexa_utils import get_utc_timestamp

This file was deleted.

This file was deleted.

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# Copyright 2018 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
Expand All @@ -25,20 +25,25 @@ def __init__(self, request):
self.payload_version = request["directive"]["header"]["payloadVersion"]
self.endpoints = []

def add_endpoint(self, thing):
# Translate the AWS IoT Thing attributes
endpoint_id_value = thing['thingName']
# HACK Using the thing name as the friendly name!
friendly_name_value = thing['thingName'].replace('_', ' ')
# NOTE SWITCH is currently hardcoded into the endpoint
self.endpoints.append(self.create_endpoint(endpoint_id=endpoint_id_value, friendly_name=friendly_name_value, display_categories=['SWITCH']))
def add_endpoint(self, endpoint_details):
self.endpoints.append(
self.create_endpoint(
capabilities=endpoint_details.capabilities,
description=endpoint_details.description,
display_categories=endpoint_details.display_categories,
endpoint_id=endpoint_details.id,
friendly_name=endpoint_details.friendly_name,
manufacturer_name=endpoint_details.manufacturer_name,
sku=endpoint_details.sku,
user_id=endpoint_details.user_id
))

def create_capability(self, **kwargs):
capability = {}
capability['type'] = kwargs.get('type', 'AlexaInterface')
capability['interface'] = kwargs.get('interface', 'Alexa')
capability['version'] = kwargs.get('version', '3')
supported = kwargs.get('supported', None) # [{"name": "powerState"}]
supported = kwargs.get('supported', None)
if supported:
capability['properties'] = {}
capability['properties']['supported'] = supported
Expand All @@ -48,27 +53,23 @@ def create_capability(self, **kwargs):
return capability

def create_endpoint(self, **kwargs):
# Return the proper structure expected for the endpoint
endpoint = {}
endpoint['capabilities'] = kwargs.get('capabilities', [])
endpoint['description'] = kwargs.get('description', 'Endpoint Description')
endpoint['displayCategories'] = kwargs.get('display_categories', ['OTHER'])
endpoint['endpointId'] = kwargs.get('endpoint_id', 'endpoint_' + "%0.6d" % random.randint(0, 999999))
endpoint['friendlyName'] = kwargs.get('friendly_name', 'Endpoint')
endpoint['description'] = kwargs.get('description', 'Endpoint Description')
endpoint['manufacturerName'] = kwargs.get('manufacturer_name', 'Unknown Manufacturer')
endpoint['displayCategories'] = kwargs.get('display_categories', ['OTHER'])

# NOTE: These capabilities are hardcoded, how might we expose them differently?
endpoint['capabilities'] = []
endpoint['capabilities'].append(self.create_capability())
endpoint['capabilities'].append(self.create_capability(interface='Alexa.PowerController', supported=[{"name": "powerState"}]))
endpoint['capabilities'].append(self.create_capability(interface='Alexa.EndpointHealth', supported=[{"name": "connectivity"}]))
return endpoint

def create_property(self, **kwargs):
p = {}
p['namespace'] = kwargs.get('namespace', 'Alexa')
p['name'] = 'powerState'
p['value'] = 'ON'
p['namespace'] = kwargs.get('namespace', 'Alexa')
p['timeOfSample'] = get_utc_timestamp()
p['uncertaintyInMilliseconds'] = kwargs.get('uncertainty_in_milliseconds', 0)
p['value'] = 'ON'
return p

def get_response(self):
Expand All @@ -86,8 +87,6 @@ def get_response(self):
header['payloadVersion'] = self.payload_version
header['messageId'] = self.message_id

# self.endpoints.append(self.create_endpoint())

payload = {}
payload['endpoints'] = self.endpoints

Expand Down

This file was deleted.

0 comments on commit 835e2a7

Please sign in to comment.