Respond to Alexa scene activation correctly (#11869)
The API documentation[1] specifies that Alexa.SceneController Activate must get a ActivationStarted response. Responding with just a `Response` will elicit a "Hmm... $scene is not responding" from Alexa. [1]: https://developer.amazon.com/docs/smarthome/provide-scenes-in-a-smart-home-skill.html
This commit is contained in:
parent
09e3bf94eb
commit
95592d9283
2 changed files with 48 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
from datetime import datetime
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from homeassistant.components import (
|
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:
|
class Config:
|
||||||
"""Hold the configuration for Alexa."""
|
"""Hold the configuration for Alexa."""
|
||||||
|
|
||||||
|
@ -400,7 +434,17 @@ def async_api_activate(hass, config, request, entity):
|
||||||
ATTR_ENTITY_ID: entity.entity_id
|
ATTR_ENTITY_ID: entity.entity_id
|
||||||
}, blocking=False)
|
}, 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'))
|
@HANDLERS.register(('Alexa.PercentageController', 'SetPercentage'))
|
||||||
|
|
|
@ -739,7 +739,9 @@ def test_api_activate(hass, domain):
|
||||||
|
|
||||||
assert len(call) == 1
|
assert len(call) == 1
|
||||||
assert call[0].data['entity_id'] == '{}.test'.format(domain)
|
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
|
@asyncio.coroutine
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue