Initial version of substream support.
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
DataQuery,
|
||||
EventQuery,
|
||||
EventQueryResultsMap,
|
||||
MediaMetadata,
|
||||
PartialEventQuery,
|
||||
PartialRecordingQuery,
|
||||
PartialRecordingSegmentsQuery,
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
EventQuery,
|
||||
EventQueryResults,
|
||||
EventQueryResultsMap,
|
||||
MediaMetadata,
|
||||
PartialEventQuery,
|
||||
PartialRecordingQuery,
|
||||
PartialRecordingSegmentsQuery,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { HomeAssistant } from 'custom-card-helpers';
|
||||
import { CameraConfig, CamerasConfig, CardWideConfig } from '../types.js';
|
||||
import {
|
||||
CameraConfig,
|
||||
CamerasConfig,
|
||||
CardWideConfig,
|
||||
} from '../types.js';
|
||||
import { allPromises, arrayify, setify } from '../utils/basic.js';
|
||||
import {
|
||||
CameraManagerCameraCapabilities,
|
||||
@@ -46,7 +50,7 @@ import { EntityRegistryManager } from '../utils/ha/entity-registry/index.js';
|
||||
import { getCameraID } from '../utils/camera.js';
|
||||
import { localize } from '../localize/localize.js';
|
||||
import { CameraInitializationError } from './error.js';
|
||||
import { CameraManagerStore } from './store.js';
|
||||
import { CameraManagerReadOnlyConfigStore, CameraManagerStore } from './store.js';
|
||||
import cloneDeep from 'lodash-es/cloneDeep';
|
||||
import { MEDIA_CHUNK_SIZE_DEFAULT } from '../const.js';
|
||||
|
||||
@@ -126,14 +130,18 @@ export class CameraManager {
|
||||
const output: Map<CameraConfig, CameraManagerEngine> = new Map();
|
||||
const engines: Map<Engine, CameraManagerEngine> = new Map();
|
||||
|
||||
for (const cameraConfig of camerasConfig) {
|
||||
const engineType = await this._engineFactory.getEngineForCamera(
|
||||
hass,
|
||||
cameraConfig,
|
||||
const getEngineTypes = async (configs: CameraConfig[]) => {
|
||||
return await allPromises(configs, (config) =>
|
||||
this._engineFactory.getEngineForCamera(hass, config),
|
||||
);
|
||||
};
|
||||
|
||||
const engineTypes = await getEngineTypes(camerasConfig);
|
||||
for (const [index, cameraConfig] of camerasConfig.entries()) {
|
||||
const engineType = engineTypes[index];
|
||||
const engine = engineType
|
||||
? engines.get(engineType) ?? this._engineFactory.createEngine(engineType)
|
||||
: null;
|
||||
? engines.get(engineType) ?? this._engineFactory.createEngine(engineType)
|
||||
: null;
|
||||
if (!engine || !engineType) {
|
||||
throw new CameraInitializationError(
|
||||
localize('error.no_camera_engine'),
|
||||
@@ -218,8 +226,8 @@ export class CameraManager {
|
||||
this._store.addCamera(id, result.initializedConfig, result.engine);
|
||||
});
|
||||
|
||||
if (!this._store.getCameraCount()) {
|
||||
throw new CameraInitializationError(localize('error.no_cameras'));
|
||||
if (!this._store.getVisibleCameraCount()) {
|
||||
throw new CameraInitializationError(localize('error.no_visible_cameras'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,22 +235,8 @@ export class CameraManager {
|
||||
return this._store.getCameraCount() > 0;
|
||||
}
|
||||
|
||||
public getCameras(): Map<string, CameraConfig> | null {
|
||||
return this._store.getCameras();
|
||||
}
|
||||
|
||||
public getCameraConfig(cameraID: string): CameraConfig | null {
|
||||
return this._store.getCameraConfig(cameraID);
|
||||
}
|
||||
|
||||
public getCameraIDs(): Set<string> | null {
|
||||
return this._store.getCameraCount()
|
||||
? new Set(this._store.getCameras().keys())
|
||||
: null;
|
||||
}
|
||||
|
||||
public hasCameraID(cameraID: string): boolean {
|
||||
return this._store.hasCameraID(cameraID);
|
||||
public getStore(): CameraManagerReadOnlyConfigStore {
|
||||
return this._store;
|
||||
}
|
||||
|
||||
public generateDefaultEventQueries(
|
||||
@@ -287,7 +281,7 @@ export class CameraManager {
|
||||
|
||||
const results = await this._handleQuery(hass, query);
|
||||
|
||||
for (const [query, result] of results?.entries() ?? []) {
|
||||
for (const result of results?.values() ?? []) {
|
||||
if (result.metadata.what) {
|
||||
result.metadata.what.forEach(what.add, what);
|
||||
}
|
||||
@@ -325,19 +319,19 @@ export class CameraManager {
|
||||
let queries: DataQuery[] | null = null;
|
||||
if (QueryClassifier.isEventQuery(partialQuery)) {
|
||||
queries = engine.generateDefaultEventQuery(
|
||||
this._store.getCameras(),
|
||||
this._store.getVisibleCameras(),
|
||||
cameraIDs,
|
||||
partialQuery,
|
||||
);
|
||||
} else if (QueryClassifier.isRecordingQuery(partialQuery)) {
|
||||
queries = engine.generateDefaultRecordingQuery(
|
||||
this._store.getCameras(),
|
||||
this._store.getVisibleCameras(),
|
||||
cameraIDs,
|
||||
partialQuery,
|
||||
);
|
||||
} else if (QueryClassifier.isRecordingSegmentsQuery(partialQuery)) {
|
||||
queries = engine.generateDefaultRecordingSegmentsQuery(
|
||||
this._store.getCameras(),
|
||||
this._store.getVisibleCameras(),
|
||||
cameraIDs,
|
||||
partialQuery,
|
||||
);
|
||||
|
||||
+43
-10
@@ -5,8 +5,26 @@ import { CameraConfigs, Engine } from './types';
|
||||
|
||||
type CameraManagerEngineCameraIDMap = Map<CameraManagerEngine, Set<string>>;
|
||||
|
||||
export class CameraManagerStore {
|
||||
protected _configs: Map<string, CameraConfig> = new Map();
|
||||
export interface CameraManagerReadOnlyConfigStore {
|
||||
getCameraConfig(cameraID: string): CameraConfig | null;
|
||||
getCameraConfigForMedia(media: ViewMedia): CameraConfig | null;
|
||||
|
||||
hasCameraID(cameraID: string): boolean;
|
||||
hasVisibleCameraID(cameraID: string): boolean;
|
||||
|
||||
getCameraCount(): number;
|
||||
getVisibleCameraCount(): number;
|
||||
|
||||
getCameras(): CameraConfigs;
|
||||
getVisibleCameras(): CameraConfigs;
|
||||
|
||||
getCameraIDs(): Set<string>;
|
||||
getVisibleCameraIDs(): Set<string>;
|
||||
}
|
||||
|
||||
export class CameraManagerStore implements CameraManagerReadOnlyConfigStore {
|
||||
protected _allConfigs: Map<string, CameraConfig> = new Map();
|
||||
protected _visibleConfigs: Map<string, CameraConfig> = new Map();
|
||||
protected _enginesByCamera: Map<string, CameraManagerEngine> = new Map();
|
||||
protected _enginesByType: Map<Engine, CameraManagerEngine> = new Map();
|
||||
|
||||
@@ -15,29 +33,44 @@ export class CameraManagerStore {
|
||||
cameraConfig: CameraConfig,
|
||||
engine: CameraManagerEngine,
|
||||
): void {
|
||||
this._configs.set(cameraID, cameraConfig);
|
||||
if (!cameraConfig.hide) {
|
||||
this._visibleConfigs.set(cameraID, cameraConfig);
|
||||
}
|
||||
this._allConfigs.set(cameraID, cameraConfig);
|
||||
this._enginesByCamera.set(cameraID, engine);
|
||||
this._enginesByType.set(engine.getEngineType(), engine);
|
||||
}
|
||||
|
||||
public getCameraCount(): number {
|
||||
return this._configs.size;
|
||||
public getCameraConfig(cameraID: string): CameraConfig | null {
|
||||
return this._allConfigs.get(cameraID) ?? null;
|
||||
}
|
||||
|
||||
public hasCameraID(cameraID: string): boolean {
|
||||
return this._configs.has(cameraID);
|
||||
return this._allConfigs.has(cameraID);
|
||||
}
|
||||
public hasVisibleCameraID(cameraID: string): boolean {
|
||||
return this._visibleConfigs.has(cameraID);
|
||||
}
|
||||
|
||||
public getCameraConfig(cameraID: string): CameraConfig | null {
|
||||
return this._configs.get(cameraID) ?? null;
|
||||
public getCameraCount(): number {
|
||||
return this._allConfigs.size;
|
||||
}
|
||||
public getVisibleCameraCount(): number {
|
||||
return this._visibleConfigs.size;
|
||||
}
|
||||
|
||||
public getCameras(): CameraConfigs {
|
||||
return this._configs;
|
||||
return this._allConfigs;
|
||||
}
|
||||
public getVisibleCameras(): CameraConfigs {
|
||||
return this._visibleConfigs;
|
||||
}
|
||||
|
||||
public getCameraIDs(): Set<string> {
|
||||
return new Set(this._configs.keys());
|
||||
return new Set(this._allConfigs.keys());
|
||||
}
|
||||
public getVisibleCameraIDs(): Set<string> {
|
||||
return new Set(this._visibleConfigs.keys());
|
||||
}
|
||||
|
||||
public getCameraConfigForMedia(media: ViewMedia): CameraConfig | null {
|
||||
|
||||
Reference in New Issue
Block a user