mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 10:26:35 +00:00
Add support for media player assumed state (#11642)
This commit is contained in:
parent
db7cac5782
commit
35cc291118
@ -261,8 +261,10 @@ export const computeMediaControls = (
|
||||
});
|
||||
}
|
||||
|
||||
const assumedState = stateObj.attributes.assumed_state === true;
|
||||
|
||||
if (
|
||||
(state === "playing" || state === "paused") &&
|
||||
(state === "playing" || state === "paused" || assumedState) &&
|
||||
supportsFeature(stateObj, SUPPORT_PREVIOUS_TRACK)
|
||||
) {
|
||||
buttons.push({
|
||||
@ -272,14 +274,15 @@ export const computeMediaControls = (
|
||||
}
|
||||
|
||||
if (
|
||||
(state === "playing" &&
|
||||
!assumedState &&
|
||||
((state === "playing" &&
|
||||
(supportsFeature(stateObj, SUPPORT_PAUSE) ||
|
||||
supportsFeature(stateObj, SUPPORT_STOP))) ||
|
||||
((state === "paused" || state === "idle") &&
|
||||
supportsFeature(stateObj, SUPPORT_PLAY)) ||
|
||||
(state === "on" &&
|
||||
(supportsFeature(stateObj, SUPPORT_PLAY) ||
|
||||
supportsFeature(stateObj, SUPPORT_PAUSE)))
|
||||
supportsFeature(stateObj, SUPPORT_PAUSE))))
|
||||
) {
|
||||
buttons.push({
|
||||
icon:
|
||||
@ -299,8 +302,29 @@ export const computeMediaControls = (
|
||||
});
|
||||
}
|
||||
|
||||
if (assumedState && supportsFeature(stateObj, SUPPORT_PLAY)) {
|
||||
buttons.push({
|
||||
icon: mdiPlay,
|
||||
action: "media_play",
|
||||
});
|
||||
}
|
||||
|
||||
if (assumedState && supportsFeature(stateObj, SUPPORT_PAUSE)) {
|
||||
buttons.push({
|
||||
icon: mdiPause,
|
||||
action: "media_pause",
|
||||
});
|
||||
}
|
||||
|
||||
if (assumedState && supportsFeature(stateObj, SUPPORT_STOP)) {
|
||||
buttons.push({
|
||||
icon: mdiStop,
|
||||
action: "media_stop",
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
(state === "playing" || state === "paused") &&
|
||||
(state === "playing" || state === "paused" || assumedState) &&
|
||||
supportsFeature(stateObj, SUPPORT_NEXT_TRACK)
|
||||
) {
|
||||
buttons.push({
|
||||
|
@ -110,10 +110,11 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
||||
|
||||
const entityState = stateObj.state;
|
||||
const controlButton = this._computeControlButton(stateObj);
|
||||
const assumedState = stateObj.attributes.assumed_state === true;
|
||||
|
||||
const buttons = html`
|
||||
${!this._narrow &&
|
||||
entityState === "playing" &&
|
||||
(entityState === "playing" || assumedState) &&
|
||||
supportsFeature(stateObj, SUPPORT_PREVIOUS_TRACK)
|
||||
? html`
|
||||
<ha-icon-button
|
||||
@ -125,14 +126,15 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
||||
></ha-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${(entityState === "playing" &&
|
||||
${!assumedState &&
|
||||
((entityState === "playing" &&
|
||||
(supportsFeature(stateObj, SUPPORT_PAUSE) ||
|
||||
supportsFeature(stateObj, SUPPORT_STOP))) ||
|
||||
((entityState === "paused" || entityState === "idle") &&
|
||||
supportsFeature(stateObj, SUPPORT_PLAY)) ||
|
||||
(entityState === "on" &&
|
||||
(supportsFeature(stateObj, SUPPORT_PLAY) ||
|
||||
supportsFeature(stateObj, SUPPORT_PAUSE)))
|
||||
supportsFeature(stateObj, SUPPORT_PAUSE))))
|
||||
? html`
|
||||
<ha-icon-button
|
||||
.path=${controlButton.icon}
|
||||
@ -143,7 +145,34 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
||||
></ha-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${entityState === "playing" &&
|
||||
${assumedState && supportsFeature(stateObj, SUPPORT_PLAY)
|
||||
? html`
|
||||
<ha-icon-button
|
||||
.path=${mdiPlay}
|
||||
.label=${this.hass.localize(`ui.card.media_player.media_play`)}
|
||||
@click=${this._play}
|
||||
></ha-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${assumedState && supportsFeature(stateObj, SUPPORT_PAUSE)
|
||||
? html`
|
||||
<ha-icon-button
|
||||
.path=${mdiPause}
|
||||
.label=${this.hass.localize(`ui.card.media_player.media_pause`)}
|
||||
@click=${this._pause}
|
||||
></ha-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${assumedState && supportsFeature(stateObj, SUPPORT_STOP)
|
||||
? html`
|
||||
<ha-icon-button
|
||||
.path=${mdiStop}
|
||||
.label=${this.hass.localize(`ui.card.media_player.media_stop`)}
|
||||
@click=${this._stop}
|
||||
></ha-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${(entityState === "playing" || assumedState) &&
|
||||
supportsFeature(stateObj, SUPPORT_NEXT_TRACK)
|
||||
? html`
|
||||
<ha-icon-button
|
||||
@ -312,6 +341,24 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
||||
});
|
||||
}
|
||||
|
||||
private _play(): void {
|
||||
this.hass!.callService("media_player", "media_play", {
|
||||
entity_id: this._config!.entity,
|
||||
});
|
||||
}
|
||||
|
||||
private _pause(): void {
|
||||
this.hass!.callService("media_player", "media_pause", {
|
||||
entity_id: this._config!.entity,
|
||||
});
|
||||
}
|
||||
|
||||
private _stop(): void {
|
||||
this.hass!.callService("media_player", "media_stop", {
|
||||
entity_id: this._config!.entity,
|
||||
});
|
||||
}
|
||||
|
||||
private _previousTrack(): void {
|
||||
this.hass!.callService("media_player", "media_previous_track", {
|
||||
entity_id: this._config!.entity,
|
||||
|
Loading…
x
Reference in New Issue
Block a user