mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 22:37:21 +00:00
Add announce: true when sending TTS from media browser (#12866)
This commit is contained in:
parent
4b36770adf
commit
2fdd50f45f
@ -36,7 +36,7 @@ declare global {
|
|||||||
class BrowseMediaTTS extends LitElement {
|
class BrowseMediaTTS extends LitElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property() public item;
|
@property() public item!: MediaPlayerItem;
|
||||||
|
|
||||||
@property() public action!: MediaPlayerBrowseAction;
|
@property() public action!: MediaPlayerBrowseAction;
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import { supportsFeature } from "../common/entity/supports-feature";
|
|||||||
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { UNAVAILABLE_STATES } from "./entity";
|
import { UNAVAILABLE_STATES } from "./entity";
|
||||||
|
import { isTTSMediaSource } from "./tts";
|
||||||
|
|
||||||
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
||||||
media_content_id?: string;
|
media_content_id?: string;
|
||||||
@ -441,3 +442,29 @@ export const handleMediaControlClick = (
|
|||||||
entity_id: stateObj!.entity_id,
|
entity_id: stateObj!.entity_id,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const mediaPlayerPlayMedia = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_id: string,
|
||||||
|
media_content_id: string,
|
||||||
|
media_content_type: string,
|
||||||
|
extra: {
|
||||||
|
enqueue?: "play" | "next" | "add" | "replace";
|
||||||
|
announce?: boolean;
|
||||||
|
} = {}
|
||||||
|
) => {
|
||||||
|
// We set text-to-speech to announce.
|
||||||
|
if (
|
||||||
|
!extra.enqueue &&
|
||||||
|
extra.announce === undefined &&
|
||||||
|
isTTSMediaSource(media_content_id)
|
||||||
|
) {
|
||||||
|
extra.announce = true;
|
||||||
|
}
|
||||||
|
return hass.callService("media_player", "play_media", {
|
||||||
|
entity_id,
|
||||||
|
media_content_id,
|
||||||
|
media_content_type,
|
||||||
|
...extra,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -26,6 +26,7 @@ import {
|
|||||||
handleMediaControlClick,
|
handleMediaControlClick,
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
MediaPlayerEntity,
|
MediaPlayerEntity,
|
||||||
|
mediaPlayerPlayMedia,
|
||||||
SUPPORT_BROWSE_MEDIA,
|
SUPPORT_BROWSE_MEDIA,
|
||||||
SUPPORT_PLAY_MEDIA,
|
SUPPORT_PLAY_MEDIA,
|
||||||
SUPPORT_SELECT_SOUND_MODE,
|
SUPPORT_SELECT_SOUND_MODE,
|
||||||
@ -305,20 +306,14 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
action: "play",
|
action: "play",
|
||||||
entityId: this.stateObj!.entity_id,
|
entityId: this.stateObj!.entity_id,
|
||||||
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
||||||
this._playMedia(
|
mediaPlayerPlayMedia(
|
||||||
|
this.hass,
|
||||||
|
this.stateObj!.entity_id,
|
||||||
pickedMedia.item.media_content_id,
|
pickedMedia.item.media_content_id,
|
||||||
pickedMedia.item.media_content_type
|
pickedMedia.item.media_content_type
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _playMedia(media_content_id: string, media_content_type: string) {
|
|
||||||
this.hass!.callService("media_player", "play_media", {
|
|
||||||
entity_id: this.stateObj!.entity_id,
|
|
||||||
media_content_id,
|
|
||||||
media_content_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -31,6 +31,7 @@ import {
|
|||||||
handleMediaControlClick,
|
handleMediaControlClick,
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
MediaPlayerEntity,
|
MediaPlayerEntity,
|
||||||
|
mediaPlayerPlayMedia,
|
||||||
SUPPORT_BROWSE_MEDIA,
|
SUPPORT_BROWSE_MEDIA,
|
||||||
SUPPORT_SEEK,
|
SUPPORT_SEEK,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
@ -489,21 +490,15 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
action: "play",
|
action: "play",
|
||||||
entityId: this._config!.entity,
|
entityId: this._config!.entity,
|
||||||
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
||||||
this._playMedia(
|
mediaPlayerPlayMedia(
|
||||||
|
this.hass,
|
||||||
|
this._config!.entity,
|
||||||
pickedMedia.item.media_content_id,
|
pickedMedia.item.media_content_id,
|
||||||
pickedMedia.item.media_content_type
|
pickedMedia.item.media_content_type
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _playMedia(media_content_id: string, media_content_type: string) {
|
|
||||||
this.hass!.callService("media_player", "play_media", {
|
|
||||||
entity_id: this._config!.entity,
|
|
||||||
media_content_id,
|
|
||||||
media_content_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _handleClick(e: MouseEvent): void {
|
private _handleClick(e: MouseEvent): void {
|
||||||
handleMediaControlClick(
|
handleMediaControlClick(
|
||||||
this.hass!,
|
this.hass!,
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
BROWSER_PLAYER,
|
BROWSER_PLAYER,
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
MediaPlayerItem,
|
MediaPlayerItem,
|
||||||
|
mediaPlayerPlayMedia,
|
||||||
} from "../../data/media-player";
|
} from "../../data/media-player";
|
||||||
import {
|
import {
|
||||||
ResolvedMediaSource,
|
ResolvedMediaSource,
|
||||||
@ -208,11 +209,12 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
if (this._entityId !== BROWSER_PLAYER) {
|
if (this._entityId !== BROWSER_PLAYER) {
|
||||||
this._player.showResolvingNewMediaPicked();
|
this._player.showResolvingNewMediaPicked();
|
||||||
try {
|
try {
|
||||||
await this.hass!.callService("media_player", "play_media", {
|
await mediaPlayerPlayMedia(
|
||||||
entity_id: this._entityId,
|
this.hass,
|
||||||
media_content_id: item.media_content_id,
|
this._entityId,
|
||||||
media_content_type: item.media_content_type,
|
item.media_content_id,
|
||||||
});
|
item.media_content_type
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._player.hideResolvingNewMediaPicked();
|
this._player.hideResolvingNewMediaPicked();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user