chronograph-npm 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cg.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cg.js +39 -31
package/dist/cg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cg.d.ts","sourceRoot":"","sources":["../src/cg.js"],"names":[],"mappings":"AAAA;IAGI;;
|
|
1
|
+
{"version":3,"file":"cg.d.ts","sourceRoot":"","sources":["../src/cg.js"],"names":[],"mappings":"AAAA;IAGI;;oBAyBC;IA+BD,uBAQC;IAuCD,0CAEC;IAED,uCAEC;IAKD;;;OAGG;IACH,gEAGC;IA/FD;;OAWC;IATG,WAA6B;IAC7B,iBAAoB;IAIpB,WAAyC;IAM7C,2BAaC;IAVW,SAAqC;IAyBjD,uDAcC;IAGD,eAAe;IACf,kBAeC;CAyBJ"}
|
package/package.json
CHANGED
package/src/cg.js
CHANGED
|
@@ -4,21 +4,22 @@ class CG {
|
|
|
4
4
|
static async init({ homey } = {}) {
|
|
5
5
|
let cg = new CG({ homey });
|
|
6
6
|
|
|
7
|
-
homey.app.__CG_OnUninit
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
if (!homey.app.__CG_OnUninit) {
|
|
8
|
+
homey.app.__CG_OnUninit = homey.app.onUninit;
|
|
9
|
+
homey.app.onUninit = async function (args) {
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
if (CG) await CG.destroy();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.log(error);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (args) await CG.homey.__CG_OnUninit(...args); else await CG.homey.__CG_OnUninit();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
let a = error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
22
23
|
try {
|
|
23
24
|
await cg.init();
|
|
24
25
|
} catch (error) {
|
|
@@ -26,16 +27,16 @@ class CG {
|
|
|
26
27
|
}
|
|
27
28
|
return cg;
|
|
28
29
|
}
|
|
29
|
-
constructor({homey}) {
|
|
30
|
+
constructor({ homey }) {
|
|
30
31
|
CG.Current = this;
|
|
31
32
|
this.homey = CG.homey = homey;
|
|
32
33
|
this.isReady = false;
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
CG._defer = new Defer();
|
|
35
|
-
|
|
36
|
-
this.ready = CG.ready = CG._defer.promise;
|
|
37
|
-
CG.ready.then(() => {
|
|
38
|
-
CG.isReady = this.isReady = true;
|
|
36
|
+
|
|
37
|
+
this.ready = CG.ready = CG._defer.promise;
|
|
38
|
+
CG.ready.then(() => {
|
|
39
|
+
CG.isReady = this.isReady = true;
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -45,7 +46,7 @@ class CG {
|
|
|
45
46
|
this.api = await this.getAppApi(true);
|
|
46
47
|
this.api.on('realtime', this.realtimeFunction);
|
|
47
48
|
await this.api.get('/chronographs')
|
|
48
|
-
if(!CG.isReady && CG._defer) CG._defer.resolve();
|
|
49
|
+
if (!CG.isReady && CG._defer) CG._defer.resolve();
|
|
49
50
|
} catch (error) {
|
|
50
51
|
this.homey.error('CG.init', error);
|
|
51
52
|
return this;
|
|
@@ -68,11 +69,18 @@ class CG {
|
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
async realtimeFunction(event, data) {
|
|
71
|
-
if(!CG.isReady && CG._defer) CG._defer.resolve();
|
|
72
|
+
if (!CG.isReady && CG._defer) CG._defer.resolve();
|
|
72
73
|
|
|
73
74
|
if (event === 'chronograph_event') {
|
|
74
|
-
if(data && data.now) data.now = new Date(data.now);
|
|
75
|
-
CG.onChronographUpdate({chronograph:data});
|
|
75
|
+
if (data && data.now) data.now = new Date(data.now);
|
|
76
|
+
CG.onChronographUpdate({ chronograph: data });
|
|
77
|
+
} else if (event === 'chronograph_event_multi') {
|
|
78
|
+
if (data && data.length) for (let i = 0; i < data.length; i++) {
|
|
79
|
+
const chronograph = data[i];
|
|
80
|
+
if (chronograph && chronograph.now) chronograph.now = new Date(chronograph.now);
|
|
81
|
+
CG.onChronographUpdate({ chronograph });
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
|
|
@@ -95,25 +103,25 @@ class CG {
|
|
|
95
103
|
return this.api;
|
|
96
104
|
}
|
|
97
105
|
|
|
98
|
-
|
|
106
|
+
|
|
99
107
|
static async getAllChronographs() {
|
|
100
|
-
if(CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/allchronographs')
|
|
108
|
+
if (CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/allchronographs')
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
static async getChronographs() {
|
|
104
|
-
if(CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/chronographs')
|
|
112
|
+
if (CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/chronographs')
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
|
|
110
118
|
/**
|
|
111
119
|
* @description Setable member, when set, will be activated on any variable update.
|
|
112
120
|
* @param {Object} param0.variable
|
|
113
121
|
*/
|
|
114
|
-
static async onChronographUpdate({chronograph}) {
|
|
122
|
+
static async onChronographUpdate({ chronograph }) {
|
|
115
123
|
//BL.homey.log('onChronographUpdate: ', chronograph);
|
|
116
|
-
|
|
124
|
+
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
|