forked from mykle1/MMM-FMI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.js
More file actions
74 lines (56 loc) · 2.22 KB
/
node_helper.js
File metadata and controls
74 lines (56 loc) · 2.22 KB
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
74
const NodeHelper = require('node_helper');
var icloud = require("find-my-iphone").findmyphone;
module.exports = NodeHelper.create({
start: function() {
console.log("Starting module: " + this.name);
},
getFMI: function(url) {
var self = this;
var distance = '';
var duration = '';
var location = '';
icloud.apple_id = this.config.email; //this.config.login
icloud.password = this.config.pass; //this.config.pass
icloud.getDevices(function(error, devices) {
var device;
self.sendSocketNotification('FMI_DISTANCE', devices);
console.log(devices);
if (error) {
throw error;
}
//pick a device with location and findMyPhone enabled
devices.forEach(function(d) {
if (device == undefined && d.location && d.lostModeCapable) {
device = d;
}
});
if (device) {
//gets the distance of the device from my location
var myLatitude = this.config.lat;
var myLongitude = this.config.lon;
var result;
icloud.getDistanceOfDevice(device, myLatitude, myLongitude, function(err, result) {
// console.log("Distance: " + result); // result.distance.text);
// console.log("Driving time: " + result); // result.duration.text);
// self.sendSocketNotification('FMI_DISTANCE', {result});
});
icloud.alertDevice(device.id, function(err) {
console.log("Beep Beep!");
// self.sendSocketNotification('FMI_RESULT', result);
});
icloud.getLocationOfDevice(device, function(err, location) {
// console.log(location);
// self.sendSocketNotification('FMI_LOCATION', {location});
});
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG'){
this.config = payload;
} else if (notification === 'GET_FMI') {
this.getFMI(payload);
}
}
});