mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Hide hidden media player entities in media panel (#12766)
This commit is contained in:
parent
e7517a8b61
commit
3f1a2526b3
@ -11,6 +11,7 @@ import {
|
||||
mdiStop,
|
||||
mdiVolumeHigh,
|
||||
} from "@mdi/js";
|
||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import {
|
||||
css,
|
||||
CSSResultGroup,
|
||||
@ -32,6 +33,7 @@ import "../../components/ha-button-menu";
|
||||
import "../../components/ha-circular-progress";
|
||||
import "../../components/ha-icon-button";
|
||||
import { UNAVAILABLE_STATES } from "../../data/entity";
|
||||
import { subscribeEntityRegistry } from "../../data/entity_registry";
|
||||
import {
|
||||
BROWSER_PLAYER,
|
||||
cleanupMediaTitle,
|
||||
@ -51,6 +53,7 @@ import {
|
||||
} from "../../data/media-player";
|
||||
import { ResolvedMediaSource } from "../../data/media_source";
|
||||
import { showAlertDialog } from "../../dialogs/generic/show-dialog-box";
|
||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import "../lovelace/components/hui-marquee";
|
||||
import {
|
||||
@ -65,7 +68,7 @@ declare global {
|
||||
}
|
||||
|
||||
@customElement("ha-bar-media-player")
|
||||
export class BarMediaPlayer extends LitElement {
|
||||
export class BarMediaPlayer extends SubscribeMixin(LitElement) {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ attribute: false }) public entityId!: string;
|
||||
@ -83,6 +86,9 @@ export class BarMediaPlayer extends LitElement {
|
||||
|
||||
@state() private _browserPlayer?: BrowserMediaPlayer;
|
||||
|
||||
@state()
|
||||
private _hiddenEntities = new Set<string>();
|
||||
|
||||
private _progressInterval?: number;
|
||||
|
||||
private _browserPlayerVolume = 0.8;
|
||||
@ -461,7 +467,8 @@ export class BarMediaPlayer extends LitElement {
|
||||
return Object.values(this.hass!.states).filter(
|
||||
(entity) =>
|
||||
computeStateDomain(entity) === "media_player" &&
|
||||
supportsFeature(entity, SUPPORT_BROWSE_MEDIA)
|
||||
supportsFeature(entity, SUPPORT_BROWSE_MEDIA) &&
|
||||
!this._hiddenEntities.has(entity.entity_id)
|
||||
);
|
||||
}
|
||||
|
||||
@ -487,6 +494,28 @@ export class BarMediaPlayer extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
protected override hassSubscribe(): (
|
||||
| UnsubscribeFunc
|
||||
| Promise<UnsubscribeFunc>
|
||||
)[] {
|
||||
return [
|
||||
subscribeEntityRegistry(this.hass.connection, (entries) => {
|
||||
const hiddenEntities = new Set<string>();
|
||||
|
||||
for (const entry of entries) {
|
||||
if (
|
||||
entry.hidden_by &&
|
||||
computeDomain(entry.entity_id) === "media_player"
|
||||
) {
|
||||
hiddenEntities.add(entry.entity_id);
|
||||
}
|
||||
}
|
||||
|
||||
this._hiddenEntities = hiddenEntities;
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
private _handleControlClick(e: MouseEvent): void {
|
||||
const action = (e.currentTarget! as HTMLElement).getAttribute("action")!;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user