homebridge-smartsystem 6.1.7 → 6.2.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/README.md +14 -0
- package/accessories/accessory.js +4 -4
- package/accessories/accessory.ts +1 -2
- package/accessories/dimmer.js +6 -6
- package/accessories/dimmer.ts +1 -1
- package/accessories/door.js +2 -2
- package/accessories/door.ts +1 -1
- package/accessories/garagedoor.js +5 -4
- package/accessories/garagedoor.ts +2 -1
- package/accessories/lock.js +6 -5
- package/accessories/lock.ts +2 -1
- package/accessories/mood.js +2 -1
- package/accessories/mood.ts +2 -1
- package/accessories/temperature.js +2 -2
- package/accessories/temperature.ts +1 -1
- package/accessories/windowcovering.js +8 -7
- package/accessories/windowcovering.ts +2 -1
- package/config.json +169 -228
- package/config.smappee.json +178 -2
- package/config.smartapp.json +63 -0
- package/duotecno/Q.js +8 -8
- package/duotecno/Q.ts +1 -1
- package/duotecno/api.js +3 -3
- package/duotecno/api.ts +2 -2
- package/duotecno/config.js +24 -23
- package/duotecno/config.ts +23 -16
- package/duotecno/logger.js +51 -0
- package/duotecno/logger.ts +41 -0
- package/duotecno/master.js +4 -6
- package/duotecno/master.ts +2 -4
- package/duotecno/protocol.js +10 -9
- package/duotecno/protocol.ts +2 -1
- package/duotecno/system.js +17 -41
- package/duotecno/system.ts +7 -34
- package/duotecno/types.js +58 -131
- package/duotecno/types.ts +65 -125
- package/index.spec.js +22 -36
- package/index.spec.ts +20 -33
- package/package.json +2 -2
- package/server/base.js +10 -38
- package/server/base.ts +9 -42
- package/server/p1.js +9 -8
- package/server/p1.ts +6 -4
- package/server/platform.js +66 -36
- package/server/platform.ts +47 -12
- package/server/powerbase.js +15 -55
- package/server/powerbase.ts +4 -50
- package/server/shelly.js +4 -4
- package/server/shelly.ts +3 -2
- package/server/smappee.js +9 -8
- package/server/smappee.ts +4 -3
- package/server/smartapp.js +94 -39
- package/server/smartapp.ts +73 -20
- package/server/socapp.js +6 -6
- package/server/socapp.ts +2 -1
- package/server/somfy.js +12 -12
- package/server/somfy.ts +1 -1
- package/server/support.js +13 -13
- package/server/support.ts +4 -4
- package/server/views/style.ejs +1 -0
- package/server/views/switch-details.ejs +15 -5
- package/server/webapp.js +45 -47
- package/server/webapp.ts +29 -38
- package/config.groups.json +0 -8
- package/config.p1-dev.json +0 -59
- package/config.scenes.json +0 -15
package/config.smappee.json
CHANGED
|
@@ -1,7 +1,183 @@
|
|
|
1
1
|
{
|
|
2
2
|
"rules": [
|
|
3
|
+
{
|
|
4
|
+
"type": "sun",
|
|
5
|
+
"channel": "0",
|
|
6
|
+
"low": 30,
|
|
7
|
+
"high": 900,
|
|
8
|
+
"actions": [
|
|
9
|
+
{
|
|
10
|
+
"name": "Mood A",
|
|
11
|
+
"value": false,
|
|
12
|
+
"masterAddress": "192.168.0.97",
|
|
13
|
+
"masterPort": 5001,
|
|
14
|
+
"logicalAddress": 10,
|
|
15
|
+
"logicalNodeAddress": 252
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "Mood A",
|
|
19
|
+
"value": 50,
|
|
20
|
+
"masterAddress": "192.168.0.97",
|
|
21
|
+
"masterPort": 5001,
|
|
22
|
+
"logicalAddress": 10,
|
|
23
|
+
"logicalNodeAddress": 252
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "Mood A",
|
|
27
|
+
"value": true,
|
|
28
|
+
"masterAddress": "192.168.0.97",
|
|
29
|
+
"masterPort": 5001,
|
|
30
|
+
"logicalAddress": 10,
|
|
31
|
+
"logicalNodeAddress": 252
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"power": -3382,
|
|
35
|
+
"current": 0
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"type": "power",
|
|
39
|
+
"channel": "4",
|
|
40
|
+
"low": 10,
|
|
41
|
+
"high": 20,
|
|
42
|
+
"actions": [
|
|
43
|
+
{
|
|
44
|
+
"name": "Mood B",
|
|
45
|
+
"value": false,
|
|
46
|
+
"masterAddress": "192.168.0.97",
|
|
47
|
+
"masterPort": 5001,
|
|
48
|
+
"logicalAddress": 11,
|
|
49
|
+
"logicalNodeAddress": 252
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "Mood B",
|
|
53
|
+
"value": 50,
|
|
54
|
+
"masterAddress": "192.168.0.97",
|
|
55
|
+
"masterPort": 5001,
|
|
56
|
+
"logicalAddress": 11,
|
|
57
|
+
"logicalNodeAddress": 252
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "Mood B",
|
|
61
|
+
"value": true,
|
|
62
|
+
"masterAddress": "192.168.0.97",
|
|
63
|
+
"masterPort": 5001,
|
|
64
|
+
"logicalAddress": 11,
|
|
65
|
+
"logicalNodeAddress": 252
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"power": 0,
|
|
69
|
+
"current": 0
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"type": "power",
|
|
73
|
+
"channel": "7+8+9",
|
|
74
|
+
"low": 30,
|
|
75
|
+
"high": 900,
|
|
76
|
+
"actions": [
|
|
77
|
+
{
|
|
78
|
+
"name": "Mood C",
|
|
79
|
+
"value": false,
|
|
80
|
+
"masterAddress": "192.168.0.97",
|
|
81
|
+
"masterPort": 5001,
|
|
82
|
+
"logicalAddress": 12,
|
|
83
|
+
"logicalNodeAddress": 252
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "Mood C",
|
|
87
|
+
"value": 50,
|
|
88
|
+
"masterAddress": "192.168.0.97",
|
|
89
|
+
"masterPort": 5001,
|
|
90
|
+
"logicalAddress": 12,
|
|
91
|
+
"logicalNodeAddress": 252
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "Mood C",
|
|
95
|
+
"value": true,
|
|
96
|
+
"masterAddress": "192.168.0.97",
|
|
97
|
+
"masterPort": 5001,
|
|
98
|
+
"logicalAddress": 12,
|
|
99
|
+
"logicalNodeAddress": 252
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"power": 2207,
|
|
103
|
+
"current": 2
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "sun",
|
|
107
|
+
"channel": "7",
|
|
108
|
+
"low": 0,
|
|
109
|
+
"high": 0,
|
|
110
|
+
"actions": [
|
|
111
|
+
{
|
|
112
|
+
"name": "Mood C",
|
|
113
|
+
"value": false,
|
|
114
|
+
"masterAddress": "192.168.0.97",
|
|
115
|
+
"masterPort": 5001,
|
|
116
|
+
"logicalAddress": 12,
|
|
117
|
+
"logicalNodeAddress": 252
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"name": "Mood C",
|
|
121
|
+
"value": 50,
|
|
122
|
+
"masterAddress": "192.168.0.97",
|
|
123
|
+
"masterPort": 5001,
|
|
124
|
+
"logicalAddress": 12,
|
|
125
|
+
"logicalNodeAddress": 252
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"name": "Mood C",
|
|
129
|
+
"value": true,
|
|
130
|
+
"masterAddress": "192.168.0.97",
|
|
131
|
+
"masterPort": 5001,
|
|
132
|
+
"logicalAddress": 12,
|
|
133
|
+
"logicalNodeAddress": 252
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
3
137
|
],
|
|
4
|
-
"address": "192.168.0.
|
|
138
|
+
"address": "192.168.0.186",
|
|
5
139
|
"uid": "57e3e0d8-bb05-4b04-8662-1a9871998f3f",
|
|
6
|
-
"debug": false
|
|
140
|
+
"debug": false,
|
|
141
|
+
"bindings": [
|
|
142
|
+
{
|
|
143
|
+
"name": "<Solar",
|
|
144
|
+
"value": 0,
|
|
145
|
+
"masterAddress": "192.168.0.97",
|
|
146
|
+
"masterPort": 5001,
|
|
147
|
+
"logicalAddress": 102,
|
|
148
|
+
"logicalNodeAddress": 252,
|
|
149
|
+
"channel": "0+1",
|
|
150
|
+
"power": 1706
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": ">Grid",
|
|
154
|
+
"value": 0,
|
|
155
|
+
"masterAddress": "192.168.0.97",
|
|
156
|
+
"masterPort": 5001,
|
|
157
|
+
"logicalAddress": 100,
|
|
158
|
+
"logicalNodeAddress": 252,
|
|
159
|
+
"channel": "2+3",
|
|
160
|
+
"power": 2494
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": ">Cars",
|
|
164
|
+
"value": 0,
|
|
165
|
+
"masterAddress": "192.168.0.97",
|
|
166
|
+
"masterPort": 5001,
|
|
167
|
+
"logicalAddress": 103,
|
|
168
|
+
"logicalNodeAddress": 252,
|
|
169
|
+
"channel": "4+5",
|
|
170
|
+
"power": null
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"name": ">Swimmingpool",
|
|
174
|
+
"value": 0,
|
|
175
|
+
"masterAddress": "192.168.0.97",
|
|
176
|
+
"masterPort": 5001,
|
|
177
|
+
"logicalAddress": 101,
|
|
178
|
+
"logicalNodeAddress": 252,
|
|
179
|
+
"channel": "8",
|
|
180
|
+
"power": null
|
|
181
|
+
}
|
|
182
|
+
]
|
|
7
183
|
}
|
package/config.smartapp.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
+
"apiPort": 8581,
|
|
3
|
+
"apiHost": "192.168.0.99",
|
|
4
|
+
"socapp": false,
|
|
2
5
|
"port": 5002,
|
|
3
6
|
"switches": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Shelly Valies",
|
|
9
|
+
"unitName": "Red",
|
|
10
|
+
"masterAddress": "192.168.0.97",
|
|
11
|
+
"masterPort": 5001,
|
|
12
|
+
"nomacro": "Y",
|
|
13
|
+
"nostop": "Y",
|
|
14
|
+
"logicalAddress": 107,
|
|
15
|
+
"logicalNodeAddress": 252,
|
|
16
|
+
"type": "httpdim",
|
|
17
|
+
"plug": "http://192.168.0.96/light/0?brightness=$&turn=#",
|
|
18
|
+
"data": "",
|
|
19
|
+
"method": "GET",
|
|
20
|
+
"value": 0
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Screen Salon Top",
|
|
24
|
+
"unitName": "Salon Top",
|
|
25
|
+
"masterAddress": "192.168.0.97",
|
|
26
|
+
"masterPort": 5001,
|
|
27
|
+
"nomacro": "N",
|
|
28
|
+
"nostop": "N",
|
|
29
|
+
"logicalAddress": 105,
|
|
30
|
+
"logicalNodeAddress": 252,
|
|
31
|
+
"type": "somfy",
|
|
32
|
+
"plug": "1",
|
|
33
|
+
"data": "",
|
|
34
|
+
"method": "GET",
|
|
35
|
+
"value": 0
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "Screen Tim small",
|
|
39
|
+
"unitName": "Tim Small",
|
|
40
|
+
"masterAddress": "192.168.0.97",
|
|
41
|
+
"masterPort": 5001,
|
|
42
|
+
"nomacro": "N",
|
|
43
|
+
"nostop": "Y",
|
|
44
|
+
"logicalAddress": 104,
|
|
45
|
+
"logicalNodeAddress": 252,
|
|
46
|
+
"type": "httpupdown",
|
|
47
|
+
"plug": "2",
|
|
48
|
+
"data": "",
|
|
49
|
+
"method": "GET",
|
|
50
|
+
"value": 0
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "Test Plug",
|
|
54
|
+
"unitName": "Plug",
|
|
55
|
+
"masterAddress": "gm.coppieters.be",
|
|
56
|
+
"masterPort": 5005,
|
|
57
|
+
"nomacro": "N",
|
|
58
|
+
"nostop": "N",
|
|
59
|
+
"logicalAddress": 35,
|
|
60
|
+
"logicalNodeAddress": 16,
|
|
61
|
+
"type": "smappee",
|
|
62
|
+
"plug": "1",
|
|
63
|
+
"data": "",
|
|
64
|
+
"method": "GET",
|
|
65
|
+
"value": 0
|
|
66
|
+
}
|
|
4
67
|
],
|
|
5
68
|
"debug": false
|
|
6
69
|
}
|
package/duotecno/Q.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Q = void 0;
|
|
4
|
-
const
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
5
|
class Q {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.timer = null;
|
|
8
8
|
this.queue = [];
|
|
9
|
-
|
|
9
|
+
logger_1.logSettings["Q"] = logger_1.LogLevel.log;
|
|
10
10
|
}
|
|
11
11
|
exec(fn) {
|
|
12
12
|
const len = this.queue.length;
|
|
@@ -17,30 +17,30 @@ class Q {
|
|
|
17
17
|
}
|
|
18
18
|
endWaiter() {
|
|
19
19
|
if (this.timer) {
|
|
20
|
-
(0,
|
|
20
|
+
(0, logger_1.debug)("Q", "Waiter: clearing timer");
|
|
21
21
|
clearTimeout(this.timer);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
startWaiter(mSecs = 1000) {
|
|
25
25
|
this.endWaiter();
|
|
26
|
-
(0,
|
|
26
|
+
(0, logger_1.debug)("Q", "Waiter: starting timer for " + mSecs + " mSec");
|
|
27
27
|
this.timer = setTimeout(() => {
|
|
28
|
-
(0,
|
|
28
|
+
(0, logger_1.debug)("Q", "Waiter: timer finished, calling 'do' because nobody else did");
|
|
29
29
|
this.do();
|
|
30
30
|
}, mSecs);
|
|
31
31
|
}
|
|
32
32
|
do() {
|
|
33
|
-
(0,
|
|
33
|
+
(0, logger_1.debug)("Q", "Do, qlen=" + this.queue.length);
|
|
34
34
|
// Get the oldest function and execute
|
|
35
35
|
if (this.queue.length > 0) {
|
|
36
36
|
const fn = this.queue[0];
|
|
37
37
|
this.queue.splice(0, 1);
|
|
38
|
-
(0,
|
|
38
|
+
(0, logger_1.debug)("Q", "Do: calling function");
|
|
39
39
|
fn();
|
|
40
40
|
}
|
|
41
41
|
// Still stuff to execute
|
|
42
42
|
if (this.queue.length > 0) {
|
|
43
|
-
(0,
|
|
43
|
+
(0, logger_1.debug)("Q", "Do, still stuff in the queue, start timer");
|
|
44
44
|
this.startWaiter();
|
|
45
45
|
}
|
|
46
46
|
else {
|
package/duotecno/Q.ts
CHANGED
package/duotecno/api.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.post = exports.get = void 0;
|
|
13
13
|
const http = require("http");
|
|
14
|
-
const
|
|
14
|
+
const logger_1 = require("./logger");
|
|
15
15
|
///////////////////
|
|
16
16
|
// http function //
|
|
17
17
|
///////////////////
|
|
@@ -55,7 +55,7 @@ function request(method, host, port, path, body, headers = {}) {
|
|
|
55
55
|
}).on('error', (e) => {
|
|
56
56
|
if (timer)
|
|
57
57
|
clearTimeout(timer);
|
|
58
|
-
(0,
|
|
58
|
+
(0, logger_1.err)("http", "http.get failed with " + JSON.stringify(e));
|
|
59
59
|
reject(e);
|
|
60
60
|
});
|
|
61
61
|
if (method === "POST") {
|
|
@@ -64,7 +64,7 @@ function request(method, host, port, path, body, headers = {}) {
|
|
|
64
64
|
httpReq.end();
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
(0,
|
|
67
|
+
(0, logger_1.err)("http", "http.request " + method + " to " + host + " with " + path + " failed with " + error.message);
|
|
68
68
|
reject(error);
|
|
69
69
|
}
|
|
70
70
|
});
|
package/duotecno/api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as http from "http";
|
|
2
|
-
import { err } from "./
|
|
2
|
+
import { err } from "./logger";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
///////////////////
|
|
@@ -54,7 +54,7 @@ async function request(method: string, host: string, port: number, path: string,
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
} catch(error) {
|
|
57
|
-
err("http", "http.
|
|
57
|
+
err("http", "http.request " + method + " to " + host + " with " + path + " failed with " + error.message);
|
|
58
58
|
reject(error);
|
|
59
59
|
}
|
|
60
60
|
});
|
package/duotecno/config.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// Global Config //
|
|
4
4
|
///////////////////
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setAPIConfig = exports.getAPIConfig = exports.setSubConfig = exports.getSubConfig = exports.getConfig = exports.setConfig = exports.setToken = void 0;
|
|
6
|
+
exports.setAPIConfig = exports.getAPIConfig = exports.setSubConfig = exports.getSubConfig = exports.getConfig = exports.setConfig = exports.kConfigFiles = exports.isMac = exports.setToken = void 0;
|
|
7
7
|
const api_1 = require("./api");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
9
10
|
const fs = require("fs");
|
|
10
11
|
const os_1 = require("os");
|
|
11
12
|
let gToken = "";
|
|
@@ -13,10 +14,10 @@ function setToken(token) {
|
|
|
13
14
|
gToken = token;
|
|
14
15
|
}
|
|
15
16
|
exports.setToken = setToken;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!fs.existsSync(kConfigFiles))
|
|
19
|
-
fs.mkdirSync(kConfigFiles);
|
|
17
|
+
exports.isMac = ((0, os_1.platform)() === "darwin");
|
|
18
|
+
exports.kConfigFiles = (exports.isMac) ? (__dirname + "/..") : ((0, os_1.homedir)());
|
|
19
|
+
if (!fs.existsSync(exports.kConfigFiles))
|
|
20
|
+
fs.mkdirSync(exports.kConfigFiles);
|
|
20
21
|
// set up empty config
|
|
21
22
|
let gPlatformConfig = types_1.Sanitizers.platform(null);
|
|
22
23
|
add("smartapp"); // webserver interface
|
|
@@ -48,33 +49,34 @@ function setSubConfig(type, cfg) {
|
|
|
48
49
|
}
|
|
49
50
|
exports.setSubConfig = setSubConfig;
|
|
50
51
|
// we should get the config through the homebridge platform init call !!
|
|
52
|
+
// no need to call this function.
|
|
51
53
|
function getAPIConfig(done) {
|
|
52
54
|
let config = null;
|
|
53
|
-
if (gPlatformConfig.apiHost) {
|
|
55
|
+
if (gPlatformConfig.smartapp.apiHost) {
|
|
54
56
|
const headers = { "Content-Type": "application/json" };
|
|
55
57
|
if (gToken) {
|
|
56
58
|
headers["Authorization"] = "Bearer " + gToken;
|
|
57
59
|
}
|
|
58
|
-
(0, api_1.get)(gPlatformConfig.apiHost, gPlatformConfig.apiPort, "/api/config-editor", headers).then((resp) => {
|
|
59
|
-
(0,
|
|
60
|
+
(0, api_1.get)(gPlatformConfig.smartapp.apiHost, gPlatformConfig.smartapp.apiPort, "/api/config-editor/plugin/homebridge-smartsystem", headers).then((resp) => {
|
|
61
|
+
(0, logger_1.debug)("smartapp", "OK: " + resp);
|
|
60
62
|
const parsed = JSON.parse(resp);
|
|
61
|
-
setConfig(parsed);
|
|
63
|
+
setConfig(parsed[0]);
|
|
62
64
|
if (done)
|
|
63
|
-
done(parsed);
|
|
65
|
+
done(parsed[0]);
|
|
64
66
|
}, (err) => {
|
|
65
|
-
(0,
|
|
67
|
+
(0, logger_1.debug)("smartapp", "ERROR: " + JSON.stringify(err));
|
|
66
68
|
done(null);
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
|
-
const fn = kConfigFiles + "/config.json";
|
|
72
|
+
const fn = exports.kConfigFiles + "/config.json";
|
|
71
73
|
try {
|
|
72
74
|
const configBuf = fs.readFileSync(fn);
|
|
73
75
|
const configStr = configBuf.toString();
|
|
74
76
|
config = JSON.parse(configStr);
|
|
75
77
|
}
|
|
76
78
|
catch (err) {
|
|
77
|
-
(0,
|
|
79
|
+
(0, logger_1.log)("system", "Couldn't read my config file (" + fn + ") -- Creating empty config.");
|
|
78
80
|
}
|
|
79
81
|
// sanitize the config
|
|
80
82
|
const sanitized = types_1.Sanitizers.platform(config);
|
|
@@ -84,21 +86,20 @@ function getAPIConfig(done) {
|
|
|
84
86
|
}
|
|
85
87
|
exports.getAPIConfig = getAPIConfig;
|
|
86
88
|
function setAPIConfig() {
|
|
87
|
-
if (gPlatformConfig.apiHost) {
|
|
89
|
+
if (gPlatformConfig.smartapp.apiHost) {
|
|
88
90
|
const headers = { "Content-Type": "application/json" };
|
|
89
91
|
if (gToken) {
|
|
90
92
|
headers["Authorization"] = "Bearer " + gToken;
|
|
91
93
|
}
|
|
92
|
-
(0, api_1.post)(gPlatformConfig.apiHost, gPlatformConfig.apiPort, "/api/config-editor", gPlatformConfig, headers).then((resp) => (0,
|
|
94
|
+
(0, api_1.post)(gPlatformConfig.smartapp.apiHost, gPlatformConfig.smartapp.apiPort, "/api/config-editor/plugin/homebridge-smartsystem", [gPlatformConfig], headers).then((resp) => (0, logger_1.debug)("smartapp", "OK: " + resp), (err) => (0, logger_1.debug)("smartapp", "ERROR: " + JSON.stringify(err)));
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
96
|
+
// still write the config files
|
|
97
|
+
const fn = exports.kConfigFiles + "/config.json";
|
|
98
|
+
try {
|
|
99
|
+
fs.writeFileSync(fn, JSON.stringify(gPlatformConfig, null, 2));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
(0, logger_1.err)("config", "Couldn't write config.json file (" + fn + ")");
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
exports.setAPIConfig = setAPIConfig;
|
package/duotecno/config.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
///////////////////
|
|
5
5
|
|
|
6
6
|
import { get, post } from "./api";
|
|
7
|
-
import {
|
|
7
|
+
import { PlatformConfig, Sanitizers } from "./types";
|
|
8
|
+
import { debug, err, log } from "./logger";
|
|
8
9
|
import * as fs from "fs";
|
|
9
10
|
import { homedir, platform } from "os";
|
|
10
11
|
|
|
@@ -14,8 +15,9 @@ export function setToken(token: string) {
|
|
|
14
15
|
gToken = token;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
const isMac = (platform() === "darwin");
|
|
18
|
-
const kConfigFiles = (isMac) ? (__dirname+"/..") : (homedir()
|
|
18
|
+
export const isMac = (platform() === "darwin");
|
|
19
|
+
export const kConfigFiles = (isMac) ? (__dirname+"/..") : (homedir());
|
|
20
|
+
|
|
19
21
|
if (! fs.existsSync(kConfigFiles)) fs.mkdirSync(kConfigFiles);
|
|
20
22
|
|
|
21
23
|
|
|
@@ -57,20 +59,22 @@ export function setSubConfig(type: string, cfg: object) {
|
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
// we should get the config through the homebridge platform init call !!
|
|
62
|
+
// no need to call this function.
|
|
60
63
|
export function getAPIConfig(done) {
|
|
61
64
|
let config = null;
|
|
62
|
-
if (gPlatformConfig.apiHost) {
|
|
65
|
+
if (gPlatformConfig.smartapp.apiHost) {
|
|
63
66
|
const headers = {"Content-Type": "application/json"};
|
|
64
67
|
if (gToken) {
|
|
65
68
|
headers["Authorization"] = "Bearer "+ gToken;
|
|
66
69
|
}
|
|
67
|
-
get(gPlatformConfig.apiHost, gPlatformConfig.apiPort,
|
|
70
|
+
get(gPlatformConfig.smartapp.apiHost, gPlatformConfig.smartapp.apiPort,
|
|
71
|
+
"/api/config-editor/plugin/homebridge-smartsystem", headers).then(
|
|
68
72
|
(resp) => {
|
|
69
73
|
debug("smartapp", "OK: " + resp);
|
|
70
74
|
const parsed = JSON.parse(resp);
|
|
71
|
-
setConfig(parsed);
|
|
75
|
+
setConfig(parsed[0]);
|
|
72
76
|
if (done)
|
|
73
|
-
done(parsed);
|
|
77
|
+
done(parsed[0]);
|
|
74
78
|
},
|
|
75
79
|
(err) => {
|
|
76
80
|
debug("smartapp", "ERROR: " + JSON.stringify(err));
|
|
@@ -97,22 +101,25 @@ export function getAPIConfig(done) {
|
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
export function setAPIConfig() {
|
|
100
|
-
if (gPlatformConfig.apiHost) {
|
|
104
|
+
if (gPlatformConfig.smartapp.apiHost) {
|
|
101
105
|
const headers = {"Content-Type": "application/json"};
|
|
102
106
|
if (gToken) {
|
|
103
107
|
headers["Authorization"] = "Bearer "+ gToken;
|
|
104
108
|
}
|
|
105
|
-
post(gPlatformConfig.apiHost, gPlatformConfig.apiPort,
|
|
109
|
+
post(gPlatformConfig.smartapp.apiHost, gPlatformConfig.smartapp.apiPort,
|
|
110
|
+
"/api/config-editor/plugin/homebridge-smartsystem", [gPlatformConfig], headers).then(
|
|
106
111
|
(resp) => debug("smartapp", "OK: " + resp),
|
|
107
112
|
(err) => debug("smartapp", "ERROR: " + JSON.stringify(err))
|
|
108
113
|
);
|
|
109
|
-
}
|
|
110
|
-
const fn = kConfigFiles + "/config.json";
|
|
111
|
-
try {
|
|
112
|
-
fs.writeFileSync(fn, JSON.stringify(gPlatformConfig, null, 2));
|
|
114
|
+
}
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
// still write the config files
|
|
117
|
+
const fn = kConfigFiles + "/config.json";
|
|
118
|
+
try {
|
|
119
|
+
fs.writeFileSync(fn, JSON.stringify(gPlatformConfig, null, 2));
|
|
120
|
+
|
|
121
|
+
} catch(error) {
|
|
122
|
+
err("config", "Couldn't write config.json file (" + fn + ")");
|
|
117
123
|
}
|
|
124
|
+
|
|
118
125
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/////////////
|
|
3
|
+
// Logging //
|
|
4
|
+
/////////////
|
|
5
|
+
// add LogLevels per type at runtime
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.debug = exports.log = exports.err = exports.setLogFunction = exports.logFunction = exports.logSettings = exports.LogLevel = void 0;
|
|
8
|
+
var LogLevel;
|
|
9
|
+
(function (LogLevel) {
|
|
10
|
+
LogLevel[LogLevel["noLog"] = 0] = "noLog";
|
|
11
|
+
LogLevel[LogLevel["log"] = 1] = "log";
|
|
12
|
+
LogLevel[LogLevel["debug"] = 2] = "debug";
|
|
13
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
14
|
+
;
|
|
15
|
+
exports.logSettings = {
|
|
16
|
+
"*": LogLevel.log,
|
|
17
|
+
"master": LogLevel.log,
|
|
18
|
+
"protocol": LogLevel.noLog,
|
|
19
|
+
"webapp": LogLevel.log,
|
|
20
|
+
"p1": LogLevel.log,
|
|
21
|
+
"power": LogLevel.log,
|
|
22
|
+
"smartapp": LogLevel.log
|
|
23
|
+
};
|
|
24
|
+
// can be overriden with server log function
|
|
25
|
+
exports.logFunction = console.log;
|
|
26
|
+
function setLogFunction(F) {
|
|
27
|
+
console.log(">>>>>>>>> NOT changing logfunction to: " + F.name + " <<<<<<<<<<");
|
|
28
|
+
// logFunction = (m) => { F(m) };
|
|
29
|
+
}
|
|
30
|
+
exports.setLogFunction = setLogFunction;
|
|
31
|
+
function err(type, message) {
|
|
32
|
+
(0, exports.logFunction)(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
33
|
+
}
|
|
34
|
+
exports.err = err;
|
|
35
|
+
function log(type, message) {
|
|
36
|
+
var _a;
|
|
37
|
+
const level = (_a = exports.logSettings[type]) !== null && _a !== void 0 ? _a : exports.logSettings["*"];
|
|
38
|
+
if (level) {
|
|
39
|
+
(0, exports.logFunction)(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.log = log;
|
|
43
|
+
function debug(type, message) {
|
|
44
|
+
var _a;
|
|
45
|
+
const level = (_a = exports.logSettings[type]) !== null && _a !== void 0 ? _a : exports.logSettings["*"];
|
|
46
|
+
if (level === LogLevel.debug) {
|
|
47
|
+
(0, exports.logFunction)(type + "> " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.debug = debug;
|
|
51
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
/////////////
|
|
3
|
+
// Logging //
|
|
4
|
+
/////////////
|
|
5
|
+
// add LogLevels per type at runtime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export enum LogLevel { noLog = 0, log = 1, debug = 2 };
|
|
9
|
+
|
|
10
|
+
export const logSettings = {
|
|
11
|
+
"*": LogLevel.log,
|
|
12
|
+
"master": LogLevel.log,
|
|
13
|
+
"protocol": LogLevel.noLog,
|
|
14
|
+
"webapp": LogLevel.log,
|
|
15
|
+
"p1": LogLevel.log,
|
|
16
|
+
"power": LogLevel.log,
|
|
17
|
+
"smartapp": LogLevel.log
|
|
18
|
+
};
|
|
19
|
+
// can be overriden with server log function
|
|
20
|
+
|
|
21
|
+
export let logFunction = console.log;
|
|
22
|
+
export function setLogFunction(F) {
|
|
23
|
+
console.log(">>>>>>>>> NOT changing logfunction to: " + F.name + " <<<<<<<<<<");
|
|
24
|
+
// logFunction = (m) => { F(m) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function err(type: string, message: string | object) {
|
|
28
|
+
logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
29
|
+
}
|
|
30
|
+
export function log(type: string, message: string | object) {
|
|
31
|
+
const level = logSettings[type] ?? logSettings["*"];
|
|
32
|
+
if (level) {
|
|
33
|
+
logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function debug(type: string, message: string | object) {
|
|
37
|
+
const level = logSettings[type] ?? logSettings["*"];
|
|
38
|
+
if (level === LogLevel.debug) {
|
|
39
|
+
logFunction(type + "> " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
40
|
+
}
|
|
41
|
+
}
|
package/duotecno/master.js
CHANGED
|
@@ -12,15 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.Master = void 0;
|
|
13
13
|
const protocol_1 = require("./protocol");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
15
16
|
const base_1 = require("../server/base");
|
|
16
17
|
const Q_1 = require("./Q");
|
|
17
18
|
const smartsocket_1 = require("./smartsocket");
|
|
18
19
|
class Master extends base_1.Base {
|
|
19
20
|
// command was sent, no response received yet
|
|
20
21
|
/* system.config: {
|
|
21
|
-
"language": "EN",
|
|
22
|
-
"stores": false,
|
|
23
|
-
"multiple": false,
|
|
24
22
|
"socketserver": "akiworks.be",
|
|
25
23
|
"socketport": 9999,
|
|
26
24
|
"mood": "sfeer",
|
|
@@ -161,13 +159,13 @@ class Master extends base_1.Base {
|
|
|
161
159
|
}
|
|
162
160
|
// overwrite to add IP address
|
|
163
161
|
log(msg) {
|
|
164
|
-
(0,
|
|
162
|
+
(0, logger_1.log)("master", this.getAddress() + ": " + msg);
|
|
165
163
|
}
|
|
166
164
|
info(msg) {
|
|
167
|
-
(0,
|
|
165
|
+
(0, logger_1.debug)("master", this.getAddress() + ": " + msg);
|
|
168
166
|
}
|
|
169
167
|
err(msg) {
|
|
170
|
-
(0,
|
|
168
|
+
(0, logger_1.log)("master", this.getAddress() + ": " + msg);
|
|
171
169
|
}
|
|
172
170
|
writeConfig(config, fn) {
|
|
173
171
|
// overwrite: don't do anything, all is stored in the system-config
|