Break out actions for type safety.

This commit is contained in:
Dermot Duffy
2022-05-01 22:50:18 -07:00
parent 14fb1c65eb
commit e90d56371c
+15 -9
View File
@@ -341,13 +341,16 @@ export class FrigateCard extends LitElement {
if (this._cameras && this._cameras.size > 1) { if (this._cameras && this._cameras.size > 1) {
const menuItems = Array.from(this._cameras, ([camera, config]) => { const menuItems = Array.from(this._cameras, ([camera, config]) => {
const action = createFrigateCardCustomAction('camera_select', {
camera: camera,
});
return { return {
icon: getCameraIcon(this._hass, config), icon: getCameraIcon(this._hass, config),
entity: config.camera_entity, entity: config.camera_entity,
state_color: true, state_color: true,
title: getCameraTitle(this._hass, config), title: getCameraTitle(this._hass, config),
selected: this._view?.camera === camera, selected: this._view?.camera === camera,
tap_action: createFrigateCardCustomAction('camera_select', { camera: camera }), ...(action && { tap_action: action }),
}; };
}); });
@@ -478,6 +481,15 @@ export class FrigateCard extends LitElement {
const mediaPlayerItems = mediaPlayers.map((playerEntityID) => { const mediaPlayerItems = mediaPlayers.map((playerEntityID) => {
const title = getEntityTitle(this._hass, playerEntityID) || playerEntityID; const title = getEntityTitle(this._hass, playerEntityID) || playerEntityID;
const state = this._hass?.states[playerEntityID]; const state = this._hass?.states[playerEntityID];
const playAction = createFrigateCardCustomAction('media_player', {
media_player: playerEntityID,
media_player_action: 'play',
});
const stopAction = createFrigateCardCustomAction('media_player', {
media_player: playerEntityID,
media_player_action: 'stop',
});
return { return {
icon: getEntityIcon(this._hass, playerEntityID) || 'mdi:cast', icon: getEntityIcon(this._hass, playerEntityID) || 'mdi:cast',
entity: playerEntityID, entity: playerEntityID,
@@ -485,14 +497,8 @@ export class FrigateCard extends LitElement {
title: title, title: title,
subtitle: title === playerEntityID ? undefined : playerEntityID, subtitle: title === playerEntityID ? undefined : playerEntityID,
disabled: !state || state.state === 'unavailable', disabled: !state || state.state === 'unavailable',
tap_action: createFrigateCardCustomAction('media_player', { ...(playAction && { tap_action: playAction }),
media_player: playerEntityID, ...(stopAction && { hold_action: stopAction }),
media_player_action: 'play',
}),
hold_action: createFrigateCardCustomAction('media_player', {
media_player: playerEntityID,
media_player_action: 'stop',
}),
}; };
}); });