fix: media_stop not supported on Google Cast devices (#1605)

* fix: `media_stop` not supported on Google Cast devices

* Add tests for new stop functionality

---------

Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com>
This commit is contained in:
Felipe Santos
2024-10-02 20:06:08 -07:00
committed by GitHub
co-authored by Dermot Duffy
parent 9098eb3483
commit 1f5d4bd8b0
3 changed files with 108 additions and 21 deletions
+25 -7
View File
@@ -1,5 +1,9 @@
import { CameraConfig, FrigateCardConfig } from '../config/types';
import { MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA } from '../const';
import {
MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA,
MEDIA_PLAYER_SUPPORT_STOP,
MEDIA_PLAYER_SUPPORT_TURN_OFF,
} from '../const';
import { localize } from '../localize/localize';
import { errorToConsole } from '../utils/basic';
import { Entity } from '../utils/ha/registry/entity/types';
@@ -85,12 +89,26 @@ export class MediaPlayerManager {
}
public async stop(mediaPlayer: string): Promise<void> {
await this._api
.getHASSManager()
.getHASS()
?.callService('media_player', 'media_stop', {
entity_id: mediaPlayer,
});
const hass = this._api.getHASSManager().getHASS();
const stateObj = hass?.states[mediaPlayer];
if (!stateObj) {
return;
}
let service: string;
if (supportsFeature(stateObj, MEDIA_PLAYER_SUPPORT_STOP)) {
service = 'media_stop';
} else if (supportsFeature(stateObj, MEDIA_PLAYER_SUPPORT_TURN_OFF)) {
// Google Cast devices don't support media_stop, but turning off has the
// same effect.
service = 'turn_off';
} else {
return;
}
await hass.callService('media_player', service, {
entity_id: mediaPlayer,
});
}
public async playLive(mediaPlayer: string, cameraID: string): Promise<void> {
+3 -1
View File
@@ -363,7 +363,9 @@ export const CONF_PERFORMANCE_STYLE_BORDER_RADIUS = `${CONF_PERFORMANCE}.style.b
export const CONF_PROFILES = 'profiles' as const;
// Taken from https://github.dev/home-assistant/frontend/blob/b5861869e39290fd2e15737e89571dfc543b3ad3/src/data/media-player.ts#L93
// Taken from https://github.com/home-assistant/frontend/blob/a759767d794f02527d127802831e68d3caf0cb7a/src/data/media-player.ts#L82
export const MEDIA_PLAYER_SUPPORT_TURN_OFF = 256;
export const MEDIA_PLAYER_SUPPORT_STOP = 4096;
export const MEDIA_PLAYER_SUPPORT_BROWSE_MEDIA = 131072;
// The number of media items to fetch at a time (for clips/snapshot views, and