Google Assistant request sync service (#10165)

* Initial commit for request_sync functionality

* Fixes for Tox results

* Fixed all tox issues and tested locally with GA

* Review comments - api_key, conditional read descriptions

* Add test for service
This commit is contained in:
r4nd0mbr1ck
2017-11-14 03:32:23 +11:00
committed by Paulus Schoutsen
parent bc23799c71
commit f6d511ac1a
5 changed files with 106 additions and 7 deletions

View File

@@ -21,10 +21,16 @@ from homeassistant.core import HomeAssistant # NOQA
from homeassistant.helpers.entity import Entity # NOQA
from .const import (
CONF_ACCESS_TOKEN, CONF_EXPOSED_DOMAINS, ATTR_GOOGLE_ASSISTANT,
CONF_EXPOSE_BY_DEFAULT, DEFAULT_EXPOSED_DOMAINS, DEFAULT_EXPOSE_BY_DEFAULT,
GOOGLE_ASSISTANT_API_ENDPOINT)
from .smart_home import query_device, entity_to_device, determine_service
GOOGLE_ASSISTANT_API_ENDPOINT,
CONF_ACCESS_TOKEN,
DEFAULT_EXPOSE_BY_DEFAULT,
DEFAULT_EXPOSED_DOMAINS,
CONF_EXPOSE_BY_DEFAULT,
CONF_EXPOSED_DOMAINS,
ATTR_GOOGLE_ASSISTANT,
CONF_AGENT_USER_ID
)
from .smart_home import entity_to_device, query_device, determine_service
_LOGGER = logging.getLogger(__name__)
@@ -45,6 +51,7 @@ class GoogleAssistantView(HomeAssistantView):
DEFAULT_EXPOSE_BY_DEFAULT)
self.exposed_domains = cfg.get(CONF_EXPOSED_DOMAINS,
DEFAULT_EXPOSED_DOMAINS)
self.agent_user_id = cfg.get(CONF_AGENT_USER_ID)
def is_entity_exposed(self, entity) -> bool:
"""Determine if an entity should be exposed to Google Assistant."""
@@ -82,7 +89,9 @@ class GoogleAssistantView(HomeAssistantView):
devices.append(device)
return self.json(
make_actions_response(request_id, {'devices': devices}))
make_actions_response(request_id,
{'agentUserId': self.agent_user_id,
'devices': devices}))
@asyncio.coroutine
def handle_query(self,