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:
karwosts 2023-07-13 04:20:51 -07:00 committed by GitHub
parent 3a4d2db8ff
commit 158a816f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 13 deletions

View File

@ -33,6 +33,7 @@ import type {
HassEntityBase,
} from "home-assistant-js-websocket";
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 type { HomeAssistant, TranslationDict } from "../types";
import { isUnavailableState } from "./entity";
@ -270,7 +271,7 @@ export const computeMediaControls = (
return undefined;
}
if (state === "off") {
if (!stateActive(stateObj)) {
return supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON)
? [
{

View File

@ -15,12 +15,12 @@ import { stopPropagation } from "../../../common/dom/stop_propagation";
import { computeAttributeValueDisplay } from "../../../common/entity/compute_attribute_display";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { stateActive } from "../../../common/entity/state_active";
import "../../../components/ha-icon-button";
import "../../../components/ha-select";
import "../../../components/ha-slider";
import "../../../components/ha-svg-icon";
import { showMediaBrowserDialog } from "../../../components/media-player/show-media-browser-dialog";
import { UNAVAILABLE, UNKNOWN } from "../../../data/entity";
import {
computeMediaControls,
handleMediaControlClick,
@ -83,7 +83,7 @@ class MoreInfoMediaPlayer extends LitElement {
</div>
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state)
stateActive(stateObj)
? html`
<div class="volume">
${supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_MUTE)
@ -141,7 +141,7 @@ class MoreInfoMediaPlayer extends LitElement {
</div>
`
: ""}
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
${stateActive(stateObj) &&
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOURCE) &&
stateObj.attributes.source_list?.length
? html`
@ -176,7 +176,7 @@ class MoreInfoMediaPlayer extends LitElement {
</div>
`
: ""}
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
${stateActive(stateObj) &&
supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) &&
stateObj.attributes.sound_mode_list?.length
? html`

View File

@ -17,6 +17,7 @@ import { fireEvent } from "../../../common/dom/fire_event";
import { computeStateName } from "../../../common/entity/compute_state_name";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { extractColors } from "../../../common/image/extract_color";
import { stateActive } from "../../../common/entity/state_active";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-card";
import "../../../components/ha-icon-button";
@ -169,10 +170,11 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
const entityState = stateObj.state;
const isOffState = entityState === "off";
const isOffState =
!stateActive(stateObj) && !isUnavailableState(entityState);
const isUnavailable =
isUnavailableState(entityState) ||
(entityState === "off" &&
(isOffState &&
!supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON));
const hasNoImage = !this._image;
const controls = computeMediaControls(stateObj, false);

View File

@ -24,10 +24,11 @@ import { customElement, property, state } from "lit/decorators";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { computeRTLDirection } from "../../../common/util/compute_rtl";
import { stateActive } from "../../../common/entity/state_active";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-icon-button";
import "../../../components/ha-slider";
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../../data/entity";
import { isUnavailableState } from "../../../data/entity";
import {
computeMediaDescription,
ControlButton,
@ -199,7 +200,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
>
<div class="controls">
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) &&
entityState === "off" &&
!stateActive(stateObj) &&
!isUnavailableState(entityState)
? html`
<ha-icon-button
@ -216,8 +217,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
? buttons
: ""}
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_OFF) &&
entityState !== "off" &&
!isUnavailableState(entityState)
stateActive(stateObj)
? html`
<ha-icon-button
.path=${mdiPower}
@ -230,7 +230,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
</hui-generic-entity-row>
${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) ||
supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) &&
![UNAVAILABLE, UNKNOWN, "off"].includes(entityState)
stateActive(stateObj)
? html`
<div class="flex">
<div class="volume">
@ -330,7 +330,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
this.hass!.callService(
"media_player",
stateObj.state === "off" ? "turn_on" : "turn_off",
stateActive(stateObj) ? "turn_off" : "turn_on",
{
entity_id: this._config!.entity,
}