chronograph-npm 0.0.1 → 0.0.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 ADDED
@@ -0,0 +1,18 @@
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;
16
+ }
17
+ export { CG as SL };
18
+ //# sourceMappingURL=cg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cg.d.ts","sourceRoot":"","sources":["../src/cg.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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "chronograph-npm",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "The Chronograph App for Athom's Homey",
5
- "main": "src/sl.js",
6
- "types": "./dist/sl.d.ts",
5
+ "main": "src/cg.js",
6
+ "types": "./dist/cg.d.ts",
7
7
  "scripts": {
8
8
  "prepublishOnly": "echo \"Running TS defs\" && npx tsc",
9
9
  "postinstall": "echo ________________________________________________________________________________________________________________________ && echo \"\" && echo Chronograph && echo Remember to add Chronograph to the permissions in your app.json: \"permissions\": [\"homey:app:nl.fellownet.chronograph\"] && echo ________________________________________________________________________________________________________________________"
package/src/cg.js ADDED
@@ -0,0 +1,100 @@
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
+
96
+ }
97
+
98
+
99
+
100
+ module.exports = { SL: CG };
package/dist/sl.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export class SL {
2
- }
3
- //# sourceMappingURL=sl.d.ts.map
package/dist/sl.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"sl.d.ts","sourceRoot":"","sources":["../src/sl.js"],"names":[],"mappings":"AAAA;CACC"}
package/src/sl.js DELETED
@@ -1,6 +0,0 @@
1
- class SL {
2
- }
3
-
4
-
5
-
6
- module.exports = { SL };