Merge pull request #565 from felipecrs/filter-media-players

Only show media players capable of casting
This commit is contained in:
Dermot Duffy
2022-05-09 16:55:35 -07:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
+14 -4
View File
@@ -36,7 +36,7 @@ import type {
Message, Message,
} from './types.js'; } from './types.js';
import { CAMERA_BIRDSEYE, CARD_VERSION, REPO_URL } from './const.js'; import { CAMERA_BIRDSEYE, CARD_VERSION, MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA, REPO_URL } from './const.js';
import { FrigateCardElements } from './components/elements.js'; import { FrigateCardElements } from './components/elements.js';
import { FrigateCardImage } from './components/image.js'; import { FrigateCardImage } from './components/image.js';
import { FRIGATE_BUTTON_MENU_ICON, FrigateCardMenu } from './components/menu.js'; import { FRIGATE_BUTTON_MENU_ICON, FrigateCardMenu } from './components/menu.js';
@@ -86,6 +86,7 @@ import {
getOverriddenConfig, getOverriddenConfig,
getOverridesByKey, getOverridesByKey,
} from './card-condition.js'; } from './card-condition.js';
import { supportsFeature } from './icons/update.js';
/** A note on media callbacks: /** A note on media callbacks:
* *
@@ -470,9 +471,18 @@ export class FrigateCard extends LitElement {
}); });
} }
const mediaPlayers = Object.keys(this._hass?.states || {}).filter((entity) => const isValidMediaPlayer = (entity: string): boolean => {
entity.startsWith('media_player.'), if (entity.startsWith('media_player.')) {
); const stateObj = this._hass?.states[entity];
if (stateObj && supportsFeature(stateObj, MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA)) {
return true;
}
}
return false;
}
const mediaPlayers = Object.keys(this._hass?.states || {}).filter(isValidMediaPlayer);
if ( if (
mediaPlayers.length && mediaPlayers.length &&
(this._view?.isViewerView() || (this._view?.isViewerView() ||
+3
View File
@@ -140,3 +140,6 @@ export const CONF_DIMENSIONS_ASPECT_RATIO_MODE =
`${CONF_DIMENSIONS}.aspect_ratio_mode` as const; `${CONF_DIMENSIONS}.aspect_ratio_mode` as const;
export const CONF_OVERRIDES = 'overrides' as const; export const CONF_OVERRIDES = 'overrides' as const;
// Taken from https://github.dev/home-assistant/frontend/blob/b5861869e39290fd2e15737e89571dfc543b3ad3/src/data/media-player.ts#L93
export const MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA = 131072;