Skip to content

Commit

Permalink
feat: quick global Google Assistant search
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerwyn committed Aug 1, 2023
1 parent 8db9889 commit 8f384fb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Along with a few other changes/improvements:
- Send keyboard keys using `androidtv.adb_command` using the [Android Debug Bridge integration](https://www.home-assistant.io/integrations/androidtv/) and the `adb_id` configuration option.
- Create a key titled `keyboard` to enable this and click it to open a text prompt in which you can enter text to send to your Android TV.
- Highly recommended that you also create keys for `delete` and `enter` so you can remove and send your input text.

- Quick global search also using ADB.
- Create a key titled 'search'. It will function similarly to keyboard entry except that it will launch a global search on close. This can also be used to send commands and queries to Google Assistant.
Many thanks to the original authors. Getting this to work with Android TV was straightforward and all of the frontend heavy lifting they did has provided an excellent base on which to build my personal ultimate Android TV remote.

## Demo
Expand Down Expand Up @@ -229,6 +230,8 @@ _row_3:

<img src="assets/keyboard_keys.png" alt="keyboard example" width="300"/>

Similarly, you can use ADB to do quick global Google Assistant searches by creating a button named `search`, which will function in a similar manner but will search immediately after sending the text.

## Installation

### Step 1
Expand Down
35 changes: 28 additions & 7 deletions android-tv-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,18 @@ class TVCardServices extends LitElement {
onButtonClick(e) {
let action = e.currentTarget.action;
let info = this.getInfo(action);
if (info.key == 'KEYBOARD') {
// TODO: Make this pull up the keyboard instead and use keypress event listener to send keys
this.onKeyboardPress(e);
} else {
this.sendAction(action);
this.fireHapticEvent(window, 'light');
switch (info.key) {
case 'KEYBOARD':
// TODO: Make this pull up the keyboard instead and use keypress event listener to send keys
this.onKeyboardPress(e);
break;
case 'SEARCH':
this.onSearchPress(e);
break;
default:
this.sendAction(action);
this.fireHapticEvent(window, 'light');
break;
}
}

Expand Down Expand Up @@ -524,7 +530,7 @@ class TVCardServices extends LitElement {

onKeyboardPress(e) {
e.stopImmediatePropagation();
let text = prompt('Send Text To TV: ');
let text = prompt('Search: ');
if (text) {
let data = {
entity_id: this._config.adb_id,
Expand All @@ -535,6 +541,21 @@ class TVCardServices extends LitElement {
}
}

onSearchPress(e) {
e.stopImmediatePropagation();
let text = prompt('Global Search: ');
if (text) {
let data = {
entity_id: this._config.adb_id,
command:
'am start -a "android.search.action.GLOBAL_SEARCH" --es query "' +
text +
'"',
};
this._hass.callService('androidtv', 'adb_command', data);
}
}

buildIconButton(action) {
let info = this.getInfo(action);
let icon = info?.icon ?? '';
Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A fork of usernein's tv-card for the Home Assistant [Android TV Remote](https://
- Many more default keys and sources
- *Not all working or tested at this time, let me know if you find the correct source/activity for the broken ones!
- Keyboard text entry via the [Android Debug Bridge integration](https://www.home-assistant.io/integrations/androidtv/).
- Quick global Google Assistant search also via ADB.

**Sample overview:**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "android-tv-card",
"version": "1.4.0",
"version": "1.4.1",
"description": "Android TV Remote Card",
"main": "./src/android-tv-card.js",
"scripts": {
Expand Down

0 comments on commit 8f384fb

Please sign in to comment.