mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Consistently treat standby
as a non-active state for media_player (#17289)
Consistently treat standby as an off state for media_player
This commit is contained in:
parent
3a4d2db8ff
commit
158a816f7a
@ -33,6 +33,7 @@ import type {
|
|||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
|
import { stateActive } from "../common/entity/state_active";
|
||||||
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
import { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
||||||
import type { HomeAssistant, TranslationDict } from "../types";
|
import type { HomeAssistant, TranslationDict } from "../types";
|
||||||
import { isUnavailableState } from "./entity";
|
import { isUnavailableState } from "./entity";
|
||||||
@ -270,7 +271,7 @@ export const computeMediaControls = (
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === "off") {
|
if (!stateActive(stateObj)) {
|
||||||
return supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON)
|
return supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON)
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
@ -15,12 +15,12 @@ import { stopPropagation } from "../../../common/dom/stop_propagation";
|
|||||||
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
|
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
||||||
|
import { stateActive } from "../../../common/entity/state_active";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-select";
|
import "../../../components/ha-select";
|
||||||
import "../../../components/ha-slider";
|
import "../../../components/ha-slider";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog";
|
import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity";
|
|
||||||
import {
|
import {
|
||||||
computeMediaControls,
|
computeMediaControls,
|
||||||
handleMediaControlClick,
|
handleMediaControlClick,
|
||||||
@ -83,7 +83,7 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
|
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
|
||||||
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
|
||||||
![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state)
|
stateActive(stateObj)
|
||||||
? html`
|
? html`
|
||||||
<div class="volume">
|
<div class="volume">
|
||||||
${supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_MUTE)
|
${supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_MUTE)
|
||||||
@ -141,7 +141,7 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
|
${stateActive(stateObj) &&
|
||||||
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOURCE) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOURCE) &&
|
||||||
stateObj.attributes.source_list?.length
|
stateObj.attributes.source_list?.length
|
||||||
? html`
|
? html`
|
||||||
@ -176,7 +176,7 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
|
${stateActive(stateObj) &&
|
||||||
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) &&
|
||||||
stateObj.attributes.sound_mode_list?.length
|
stateObj.attributes.sound_mode_list?.length
|
||||||
? html`
|
? html`
|
||||||
|
@ -17,6 +17,7 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
|||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import { extractColors } from "../../../common/image/extract_color";
|
import { extractColors } from "../../../common/image/extract_color";
|
||||||
|
import { stateActive } from "../../../common/entity/state_active";
|
||||||
import { debounce } from "../../../common/util/debounce";
|
import { debounce } from "../../../common/util/debounce";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -169,10 +170,11 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const entityState = stateObj.state;
|
const entityState = stateObj.state;
|
||||||
|
|
||||||
const isOffState = entityState === "off";
|
const isOffState =
|
||||||
|
!stateActive(stateObj) && !isUnavailableState(entityState);
|
||||||
const isUnavailable =
|
const isUnavailable =
|
||||||
isUnavailableState(entityState) ||
|
isUnavailableState(entityState) ||
|
||||||
(entityState === "off" &&
|
(isOffState &&
|
||||||
!supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON));
|
!supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON));
|
||||||
const hasNoImage = !this._image;
|
const hasNoImage = !this._image;
|
||||||
const controls = computeMediaControls(stateObj, false);
|
const controls = computeMediaControls(stateObj, false);
|
||||||
|
@ -24,10 +24,11 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
||||||
|
import { stateActive } from "../../../common/entity/state_active";
|
||||||
import { debounce } from "../../../common/util/debounce";
|
import { debounce } from "../../../common/util/debounce";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-slider";
|
import "../../../components/ha-slider";
|
||||||
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../../data/entity";
|
import { isUnavailableState } from "../../../data/entity";
|
||||||
import {
|
import {
|
||||||
computeMediaDescription,
|
computeMediaDescription,
|
||||||
ControlButton,
|
ControlButton,
|
||||||
@ -199,7 +200,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
>
|
>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) &&
|
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) &&
|
||||||
entityState === "off" &&
|
!stateActive(stateObj) &&
|
||||||
!isUnavailableState(entityState)
|
!isUnavailableState(entityState)
|
||||||
? html`
|
? html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@ -216,8 +217,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
? buttons
|
? buttons
|
||||||
: ""}
|
: ""}
|
||||||
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_OFF) &&
|
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_OFF) &&
|
||||||
entityState !== "off" &&
|
stateActive(stateObj)
|
||||||
!isUnavailableState(entityState)
|
|
||||||
? html`
|
? html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.path=${mdiPower}
|
.path=${mdiPower}
|
||||||
@ -230,7 +230,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
</hui-generic-entity-row>
|
</hui-generic-entity-row>
|
||||||
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
|
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
|
||||||
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
|
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
|
||||||
![UNAVAILABLE, UNKNOWN, "off"].includes(entityState)
|
stateActive(stateObj)
|
||||||
? html`
|
? html`
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="volume">
|
<div class="volume">
|
||||||
@ -330,7 +330,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
this.hass!.callService(
|
this.hass!.callService(
|
||||||
"media_player",
|
"media_player",
|
||||||
stateObj.state === "off" ? "turn_on" : "turn_off",
|
stateActive(stateObj) ? "turn_off" : "turn_on",
|
||||||
{
|
{
|
||||||
entity_id: this._config!.entity,
|
entity_id: this._config!.entity,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user