-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
73 lines (60 loc) · 3.19 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const Homey = require('homey');
const Util = require('./lib/util.js');
class IpwebcamApp extends Homey.App {
onInit() {
this.log('Initializing Android IP Webcam app ...');
if (!this.util) this.util = new Util({homey: this.homey });
this.homey.flow.getActionCard('emailsnapshot')
.registerRunListener(async (args) => {
try {
const image = await this.util.getBufferSnapshot('http://'+ args.device.getSetting('address') +':'+ args.device.getSetting('port') +'/shot.jpg', args.device.getSetting('username'), args.device.getSetting('password'), 'buffer');
return await this.util.sendSnapshot(image, args);
} catch (error) {
return Promise.reject(error);
}
});
this.homey.flow.getActionCard('sensor_threshold')
.registerRunListener(async (args) => {
if(args.sensor_type == 'motion') {
var path = "settings/motion_limit?set=" + args.threshold;
} else if (args.sensor_type == 'sound') {
var path = "settings/adet_limit?set=" + args.threshold;
}
return await this.util.singleCommand(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args, path);
});
this.homey.flow.getActionCard('nightvision')
.registerRunListener(async (args) => {
return await this.util.nightvision(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args);
});
this.homey.flow.getActionCard('zoom')
.registerRunListener(async (args) => {
var path = "ptz?zoom=" + args.zoom;
return await this.util.singleCommand(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args, path);
});
this.homey.flow.getActionCard('quality')
.registerRunListener(async (args) => {
var path = "settings/quality?set=" + args.quality;
return await this.util.singleCommand(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args, path);
});
this.homey.flow.getActionCard('led')
.registerRunListener(async (args) => {
if(args.led == 'on') {
var path = "enabletorch";
} else if (args.led == 'off') {
var path = "disabletorch";
}
return await this.util.singleCommand(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args, path);
});
this.homey.flow.getActionCard('whichcamera')
.registerRunListener(async (args) => {
if(args.whichcamera == 'on') {
var path = "settings/ffc?set=on";
} else if (args.whichcamera == 'off') {
var path = "settings/ffc?set=off";
}
return await this.util.singleCommand(args.device.getSetting('address'), args.device.getSetting('port'), args.device.getSetting('username'), args.device.getSetting('password'), args, path);
});
}
}
module.exports = IpwebcamApp;