* Alexa: implement auth and proactive ChangeReport messages * refactor after rebase from dev to use the new AlexaDirective and Response classes * move to aiohttp; cleanup * better function name * move endpoint to config * allow passing token function * remove uneeded state get * use iterable directly Co-Authored-By: abmantis <abmantis@users.noreply.github.com> * missing delete from previous commit * checks for when user has no auth config * update cloud component * PR suggestions * string lint * Revert "string lint" This reverts commit a05a1f134c9ebc7a6e67c093009744f142256365. * linters are now happier * more happy linters * use internal date parser; improve json response handling * remove unused import * use await instead of async_add_job * protect access token update method * add test_report_state * line too long * add docstring * Update test_smart_home.py * test accept grant api * init prefs if None * add tests for auth and token requests * replace global with hass.data * doc lint
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""
|
|
Support for Alexa skill service end point.
|
|
|
|
For more details about this component, please refer to the documentation at
|
|
https://home-assistant.io/components/alexa/
|
|
"""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
from homeassistant.helpers import entityfilter
|
|
|
|
from . import flash_briefings, intent, smart_home
|
|
from .const import (
|
|
CONF_AUDIO, CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_DISPLAY_URL,
|
|
CONF_ENDPOINT, CONF_TEXT, CONF_TITLE, CONF_UID, DOMAIN, CONF_FILTER,
|
|
CONF_ENTITY_CONFIG)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_FLASH_BRIEFINGS = 'flash_briefings'
|
|
CONF_SMART_HOME = 'smart_home'
|
|
|
|
DEPENDENCIES = ['http']
|
|
|
|
ALEXA_ENTITY_SCHEMA = vol.Schema({
|
|
vol.Optional(smart_home.CONF_DESCRIPTION): cv.string,
|
|
vol.Optional(smart_home.CONF_DISPLAY_CATEGORIES): cv.string,
|
|
vol.Optional(smart_home.CONF_NAME): cv.string,
|
|
})
|
|
|
|
SMART_HOME_SCHEMA = vol.Schema({
|
|
vol.Optional(CONF_ENDPOINT): cv.string,
|
|
vol.Optional(CONF_CLIENT_ID): cv.string,
|
|
vol.Optional(CONF_CLIENT_SECRET): cv.string,
|
|
vol.Optional(CONF_FILTER, default={}): entityfilter.FILTER_SCHEMA,
|
|
vol.Optional(CONF_ENTITY_CONFIG): {cv.entity_id: ALEXA_ENTITY_SCHEMA}
|
|
})
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
DOMAIN: {
|
|
CONF_FLASH_BRIEFINGS: {
|
|
cv.string: vol.All(cv.ensure_list, [{
|
|
vol.Optional(CONF_UID): cv.string,
|
|
vol.Required(CONF_TITLE): cv.template,
|
|
vol.Optional(CONF_AUDIO): cv.template,
|
|
vol.Required(CONF_TEXT, default=""): cv.template,
|
|
vol.Optional(CONF_DISPLAY_URL): cv.template,
|
|
}]),
|
|
},
|
|
# vol.Optional here would mean we couldn't distinguish between an empty
|
|
# smart_home: and none at all.
|
|
CONF_SMART_HOME: vol.Any(SMART_HOME_SCHEMA, None),
|
|
}
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
async def async_setup(hass, config):
|
|
"""Activate Alexa component."""
|
|
config = config.get(DOMAIN, {})
|
|
flash_briefings_config = config.get(CONF_FLASH_BRIEFINGS)
|
|
|
|
intent.async_setup(hass)
|
|
|
|
if flash_briefings_config:
|
|
flash_briefings.async_setup(hass, flash_briefings_config)
|
|
|
|
try:
|
|
smart_home_config = config[CONF_SMART_HOME]
|
|
except KeyError:
|
|
pass
|
|
else:
|
|
smart_home_config = smart_home_config or SMART_HOME_SCHEMA({})
|
|
smart_home.async_setup(hass, smart_home_config)
|
|
|
|
return True
|