Add shortcut to open the voice assist dialog (#23082)

* Add shortcut to open the voice assist dialog

* Add tip

* Only show dialog when enabled

* Update src/translations/en.json

---------

Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
Jan-Philipp Benecke 2024-12-02 10:26:27 +01:00 committed by GitHub
parent e0239486bc
commit 90b7cad7ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 2 deletions

View File

@ -96,7 +96,12 @@ const randomTip = (hass: HomeAssistant, narrow: boolean) => {
weight: 1,
narrow: false,
},
{ content: hass.localize("ui.tips.key_m_hint"), weight: 1, narrow: false }
{
content: hass.localize("ui.tips.key_m_hint"),
weight: 1,
narrow: false,
},
{ content: hass.localize("ui.tips.key_a_hint"), weight: 1, narrow: false }
);
}

View File

@ -1,5 +1,6 @@
import type { PropertyValues } from "lit";
import { tinykeys } from "tinykeys";
import memoizeOne from "memoize-one";
import { isComponentLoaded } from "../common/config/is_component_loaded";
import { mainWindow } from "../common/dom/get_main_window";
import type { QuickBarParams } from "../dialogs/quick-bar/show-dialog-quick-bar";
@ -9,6 +10,7 @@ import { storeState } from "../util/ha-pref-storage";
import { showToast } from "../util/toast";
import type { HassElement } from "./hass-element";
import { extractSearchParamsObject } from "../common/url/search-params";
import { showVoiceCommandDialog } from "../dialogs/voice-command-dialog/show-ha-voice-command-dialog";
declare global {
interface HASSDomEvents {
@ -39,6 +41,9 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
case "m":
this._createMyLink(ev.detail);
break;
case "a":
this._showVoiceCommandDialog(ev.detail);
break;
}
});
@ -51,13 +56,36 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
e: (ev) => this._showQuickBar(ev),
c: (ev) => this._showQuickBar(ev, true),
m: (ev) => this._createMyLink(ev),
a: (ev) => this._showVoiceCommandDialog(ev),
// Those are fallbacks for non-latin keyboards that don't have e, c, m keys (qwerty-based shortcuts)
KeyE: (ev) => this._showQuickBar(ev),
KeyC: (ev) => this._showQuickBar(ev, true),
KeyM: (ev) => this._createMyLink(ev),
KeyA: (ev) => this._showVoiceCommandDialog(ev),
});
}
private _conversation = memoizeOne((_components) =>
isComponentLoaded(this.hass!, "conversation")
);
private _showVoiceCommandDialog(e: KeyboardEvent) {
if (
!this.hass?.enableShortcuts ||
!this._canOverrideAlphanumericInput(e) ||
!this._conversation(this.hass.config.components)
) {
return;
}
if (e.defaultPrevented) {
return;
}
e.preventDefault();
showVoiceCommandDialog(this, this.hass!, { pipeline_id: "last_used" });
}
private _showQuickBar(e: KeyboardEvent, commandMode = false) {
if (!this._canShowQuickBar(e)) {
return;

View File

@ -7547,7 +7547,8 @@
"tips": {
"key_c_hint": "Press 'c' on any page to open the command dialog",
"key_e_hint": "Press 'e' on any page to open the entity search dialog",
"key_m_hint": "Press 'm' on any page to get the My Home Assistant link"
"key_m_hint": "Press 'm' on any page to get the My Home Assistant link",
"key_a_hint": "Press 'a' on any page to open the Assist dialog"
}
},
"landing-page": {