diff --git a/homeassistant/components/alexa/smart_home.py b/homeassistant/components/alexa/smart_home.py index b5115025c08..7360b22a89f 100644 --- a/homeassistant/components/alexa/smart_home.py +++ b/homeassistant/components/alexa/smart_home.py @@ -2,6 +2,7 @@ import asyncio import logging import math +from datetime import datetime from uuid import uuid4 from homeassistant.components import ( @@ -70,6 +71,39 @@ MAPPING_COMPONENT = { } +class _Cause(object): + """Possible causes for property changes. + + https://developer.amazon.com/docs/smarthome/state-reporting-for-a-smart-home-skill.html#cause-object + """ + + # Indicates that the event was caused by a customer interaction with an + # application. For example, a customer switches on a light, or locks a door + # using the Alexa app or an app provided by a device vendor. + APP_INTERACTION = 'APP_INTERACTION' + + # Indicates that the event was caused by a physical interaction with an + # endpoint. For example manually switching on a light or manually locking a + # door lock + PHYSICAL_INTERACTION = 'PHYSICAL_INTERACTION' + + # Indicates that the event was caused by the periodic poll of an appliance, + # which found a change in value. For example, you might poll a temperature + # sensor every hour, and send the updated temperature to Alexa. + PERIODIC_POLL = 'PERIODIC_POLL' + + # Indicates that the event was caused by the application of a device rule. + # For example, a customer configures a rule to switch on a light if a + # motion sensor detects motion. In this case, Alexa receives an event from + # the motion sensor, and another event from the light to indicate that its + # state change was caused by the rule. + RULE_TRIGGER = 'RULE_TRIGGER' + + # Indicates that the event was caused by a voice interaction with Alexa. + # For example a user speaking to their Echo device. + VOICE_INTERACTION = 'VOICE_INTERACTION' + + class Config: """Hold the configuration for Alexa.""" @@ -400,7 +434,17 @@ def async_api_activate(hass, config, request, entity): ATTR_ENTITY_ID: entity.entity_id }, blocking=False) - return api_message(request) + payload = { + 'cause': {'type': _Cause.VOICE_INTERACTION}, + 'timestamp': '%sZ' % (datetime.utcnow().isoformat(),) + } + + return api_message( + request, + name='ActivationStarted', + namespace='Alexa.SceneController', + payload=payload, + ) @HANDLERS.register(('Alexa.PercentageController', 'SetPercentage')) diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 6ac56bc10a3..1d98b87b960 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -739,7 +739,9 @@ def test_api_activate(hass, domain): assert len(call) == 1 assert call[0].data['entity_id'] == '{}.test'.format(domain) - assert msg['header']['name'] == 'Response' + assert msg['header']['name'] == 'ActivationStarted' + assert msg['payload']['cause']['type'] == 'VOICE_INTERACTION' + assert 'timestamp' in msg['payload'] @asyncio.coroutine