diff --git a/src/data/media-player.ts b/src/data/media-player.ts index c666c0ec52..0e3ca09160 100644 --- a/src/data/media-player.ts +++ b/src/data/media-player.ts @@ -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) ? [ { diff --git a/src/dialogs/more-info/controls/more-info-media_player.ts b/src/dialogs/more-info/controls/more-info-media_player.ts index b02fc75e9d..047605cd8a 100644 --- a/src/dialogs/more-info/controls/more-info-media_player.ts +++ b/src/dialogs/more-info/controls/more-info-media_player.ts @@ -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 { ${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) || supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) && - ![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) + stateActive(stateObj) ? html`
${supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_MUTE) @@ -141,7 +141,7 @@ class MoreInfoMediaPlayer extends LitElement {
` : ""} - ${![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 { ` : ""} - ${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) && + ${stateActive(stateObj) && supportsFeature(stateObj, MediaPlayerEntityFeature.SELECT_SOUND_MODE) && stateObj.attributes.sound_mode_list?.length ? html` diff --git a/src/panels/lovelace/cards/hui-media-control-card.ts b/src/panels/lovelace/cards/hui-media-control-card.ts index 4a5af932ce..aa8074d220 100644 --- a/src/panels/lovelace/cards/hui-media-control-card.ts +++ b/src/panels/lovelace/cards/hui-media-control-card.ts @@ -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); diff --git a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts index f2f481ad46..ab2de02d9a 100644 --- a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts @@ -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 { >
${supportsFeature(stateObj, MediaPlayerEntityFeature.TURN_ON) && - entityState === "off" && + !stateActive(stateObj) && !isUnavailableState(entityState) ? html` ${(supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_SET) || supportsFeature(stateObj, MediaPlayerEntityFeature.VOLUME_BUTTONS)) && - ![UNAVAILABLE, UNKNOWN, "off"].includes(entityState) + stateActive(stateObj) ? html`
@@ -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, }