chronograph-npm 0.0.1 → 0.0.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/sl.d.ts +16 -1
- package/dist/sl.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sl.js +96 -2
package/dist/sl.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
declare class CG {
|
|
2
|
+
static init({ homey }?: {
|
|
3
|
+
homey: any;
|
|
4
|
+
}): Promise<CG>;
|
|
5
|
+
static detroy(): void;
|
|
6
|
+
/**
|
|
7
|
+
* @override Setable member, when set, will be activated on any variable update.
|
|
8
|
+
* @param {Object} param0.variable
|
|
9
|
+
*/
|
|
10
|
+
static override onChronographUpdate({ chronograph }: any): Promise<void>;
|
|
11
|
+
init({}?: {}): Promise<CG>;
|
|
12
|
+
api: any;
|
|
13
|
+
realtimeFunction(event: any, data: any): Promise<void>;
|
|
14
|
+
/** @private */
|
|
15
|
+
private getAppApi;
|
|
2
16
|
}
|
|
17
|
+
export { CG as SL };
|
|
3
18
|
//# sourceMappingURL=sl.d.ts.map
|
package/dist/sl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sl.d.ts","sourceRoot":"","sources":["../src/sl.js"],"names":[],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"file":"sl.d.ts","sourceRoot":"","sources":["../src/sl.js"],"names":[],"mappings":"AAAA;IAGI;;oBAyBC;IAgBD,sBAQC;IAgCD;;;OAGG;IACH,yEAGC;IA7DD,2BAUC;IAPW,SAAqC;IAsBjD,uDAMC;IAGD,eAAe;IACf,kBAeC;CAeJ"}
|
package/package.json
CHANGED
package/src/sl.js
CHANGED
|
@@ -1,6 +1,100 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CG {
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
static async init({ homey } = {}) {
|
|
5
|
+
let cg = new CG({ homey });
|
|
6
|
+
CG.Current = cg;
|
|
7
|
+
|
|
8
|
+
homey.app.__CG_OnUninit = homey.app.onUninit;
|
|
9
|
+
homey.app.onUninit = async function (args) {
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
if (CG.Current) await CG.Current.detroy();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.log(error);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (args) await this.__CG_OnUninit(...args); else await this.__CG_OnUninit();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
let a = error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
return await cg.init();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
return cg;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async init({ } = {}) {
|
|
32
|
+
if (!this.api) {
|
|
33
|
+
try {
|
|
34
|
+
this.api = await this.getAppApi(true);
|
|
35
|
+
this.api.on('realtime', this.realtimeFunction);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.homey.error('CG.init', error);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
static detroy() {
|
|
46
|
+
try {
|
|
47
|
+
if (!CG.Current) return;
|
|
48
|
+
if (CG.Current.api) {
|
|
49
|
+
CG.Current.api.off('realtime', CG.Current.realtimeFunction);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} catch (error) { console.log(error); }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async realtimeFunction(event, data) {
|
|
57
|
+
let reload = false;
|
|
58
|
+
if (event === 'chronograph_changed') {
|
|
59
|
+
CG.onChronographUpdate(data);
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
/** @private */
|
|
66
|
+
async getAppApi(onlyApi) {
|
|
67
|
+
try {
|
|
68
|
+
if (!this.api) this.api = this.homey.api.getApiApp('nl.fellownet.chronograph');
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw new Error(error);
|
|
71
|
+
}
|
|
72
|
+
if (onlyApi === true) return this.api;
|
|
73
|
+
if (!this.api) throw new Error('Chronograph is not installed.');
|
|
74
|
+
else {
|
|
75
|
+
try {
|
|
76
|
+
BL._isLoaded = await this.api.getInstalled();
|
|
77
|
+
} catch (error) { }
|
|
78
|
+
if (!BL._isLoaded) throw new Error('Chronograph is not installed.');
|
|
79
|
+
}
|
|
80
|
+
return this.api;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @override Setable member, when set, will be activated on any variable update.
|
|
87
|
+
* @param {Object} param0.variable
|
|
88
|
+
*/
|
|
89
|
+
static async onChronographUpdate({chronograph}) {
|
|
90
|
+
BL.homey.log('onChronographUpdate: ', chronograph);
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
2
96
|
}
|
|
3
97
|
|
|
4
98
|
|
|
5
99
|
|
|
6
|
-
module.exports = { SL };
|
|
100
|
+
module.exports = { SL: CG };
|