feat: Add control/output of selected camera via an entity (#1895)

- Closes #1871
This commit is contained in:
Dermot Duffy
2025-02-17 13:33:10 -08:00
committed by GitHub
parent da79664a67
commit c66c3ec919
46 changed files with 677 additions and 91 deletions
@@ -12,7 +12,11 @@ export class CameraSelectAction extends AdvancedCameraCardAction<CameraSelectAct
const view = api.getViewManager().getView();
const config = api.getConfigManager().getConfig();
if (selectCameraID && view) {
// Don't do anything if the camera is already selected (especially important
// for control entities, as otherwise every camera change will generate a
// double request for events, once when the camera changes and another when
// the observed state of the control entity changes to match).
if (selectCameraID && view && selectCameraID !== view.camera) {
const viewOnCameraSelect = config?.view.camera_select ?? 'current';
const targetViewName =
viewOnCameraSelect === 'current' ? view.view : viewOnCameraSelect;
@@ -0,0 +1,9 @@
import { InternalCallbackActionConfig } from '../../../config/types';
import { CardActionsAPI } from '../../types';
import { AdvancedCameraCardAction } from './base';
export class InternalCallbackAction extends AdvancedCameraCardAction<InternalCallbackActionConfig> {
public async execute(api: CardActionsAPI): Promise<void> {
await this._action.callback(api);
}
}
+4 -1
View File
@@ -1,6 +1,6 @@
import { ActionConfig } from '@dermotduffy/custom-card-helpers';
import { ActionContext } from 'action';
import { ActionType } from '../../config/types';
import { ActionType, INTERNAL_CALLBACK_ACTION } from '../../config/types';
import { convertActionToCardCustomAction } from '../../utils/action';
import { CameraSelectAction } from './actions/camera-select';
import { CameraUIAction } from './actions/camera-ui';
@@ -10,6 +10,7 @@ import { DownloadAction } from './actions/download';
import { ExpandAction } from './actions/expand';
import { FullscreenAction } from './actions/fullscreen';
import { GenericAction } from './actions/generic';
import { InternalCallbackAction } from './actions/internal-callback';
import { LogAction } from './actions/log';
import { MediaPlayerAction } from './actions/media-player';
import { MenuToggleAction } from './actions/menu-toggle';
@@ -132,6 +133,8 @@ export class ActionFactory {
return new LogAction(context, cardCustomAction, options?.config);
case 'status_bar':
return new StatusBarAction(context, cardCustomAction, options?.config);
case INTERNAL_CALLBACK_ACTION:
return new InternalCallbackAction(context, cardCustomAction, options?.config);
}
/* istanbul ignore next: this path cannot be reached -- @preserve */