mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-24 21: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 {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public item;
|
||||
@property() public item!: MediaPlayerItem;
|
||||
|
||||
@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 type { HomeAssistant } from "../types";
|
||||
import { UNAVAILABLE_STATES } from "./entity";
|
||||
import { isTTSMediaSource } from "./tts";
|
||||
|
||||
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
||||
media_content_id?: string;
|
||||
@ -441,3 +442,29 @@ export const handleMediaControlClick = (
|
||||
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,
|
||||
MediaPickedEvent,
|
||||
MediaPlayerEntity,
|
||||
mediaPlayerPlayMedia,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_PLAY_MEDIA,
|
||||
SUPPORT_SELECT_SOUND_MODE,
|
||||
@ -305,20 +306,14 @@ class MoreInfoMediaPlayer extends LitElement {
|
||||
action: "play",
|
||||
entityId: this.stateObj!.entity_id,
|
||||
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
||||
this._playMedia(
|
||||
mediaPlayerPlayMedia(
|
||||
this.hass,
|
||||
this.stateObj!.entity_id,
|
||||
pickedMedia.item.media_content_id,
|
||||
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 {
|
||||
|
@ -31,6 +31,7 @@ import {
|
||||
handleMediaControlClick,
|
||||
MediaPickedEvent,
|
||||
MediaPlayerEntity,
|
||||
mediaPlayerPlayMedia,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_SEEK,
|
||||
SUPPORT_TURN_ON,
|
||||
@ -489,21 +490,15 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
||||
action: "play",
|
||||
entityId: this._config!.entity,
|
||||
mediaPickedCallback: (pickedMedia: MediaPickedEvent) =>
|
||||
this._playMedia(
|
||||
mediaPlayerPlayMedia(
|
||||
this.hass,
|
||||
this._config!.entity,
|
||||
pickedMedia.item.media_content_id,
|
||||
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 {
|
||||
handleMediaControlClick(
|
||||
this.hass!,
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
BROWSER_PLAYER,
|
||||
MediaPickedEvent,
|
||||
MediaPlayerItem,
|
||||
mediaPlayerPlayMedia,
|
||||
} from "../../data/media-player";
|
||||
import {
|
||||
ResolvedMediaSource,
|
||||
@ -208,11 +209,12 @@ class PanelMediaBrowser extends LitElement {
|
||||
if (this._entityId !== BROWSER_PLAYER) {
|
||||
this._player.showResolvingNewMediaPicked();
|
||||
try {
|
||||
await this.hass!.callService("media_player", "play_media", {
|
||||
entity_id: this._entityId,
|
||||
media_content_id: item.media_content_id,
|
||||
media_content_type: item.media_content_type,
|
||||
});
|
||||
await mediaPlayerPlayMedia(
|
||||
this.hass,
|
||||
this._entityId,
|
||||
item.media_content_id,
|
||||
item.media_content_type
|
||||
);
|
||||
} catch (err) {
|
||||
this._player.hideResolvingNewMediaPicked();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user