mirror of
https://github.com/koush/scrypted.git
synced 2026-06-20 08:30:30 +01:00
sdk: update with createdDevice string
This commit is contained in:
@@ -1013,6 +1013,51 @@ export class ObjectDetectionPlugin extends AutoenableMixinProvider implements Se
|
||||
cpuTimer = new CpuTimer();
|
||||
cpuUsage = 0;
|
||||
|
||||
constructor(nativeId?: ScryptedNativeId) {
|
||||
super(nativeId, 'v5');
|
||||
|
||||
this.createdDeviceName = 'Smart Motion Sensor';
|
||||
|
||||
process.nextTick(() => {
|
||||
sdk.deviceManager.onDeviceDiscovered({
|
||||
name: 'FFmpeg Frame Generator',
|
||||
type: ScryptedDeviceType.Builtin,
|
||||
interfaces: [
|
||||
ScryptedInterface.VideoFrameGenerator,
|
||||
],
|
||||
nativeId: 'ffmpeg',
|
||||
})
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
this.cpuUsage = this.cpuTimer.sample();
|
||||
// this.console.log('cpu usage', Math.round(this.cpuUsage * 100));
|
||||
|
||||
const runningDetections = this.runningObjectDetections;
|
||||
|
||||
let allowStart = 2;
|
||||
// always allow 2 cameras to push past cpu throttling
|
||||
if (runningDetections.length > 2) {
|
||||
const cpuPerDetector = this.cpuUsage / runningDetections.length;
|
||||
allowStart = Math.ceil(1 / cpuPerDetector) - runningDetections.length;
|
||||
if (allowStart <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
const idleDetectors = [...this.currentMixins.values()]
|
||||
.map(d => [...d.currentMixins.values()].filter(dd => !dd.hasMotionType)).flat()
|
||||
.filter(c => !c.detectorRunning);
|
||||
|
||||
for (const notRunning of idleDetectors) {
|
||||
if (notRunning.maybeStartDetection()) {
|
||||
allowStart--;
|
||||
if (allowStart <= 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 10000)
|
||||
}
|
||||
|
||||
pruneOldStatistics() {
|
||||
const now = Date.now();
|
||||
for (const [k, v] of this.objectDetectionStatistics.entries()) {
|
||||
@@ -1101,49 +1146,6 @@ export class ObjectDetectionPlugin extends AutoenableMixinProvider implements Se
|
||||
this.statsSnapshotTime = now;
|
||||
}
|
||||
|
||||
constructor(nativeId?: ScryptedNativeId) {
|
||||
super(nativeId, 'v5');
|
||||
|
||||
process.nextTick(() => {
|
||||
sdk.deviceManager.onDeviceDiscovered({
|
||||
name: 'FFmpeg Frame Generator',
|
||||
type: ScryptedDeviceType.Builtin,
|
||||
interfaces: [
|
||||
ScryptedInterface.VideoFrameGenerator,
|
||||
],
|
||||
nativeId: 'ffmpeg',
|
||||
})
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
this.cpuUsage = this.cpuTimer.sample();
|
||||
// this.console.log('cpu usage', Math.round(this.cpuUsage * 100));
|
||||
|
||||
const runningDetections = this.runningObjectDetections;
|
||||
|
||||
let allowStart = 2;
|
||||
// always allow 2 cameras to push past cpu throttling
|
||||
if (runningDetections.length > 2) {
|
||||
const cpuPerDetector = this.cpuUsage / runningDetections.length;
|
||||
allowStart = Math.ceil(1 / cpuPerDetector) - runningDetections.length;
|
||||
if (allowStart <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
const idleDetectors = [...this.currentMixins.values()]
|
||||
.map(d => [...d.currentMixins.values()].filter(dd => !dd.hasMotionType)).flat()
|
||||
.filter(c => !c.detectorRunning);
|
||||
|
||||
for (const notRunning of idleDetectors) {
|
||||
if (notRunning.maybeStartDetection()) {
|
||||
allowStart--;
|
||||
if (allowStart <= 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, 10000)
|
||||
}
|
||||
|
||||
async getDevice(nativeId: string): Promise<any> {
|
||||
let ret: any;
|
||||
if (nativeId === 'ffmpeg')
|
||||
|
||||
@@ -982,6 +982,7 @@ class ColorSettingTemperature:
|
||||
class DeviceCreator:
|
||||
"""A DeviceProvider that allows the user to create a device."""
|
||||
|
||||
createdDevice: str # Type of device that will be created by this DeviceCreator. For example: Example Corp Camera or ACME Light Switch.
|
||||
async def createDevice(self, settings: DeviceCreatorSettings) -> str:
|
||||
pass
|
||||
|
||||
@@ -1756,6 +1757,7 @@ class ScryptedInterfaceProperty(str, Enum):
|
||||
ptzCapabilities = "ptzCapabilities"
|
||||
lockState = "lockState"
|
||||
entryOpen = "entryOpen"
|
||||
createdDevice = "createdDevice"
|
||||
batteryLevel = "batteryLevel"
|
||||
chargeState = "chargeState"
|
||||
online = "online"
|
||||
@@ -2151,6 +2153,14 @@ class DeviceState:
|
||||
def entryOpen(self, value: bool | Any):
|
||||
self.setScryptedProperty("entryOpen", value)
|
||||
|
||||
@property
|
||||
def createdDevice(self) -> str:
|
||||
return self.getScryptedProperty("createdDevice")
|
||||
|
||||
@createdDevice.setter
|
||||
def createdDevice(self, value: str):
|
||||
self.setScryptedProperty("createdDevice", value)
|
||||
|
||||
@property
|
||||
def batteryLevel(self) -> float:
|
||||
return self.getScryptedProperty("batteryLevel")
|
||||
@@ -2717,7 +2727,9 @@ ScryptedInterfaceDescriptors = {
|
||||
"createDevice",
|
||||
"getCreateDeviceSettings"
|
||||
],
|
||||
"properties": []
|
||||
"properties": [
|
||||
"createdDevice"
|
||||
]
|
||||
},
|
||||
"Battery": {
|
||||
"name": "Battery",
|
||||
|
||||
@@ -1037,6 +1037,11 @@ export interface DeviceCreator {
|
||||
* Return the id of the created device.
|
||||
*/
|
||||
createDevice(settings: DeviceCreatorSettings): Promise<string>;
|
||||
/**
|
||||
* Type of device that will be created by this DeviceCreator.
|
||||
* For example: Example Corp Camera or ACME Light Switch.
|
||||
*/
|
||||
createdDevice?: string;
|
||||
}
|
||||
export interface DiscoveredDevice {
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user