Implement detection timeout
This commit is contained in:
parent
9316028e2c
commit
4be1c53807
@ -3,7 +3,7 @@ import * as path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
// SsdMobilenetv1Options
|
||||
export const minConfidence = 0.5;
|
||||
export const minConfidence = 0.4;
|
||||
|
||||
// TinyFaceDetectorOptions
|
||||
export const inputSize = 408;
|
||||
|
@ -7,13 +7,20 @@ import { Monitor, IStateChangeEventArgs } from "./monitor/monitor";
|
||||
import { HomeLocationPlatform } from "./homeLocationPlatform";
|
||||
import { IRoom } from "./config";
|
||||
|
||||
const defaultDetectionTimeout = 180000;
|
||||
|
||||
interface IMotionDetectionService {
|
||||
service: Service;
|
||||
detectionTimeout: NodeJS.Timeout | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform Accessory
|
||||
* An instance of this class is created for each accessory your platform registers
|
||||
* Each accessory may expose multiple services of different service types.
|
||||
*/
|
||||
export class LocationAccessory {
|
||||
private _services: Array<Service>;
|
||||
private _services: Array<IMotionDetectionService>;
|
||||
|
||||
constructor(
|
||||
private readonly _platform: HomeLocationPlatform,
|
||||
@ -54,7 +61,10 @@ export class LocationAccessory {
|
||||
this.onMotionDetectedGet(label, callback)
|
||||
);
|
||||
|
||||
this._services.push(newService);
|
||||
this._services.push({
|
||||
service: newService,
|
||||
detectionTimeout: null,
|
||||
});
|
||||
}
|
||||
|
||||
//Register monitor state change events
|
||||
@ -78,14 +88,31 @@ export class LocationAccessory {
|
||||
sender: Monitor,
|
||||
args: IStateChangeEventArgs
|
||||
) => {
|
||||
const service = this._services.find(
|
||||
(service) => service.displayName == args.label
|
||||
const motionService = this._services.find(
|
||||
(motionService) => motionService.service.displayName == args.label
|
||||
);
|
||||
if (service) {
|
||||
service.setCharacteristic(
|
||||
if (motionService) {
|
||||
//Set accessory state
|
||||
motionService.service.setCharacteristic(
|
||||
this._platform.Characteristic.MotionDetected,
|
||||
args.new === this._room.name
|
||||
);
|
||||
|
||||
//Reset detectionTimeout
|
||||
clearTimeout(motionService.detectionTimeout!);
|
||||
motionService.detectionTimeout = setTimeout(
|
||||
() => this.onDetectionTimeout(motionService),
|
||||
this._platform.config.detectionTimeout ?? defaultDetectionTimeout
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private onDetectionTimeout = (motionService: IMotionDetectionService) => {
|
||||
//Set accessory state
|
||||
motionService.service.setCharacteristic(
|
||||
this._platform.Characteristic.MotionDetected,
|
||||
0
|
||||
);
|
||||
this._monitor.resetState(motionService.service.displayName);
|
||||
};
|
||||
}
|
||||
|
@ -66,6 +66,11 @@ export class Monitor {
|
||||
return this._state[label];
|
||||
}
|
||||
|
||||
public resetState(label: string): Monitor {
|
||||
this._state[label] = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property labels
|
||||
*
|
||||
@ -89,7 +94,7 @@ export class Monitor {
|
||||
*
|
||||
* Starts monitoring rtsp streams
|
||||
*/
|
||||
public startStreams() {
|
||||
public startStreams(): Monitor {
|
||||
for (const key in this._streamsByRoom) {
|
||||
for (const stream of this._streamsByRoom[key]) {
|
||||
//Start stream
|
||||
@ -102,6 +107,8 @@ export class Monitor {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +116,7 @@ export class Monitor {
|
||||
*
|
||||
* Stops monitoring rtsp streams
|
||||
*/
|
||||
public closeStreams() {
|
||||
public closeStreams(): Monitor {
|
||||
for (const key in this._streamsByRoom) {
|
||||
for (const stream of this._streamsByRoom[key]) {
|
||||
stream.rtsp.close();
|
||||
@ -120,6 +127,8 @@ export class Monitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private onData = async (
|
||||
@ -178,18 +187,19 @@ export class Monitor {
|
||||
stream.rtsp.dataEvent.push((sender: Rtsp, args: IStreamEventArgs) =>
|
||||
this.onData(roomName, stream, args)
|
||||
);
|
||||
stream.rtsp.closeEvent.push((sender: Rtsp, args: ICloseEventArgs) => {
|
||||
this._logger.info(
|
||||
`[${connectionString}] Stream has exited: ${args.message}`
|
||||
);
|
||||
});
|
||||
stream.rtsp.errorEvent.push((sender: Rtsp, args: IErrorEventArgs) => {
|
||||
this._logger.info(`[${connectionString}] ${args.message}`);
|
||||
});
|
||||
//Only subscribe to these events if debug
|
||||
if (this._config.debug) {
|
||||
stream.rtsp.messageEvent.push((sender: Rtsp, args: IMessageEventArgs) => {
|
||||
this._logger.info(`[${connectionString}] ${args.message}`);
|
||||
});
|
||||
stream.rtsp.errorEvent.push((sender: Rtsp, args: IErrorEventArgs) => {
|
||||
this._logger.info(`[${connectionString}] ${args.message}`);
|
||||
});
|
||||
stream.rtsp.closeEvent.push((sender: Rtsp, args: ICloseEventArgs) => {
|
||||
this._logger.info(
|
||||
`[${connectionString}] Stream has exited: ${args.message}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
Loading…
Reference in New Issue
Block a user