diff --git a/src/panels/config/dashboard/ha-config-dashboard.ts b/src/panels/config/dashboard/ha-config-dashboard.ts index 471bb9c091..1e18778c10 100644 --- a/src/panels/config/dashboard/ha-config-dashboard.ts +++ b/src/panels/config/dashboard/ha-config-dashboard.ts @@ -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 } ); } diff --git a/src/state/quick-bar-mixin.ts b/src/state/quick-bar-mixin.ts index 709450c94c..837bb3c447 100644 --- a/src/state/quick-bar-mixin.ts +++ b/src/state/quick-bar-mixin.ts @@ -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 >(superClass: T) => case "m": this._createMyLink(ev.detail); break; + case "a": + this._showVoiceCommandDialog(ev.detail); + break; } }); @@ -51,13 +56,36 @@ export default >(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; diff --git a/src/translations/en.json b/src/translations/en.json index b92e633806..a66bbf3481 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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": {