1# Copyright 2019 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4import logging 5 6class AssistantAdapterError(Exception): 7 """Error in AssistantAdapterNative.""" 8 pass 9 10class AssistantFacadeRemoteAdapter(object): 11 """AssistantFacadeRemoteAdapter is an adapter to remotely control DUT 12 assistant. 13 14 The Autotest host object representing the remote DUT, passed to this 15 class on initialization, can be accessed from its _client property. 16 17 """ 18 def __init__(self, host, remote_facade_proxy): 19 """Construct a AssistantFacadeRemoteAdapter. 20 21 @param host: Host object representing a remote host. 22 @param remote_facade_proxy: RemoteFacadeProxy object. 23 """ 24 self._client = host 25 self._proxy = remote_facade_proxy 26 27 28 @property 29 def _assistant_proxy(self): 30 return self._proxy.assistant 31 32 33 def restart_chrome_for_assistant(self, enable_dsp_hotword=True): 34 """Restarts Chrome with Google assistant enabled. 35 36 @param enable_dsp_hotword: A bool to control the usage of dsp for 37 hotword. 38 """ 39 logging.info("Restarting Chrome with Google assistant enabled.") 40 self._assistant_proxy.restart_chrome_for_assistant(enable_dsp_hotword) 41 logging.info("Chrome process restarted with assistant enabled.") 42 43 44 def send_text_query(self, text): 45 """Sends text query to Google assistant and gets respond. 46 47 @param text: A str object for text qeury. 48 49 @returns: A str object for query response. 50 """ 51 return self._assistant_proxy.send_text_query(text) 52 53 54 def enable_hotword(self): 55 """Enable hotword feature in Google assistant.""" 56 logging.info("Enabling hotword in Google assistant.") 57 self._assistant_proxy.enable_hotword() 58