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