chronograph-npm 0.1.1 → 0.1.2
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 +32 -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;IAgCD,0CAEC;IAED,uCAEC;IAKD;;;OAGG;IACH,gEAGC;IAxFD;;OAWC;IATG,WAA6B;IAC7B,iBAAoB;IAIpB,WAAyC;IAM7C,2BAaC;IAVW,SAAqC;IAyBjD,uDAOC;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,11 @@ 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 });
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -95,25 +96,25 @@ class CG {
|
|
|
95
96
|
return this.api;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
|
|
99
100
|
static async getAllChronographs() {
|
|
100
|
-
if(CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/allchronographs')
|
|
101
|
+
if (CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/allchronographs')
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
static async getChronographs() {
|
|
104
|
-
if(CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/chronographs')
|
|
105
|
+
if (CG && CG.Current && CG.Current.api) return await CG.Current.api.get('/chronographs')
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
|
|
110
111
|
/**
|
|
111
112
|
* @description Setable member, when set, will be activated on any variable update.
|
|
112
113
|
* @param {Object} param0.variable
|
|
113
114
|
*/
|
|
114
|
-
static async onChronographUpdate({chronograph}) {
|
|
115
|
+
static async onChronographUpdate({ chronograph }) {
|
|
115
116
|
//BL.homey.log('onChronographUpdate: ', chronograph);
|
|
116
|
-
|
|
117
|
+
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
|