|
1 | 1 | import uniq from 'lodash-es/uniq';
|
| 2 | +import { ActionsExecutor } from '../../card-controller/actions/types'; |
2 | 3 | import { StateWatcherSubscriptionInterface } from '../../card-controller/hass/state-watcher';
|
| 4 | +import { PTZAction, PTZActionPhase } from '../../config/schema/actions/custom/ptz'; |
3 | 5 | import { CameraConfig } from '../../config/schema/cameras';
|
4 | 6 | import { HomeAssistant } from '../../ha/types';
|
5 | 7 | import { localize } from '../../localize/localize';
|
6 | 8 | import { PTZCapabilities, PTZMovementType } from '../../types';
|
7 | 9 | import { errorToConsole } from '../../utils/basic';
|
8 |
| -import { EntityRegistryManager } from '../../utils/ha/registry/entity'; |
9 |
| -import { Entity } from '../../utils/ha/registry/entity/types'; |
| 10 | +import { Entity, EntityRegistryManager } from '../../utils/ha/registry/entity/types'; |
10 | 11 | import { Camera, CameraInitializationOptions } from '../camera';
|
11 | 12 | import { Capabilities } from '../capabilities';
|
12 | 13 | import { CameraManagerEngine } from '../engine';
|
@@ -57,6 +58,55 @@ export class FrigateCamera extends Camera {
|
57 | 58 | return await super.initialize(options);
|
58 | 59 | }
|
59 | 60 |
|
| 61 | + public async executePTZAction( |
| 62 | + executor: ActionsExecutor, |
| 63 | + action: PTZAction, |
| 64 | + options?: { |
| 65 | + phase?: PTZActionPhase; |
| 66 | + preset?: string; |
| 67 | + }, |
| 68 | + ): Promise<boolean> { |
| 69 | + if (await super.executePTZAction(executor, action, options)) { |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
| 73 | + const cameraEntity = this.getConfig().camera_entity; |
| 74 | + if ((action === 'preset' && !options?.preset) || !cameraEntity) { |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + // Awkward translation between card action and service parameters: |
| 79 | + // https://github.com/blakeblackshear/frigate-hass-integration/blob/dev/custom_components/frigate/services.yaml |
| 80 | + await executor.executeActions({ |
| 81 | + actions: { |
| 82 | + action: 'perform-action', |
| 83 | + perform_action: 'frigate.ptz', |
| 84 | + data: { |
| 85 | + action: |
| 86 | + options?.phase === 'stop' |
| 87 | + ? 'stop' |
| 88 | + : action === 'zoom_in' || action === 'zoom_out' |
| 89 | + ? 'zoom' |
| 90 | + : action === 'preset' |
| 91 | + ? 'preset' |
| 92 | + : 'move', |
| 93 | + ...(options?.phase !== 'stop' && { |
| 94 | + argument: |
| 95 | + action === 'zoom_in' |
| 96 | + ? 'in' |
| 97 | + : action === 'zoom_out' |
| 98 | + ? 'out' |
| 99 | + : action === 'preset' |
| 100 | + ? options?.preset |
| 101 | + : action, |
| 102 | + }), |
| 103 | + }, |
| 104 | + target: { entity_id: cameraEntity }, |
| 105 | + }, |
| 106 | + }); |
| 107 | + return true; |
| 108 | + } |
| 109 | + |
60 | 110 | protected async _initializeConfig(
|
61 | 111 | hass: HomeAssistant,
|
62 | 112 | entityRegistryManager: EntityRegistryManager,
|
@@ -194,10 +244,10 @@ export class FrigateCamera extends Camera {
|
194 | 244 | // Note: The Frigate integration only supports continuous PTZ movements
|
195 | 245 | // (regardless of the actual underlying camera capability).
|
196 | 246 | const panTilt: PTZMovementType[] = [
|
197 |
| - ...(ptzInfo.features?.includes('pt') ? ['continuous' as const] : []), |
| 247 | + ...(ptzInfo.features?.includes('pt') ? [PTZMovementType.Continuous] : []), |
198 | 248 | ];
|
199 | 249 | const zoom: PTZMovementType[] = [
|
200 |
| - ...(ptzInfo.features?.includes('zoom') ? ['continuous' as const] : []), |
| 250 | + ...(ptzInfo.features?.includes('zoom') ? [PTZMovementType.Continuous] : []), |
201 | 251 | ];
|
202 | 252 | const presets = ptzInfo.presets;
|
203 | 253 |
|
|
0 commit comments