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.
Files changed (66) hide show
  1. package/README.md +14 -0
  2. package/accessories/accessory.js +4 -4
  3. package/accessories/accessory.ts +1 -2
  4. package/accessories/dimmer.js +6 -6
  5. package/accessories/dimmer.ts +1 -1
  6. package/accessories/door.js +2 -2
  7. package/accessories/door.ts +1 -1
  8. package/accessories/garagedoor.js +5 -4
  9. package/accessories/garagedoor.ts +2 -1
  10. package/accessories/lock.js +6 -5
  11. package/accessories/lock.ts +2 -1
  12. package/accessories/mood.js +2 -1
  13. package/accessories/mood.ts +2 -1
  14. package/accessories/temperature.js +2 -2
  15. package/accessories/temperature.ts +1 -1
  16. package/accessories/windowcovering.js +8 -7
  17. package/accessories/windowcovering.ts +2 -1
  18. package/config.json +169 -228
  19. package/config.smappee.json +178 -2
  20. package/config.smartapp.json +63 -0
  21. package/duotecno/Q.js +8 -8
  22. package/duotecno/Q.ts +1 -1
  23. package/duotecno/api.js +3 -3
  24. package/duotecno/api.ts +2 -2
  25. package/duotecno/config.js +24 -23
  26. package/duotecno/config.ts +23 -16
  27. package/duotecno/logger.js +51 -0
  28. package/duotecno/logger.ts +41 -0
  29. package/duotecno/master.js +4 -6
  30. package/duotecno/master.ts +2 -4
  31. package/duotecno/protocol.js +10 -9
  32. package/duotecno/protocol.ts +2 -1
  33. package/duotecno/system.js +17 -41
  34. package/duotecno/system.ts +7 -34
  35. package/duotecno/types.js +58 -131
  36. package/duotecno/types.ts +65 -125
  37. package/index.spec.js +22 -36
  38. package/index.spec.ts +20 -33
  39. package/package.json +2 -2
  40. package/server/base.js +10 -38
  41. package/server/base.ts +9 -42
  42. package/server/p1.js +9 -8
  43. package/server/p1.ts +6 -4
  44. package/server/platform.js +66 -36
  45. package/server/platform.ts +47 -12
  46. package/server/powerbase.js +15 -55
  47. package/server/powerbase.ts +4 -50
  48. package/server/shelly.js +4 -4
  49. package/server/shelly.ts +3 -2
  50. package/server/smappee.js +9 -8
  51. package/server/smappee.ts +4 -3
  52. package/server/smartapp.js +94 -39
  53. package/server/smartapp.ts +73 -20
  54. package/server/socapp.js +6 -6
  55. package/server/socapp.ts +2 -1
  56. package/server/somfy.js +12 -12
  57. package/server/somfy.ts +1 -1
  58. package/server/support.js +13 -13
  59. package/server/support.ts +4 -4
  60. package/server/views/style.ejs +1 -0
  61. package/server/views/switch-details.ejs +15 -5
  62. package/server/webapp.js +45 -47
  63. package/server/webapp.ts +29 -38
  64. package/config.groups.json +0 -8
  65. package/config.p1-dev.json +0 -59
  66. package/config.scenes.json +0 -15
package/server/base.ts CHANGED
@@ -1,13 +1,5 @@
1
- import * as fs from 'fs';
2
- import { debug, err, log, LogFunction, LogLevel, logSettings, Sanitizers } from "../duotecno/types";
3
-
4
-
5
- import { existsSync, mkdirSync } from "fs";
6
- import { homedir, platform } from "os";
7
-
8
- const isMac = (platform() === "darwin");
9
- const kConfigFiles = (isMac) ? (__dirname+"/..") : (homedir() + "/duotecno");
10
- if (! existsSync(kConfigFiles)) mkdirSync(kConfigFiles);
1
+ import { debug, LogLevel, logSettings } from "../duotecno/logger";
2
+ import { setSubConfig, getSubConfig, setAPIConfig } from '../duotecno/config';
11
3
 
12
4
 
13
5
  ///////////////
@@ -18,7 +10,7 @@ export class Base {
18
10
  type: string;
19
11
  debug: boolean;
20
12
  config: any;
21
- configFiles = kConfigFiles;
13
+
22
14
 
23
15
  constructor(type: string, config?) {
24
16
  this.type = type || "base";
@@ -43,43 +35,18 @@ export class Base {
43
35
  this.config = this.read(this.type);
44
36
  this.debug = (!!this.config.debug) || false;
45
37
  }
46
-
47
38
  writeConfig() {
48
39
  this.write(this.type, this.config);
49
40
  }
50
41
 
51
-
52
- read(type: string, fname: string = "") {
53
- const fn = fname || (this.configFiles + "/config." + type + ".json");
54
- let config = null;
55
-
56
- try {
57
- const configBuf = fs.readFileSync(fn);
58
- const configStr = configBuf.toString();
59
- config = JSON.parse(configStr);
60
-
61
- } catch(err) {
62
- log("system", "Couldn't read my config file (" + fn + ") -- Creating empty config.")
63
- }
64
-
65
- // sanitize the config
66
- const temp = Sanitizers[type](config);
67
-
68
- // write if we created it (new intallations or new config params)
69
- if (!config && temp) this.write(type, temp, fname);
70
- return temp;
42
+ read(type: string) {
43
+ return getSubConfig(type);
71
44
  }
45
+ write(type: string, config) {
46
+ setSubConfig(type, config);
72
47
 
73
- write(type: string, config, fname: string = "") {
74
- const fn = fname || (this.configFiles + "/config." + type + ".json");
75
- try {
76
- config = Sanitizers[type](config);
77
- fs.writeFileSync(fn, JSON.stringify(config, null, 2));
78
-
79
- } catch(error) {
80
- err(this.type, "Couldn't write my " + type + " config file (" + fn + ")");
81
- }
82
- return config;
48
+ // but better to much than not enough
49
+ setAPIConfig();
83
50
  }
84
51
 
85
52
  }
package/server/p1.js CHANGED
@@ -13,11 +13,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.P1 = void 0;
16
- const types_1 = require("../duotecno/types");
16
+ const logger_1 = require("../duotecno/logger");
17
17
  const powerbase_1 = require("./powerbase");
18
- const types_2 = require("../duotecno/types");
18
+ const logger_2 = require("../duotecno/logger");
19
+ const api_1 = require("../duotecno/api");
19
20
  class P1 extends powerbase_1.PowerBase {
20
- constructor(system, dev = false) {
21
+ constructor(system) {
21
22
  super("p1", system);
22
23
  // readconfig and init are called by super
23
24
  }
@@ -38,7 +39,7 @@ class P1 extends powerbase_1.PowerBase {
38
39
  subscribe() {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
41
  const kInterval = 5;
41
- (0, types_1.log)("p1", "connecting to P1: " + this.config.address);
42
+ (0, logger_1.log)("p1", "connecting to P1: " + this.config.address);
42
43
  if (this.config.address) {
43
44
  this.timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
44
45
  this.realtimeCounter += kInterval;
@@ -64,9 +65,9 @@ class P1 extends powerbase_1.PowerBase {
64
65
  fetchData() {
65
66
  return __awaiter(this, void 0, void 0, function* () {
66
67
  try {
67
- (0, types_2.debug)("p1", "fetching from " + this.config.address + "/api/v1/telegram");
68
- const res = yield this.get(this.config.address, "/api/v1/telegram");
69
- (0, types_2.debug)("p1", "received: " + res);
68
+ (0, logger_2.debug)("p1", "fetching from " + this.config.address + "/api/v1/telegram");
69
+ const res = yield (0, api_1.get)(this.config.address, 80, "/api/v1/telegram", undefined);
70
+ (0, logger_2.debug)("p1", "received: " + res);
70
71
  const result = {};
71
72
  res.split("\r\n").filter(l => (l[0] === '1')).map(L => {
72
73
  // 0-0:1.0.0(220720172521S)
@@ -85,7 +86,7 @@ class P1 extends powerbase_1.PowerBase {
85
86
  return result;
86
87
  }
87
88
  catch (error) {
88
- (0, types_1.err)("p1", "error fetching data: " + JSON.stringify(error));
89
+ (0, logger_1.err)("p1", "error fetching data: " + JSON.stringify(error));
89
90
  return null;
90
91
  }
91
92
  });
package/server/p1.ts CHANGED
@@ -3,9 +3,11 @@
3
3
  //
4
4
 
5
5
  import { System } from "../duotecno/system";
6
- import { err, log, P1Config } from "../duotecno/types";
6
+ import { P1Config } from "../duotecno/types";
7
+ import { err, log } from "../duotecno/logger";
7
8
  import { PowerBase } from "./powerbase";
8
- import { debug } from "../duotecno/types";
9
+ import { debug } from "../duotecno/logger";
10
+ import { get } from "../duotecno/api";
9
11
 
10
12
  /* http://192.168.0.214/api/v1/data
11
13
 
@@ -93,7 +95,7 @@ export class P1 extends PowerBase {
93
95
  timer: NodeJS.Timer;
94
96
 
95
97
 
96
- constructor(system: System, dev = false) {
98
+ constructor(system: System) {
97
99
  super("p1", system);
98
100
 
99
101
  // readconfig and init are called by super
@@ -147,7 +149,7 @@ export class P1 extends PowerBase {
147
149
  async fetchData(): Promise<P1Data> {
148
150
  try {
149
151
  debug("p1", "fetching from " + this.config.address + "/api/v1/telegram");
150
- const res = await this.get(this.config.address, "/api/v1/telegram");
152
+ const res = await get(this.config.address, 80, "/api/v1/telegram", undefined);
151
153
  debug("p1", "received: " + res);
152
154
  const result: P1Data = {};
153
155
 
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Platform = void 0;
13
13
  const types_1 = require("../duotecno/types");
14
+ const logger_1 = require("../duotecno/logger");
14
15
  const system_1 = require("../duotecno/system");
15
16
  const smappee_1 = require("./smappee");
16
17
  const smartapp_1 = require("./smartapp");
@@ -27,41 +28,47 @@ const door_1 = require("../accessories/door");
27
28
  const lock_1 = require("../accessories/lock");
28
29
  const p1_1 = require("./p1");
29
30
  const shelly_1 = require("./shelly");
31
+ const config_1 = require("../duotecno/config");
32
+ const fs_1 = require("fs");
30
33
  class Platform extends base_1.Base {
31
- constructor(logger, config, api) {
32
- // set debug to true for new config files
34
+ constructor(logger, pConfig, api) {
33
35
  super("homebridge");
34
36
  this.accessoryList = [];
35
37
  this.ready = false;
36
38
  this.startWaiting = 0;
37
39
  if (logger.info)
38
- (0, types_1.setLogFunction)(logger.info);
39
- this.config = Object.assign({}, config);
40
- this.config.debug = (config && ("debug" in config)) ? config.debug : false;
40
+ (0, logger_1.setLogFunction)(logger.info);
41
+ this.config = Object.assign({}, pConfig);
42
+ this.config.debug = (pConfig && ("debug" in pConfig)) ? pConfig.debug : false;
41
43
  if (this.config.debug)
42
- types_1.logSettings["homebridge"] = types_1.LogLevel.debug;
43
- (0, types_1.log)("homebridge", "running in " + ((this.config.debug) ? "debug" : "prod") + " mode in directory: " + process.cwd());
44
- (0, types_1.log)("homebridge", "config files in " + this.configFiles + "/config.xxx.json");
45
- (0, types_1.log)("homebridge", "with config:" + JSON.stringify(config, null, 2));
46
- // log("homebridge", "homebridge object:", api);
44
+ logger_1.logSettings["homebridge"] = logger_1.LogLevel.debug;
45
+ if (typeof this.config.system.cmasters === "undefined") {
46
+ (0, logger_1.log)("homebridge", "try doing upgrade from pre v6.2 versions");
47
+ this.doUpgradeV62();
48
+ }
49
+ (0, logger_1.log)("homebridge", "running in " + ((this.config.debug) ? "debug" : "prod") + " mode in directory: " + process.cwd());
50
+ (0, logger_1.log)("homebridge", "with config:" + JSON.stringify(this.config, null, 2));
51
+ // save config for other components
52
+ (0, config_1.setConfig)(this.config);
53
+ // remember api for later use
47
54
  this.homebridgeAPI = api;
48
55
  if (this.config.system) {
49
56
  try {
50
- this.system = new system_1.System(false);
57
+ this.system = new system_1.System();
51
58
  this.system.openMasters(true);
52
59
  this.system.emitter.on('ready', this.systemReady.bind(this));
53
60
  this.system.emitter.on('update', this.updateState.bind(this));
54
61
  }
55
62
  catch (err) {
56
- (0, types_1.log)("homebridge", err);
63
+ (0, logger_1.log)("homebridge", err);
57
64
  if (!this.system) {
58
- (0, types_1.log)("homebridge", "platform - Can't run without a System.");
65
+ (0, logger_1.log)("homebridge", "platform - Can't run without a System.");
59
66
  return;
60
67
  }
61
68
  }
62
69
  }
63
70
  else {
64
- (0, types_1.log)("homebridge", "platform - No System configured -> can't run !!!");
71
+ (0, logger_1.log)("homebridge", "platform - No System configured -> can't run !!!");
65
72
  return;
66
73
  }
67
74
  // start power managers
@@ -69,23 +76,23 @@ class Platform extends base_1.Base {
69
76
  this.startPower("smappee", smappee_1.Smappee);
70
77
  this.startPower("p1", p1_1.P1);
71
78
  this.startPower("shelly", shelly_1.Shelly);
72
- // startup a smartApp if configured -> only on Raspberry's
79
+ // startup a smartApp if configured
73
80
  if (this.config.smartapp) {
74
81
  try {
75
- this.smartapp = new smartapp_1.SmartApp(this.system, this.power, this, false);
82
+ this.smartapp = new smartapp_1.SmartApp(this.system, this.power, this);
76
83
  this.smartapp.serve();
77
84
  }
78
85
  catch (err) {
79
- (0, types_1.log)("homebridge", err);
86
+ (0, logger_1.log)("homebridge", err);
80
87
  if (!this.smartapp) {
81
- (0, types_1.log)("homebridge", "platform - No SmartApp started.");
88
+ (0, logger_1.log)("homebridge", "platform - No SmartApp started.");
82
89
  }
83
90
  }
84
91
  }
85
92
  else {
86
- (0, types_1.log)("homebridge", "platform - No SmartApp configured.");
93
+ (0, logger_1.log)("homebridge", "platform - No SmartApp configured.");
87
94
  }
88
- // startup a SocApp if configured -> for servers
95
+ // startup a SocApp if configured -> for proxy (not needed)
89
96
  if (this.config.socapp) {
90
97
  try {
91
98
  // reuse the config file from the smartapp
@@ -93,14 +100,14 @@ class Platform extends base_1.Base {
93
100
  this.smartsoc.serve();
94
101
  }
95
102
  catch (err) {
96
- (0, types_1.log)("homebridge", err);
103
+ (0, logger_1.log)("homebridge", err);
97
104
  if (!this.smartsoc) {
98
- (0, types_1.log)("homebridge", "platform - No SocApp started.");
105
+ (0, logger_1.log)("homebridge", "platform - No SocApp started.");
99
106
  }
100
107
  }
101
108
  }
102
109
  else {
103
- (0, types_1.log)("homebridge", "platform - No SocApp configured.");
110
+ (0, logger_1.log)("homebridge", "platform - No SocApp configured.");
104
111
  }
105
112
  }
106
113
  startPower(type, PowerMgr) {
@@ -110,14 +117,14 @@ class Platform extends base_1.Base {
110
117
  this.power[type] = new PowerMgr(this.system);
111
118
  }
112
119
  catch (err) {
113
- (0, types_1.log)("homebridge", err);
120
+ (0, logger_1.log)("homebridge", err);
114
121
  if (!this.power[type]) {
115
- (0, types_1.log)("homebridge", "platform - No " + type + " started.");
122
+ (0, logger_1.log)("homebridge", "platform - No " + type + " started.");
116
123
  }
117
124
  }
118
125
  }
119
126
  else {
120
- (0, types_1.log)("homebridge", "platform - No " + type + " configured.");
127
+ (0, logger_1.log)("homebridge", "platform - No " + type + " configured.");
121
128
  }
122
129
  }
123
130
  updateState(unit) {
@@ -129,7 +136,7 @@ class Platform extends base_1.Base {
129
136
  systemReady() {
130
137
  const inConfig = this.system.activeUnitsConfig().length;
131
138
  const inSystem = this.system.allActiveUnits().length;
132
- (0, types_1.log)("homebridge", "=== SYSTEM READY received update -> addMasters: " + inSystem + " of " + inConfig + " ===");
139
+ (0, logger_1.log)("homebridge", "=== SYSTEM READY received update -> addMasters: " + inSystem + " of " + inConfig + " ===");
133
140
  this.ready = (inSystem == inConfig);
134
141
  // trigger status request of all active units in 2 seconds.
135
142
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
@@ -146,45 +153,45 @@ class Platform extends base_1.Base {
146
153
  const inSystem = this.system.allActiveUnits().length;
147
154
  this.ready = (inSystem == inConfig);
148
155
  if (this.ready) {
149
- (0, types_1.log)("homebridge", "=== running after timeout of " + this.startWaiting + " secs --> " +
156
+ (0, logger_1.log)("homebridge", "=== running after timeout of " + this.startWaiting + " secs --> " +
150
157
  inSystem + " == " + inConfig + " units -> " + (inConfig == inSystem) + ", will start in 10 seconds ===");
151
158
  setTimeout(() => { this.doAccessories(callback); }, 10 * 1000);
152
159
  }
153
160
  else if (this.startWaiting > kMaxWaiting) {
154
161
  // give up, retry connection to the masters, a manager like "forever" or "pm2" will restart us.
155
- (0, types_1.log)("homebridge", "=== giving up after " + kMaxWaiting + " secs -> auto restart system ===");
162
+ (0, logger_1.log)("homebridge", "=== giving up after " + kMaxWaiting + " secs -> auto restart system ===");
156
163
  process.exit(-1);
157
164
  }
158
165
  else {
159
166
  // wait another 5 seconds.
160
- (0, types_1.log)("homebridge", "=== waiting >> found " + inSystem + " units out of " + inConfig + " selected after " + this.startWaiting + " sec ===");
167
+ (0, logger_1.log)("homebridge", "=== waiting >> found " + inSystem + " units out of " + inConfig + " selected after " + this.startWaiting + " sec ===");
161
168
  this.startWaiting += 5;
162
169
  setTimeout(() => { this.accessories(callback); }, 5000);
163
170
  }
164
171
  }
165
172
  doAccessories(callback) {
166
- (0, types_1.log)("homebridge", "platform - accessories() called by Homebridge - System is ready");
173
+ (0, logger_1.log)("homebridge", "platform - accessories() called by Homebridge - System is ready");
167
174
  this.addAccessories()
168
175
  .then(list => {
169
- (0, types_1.log)("homebridge", "platform - addAccessories returned: " + list.length + " accessories.");
176
+ (0, logger_1.log)("homebridge", "platform - addAccessories returned: " + list.length + " accessories.");
170
177
  callback(list);
171
178
  })
172
179
  .catch(reason => {
173
- (0, types_1.log)("homebridge", "platform - addAccessories errored: " + reason);
180
+ (0, logger_1.log)("homebridge", "platform - addAccessories errored: " + reason);
174
181
  callback([]);
175
182
  });
176
183
  }
177
184
  addAccessories() {
178
185
  return __awaiter(this, void 0, void 0, function* () {
179
186
  if (!this.system) {
180
- (0, types_1.log)("homebridge", "platform - No System -> No accessories");
187
+ (0, logger_1.log)("homebridge", "platform - No System -> No accessories");
181
188
  this.accessoryList = [];
182
189
  return;
183
190
  }
184
191
  // clear our list
185
192
  this.accessoryList = [];
186
193
  this.system.allActiveUnits().forEach(unit => {
187
- (0, types_1.log)("homebridge", "adding accessory: " + unit.getDescription());
194
+ (0, logger_1.log)("homebridge", "adding accessory: " + unit.getDescription());
188
195
  switch (unit.getType()) {
189
196
  case types_1.UnitExtendedType.kDimmer:
190
197
  this.accessoryList.push(new dimmer_1.Dimmer(this.homebridgeAPI, unit));
@@ -217,7 +224,7 @@ class Platform extends base_1.Base {
217
224
  this.accessoryList.push(new temperature_1.Temperature(this.homebridgeAPI, unit));
218
225
  break;
219
226
  default:
220
- (0, types_1.log)("homebridge", "platform - addAccessories: accessory type not yet supported: " + unit.typeName() +
227
+ (0, logger_1.log)("homebridge", "platform - addAccessories: accessory type not yet supported: " + unit.typeName() +
221
228
  " (" + unit.getName() + ")");
222
229
  break;
223
230
  }
@@ -225,6 +232,29 @@ class Platform extends base_1.Base {
225
232
  return this.accessoryList;
226
233
  });
227
234
  }
235
+ doUpgradeV62() {
236
+ function readFile(type) {
237
+ const fn = config_1.kConfigFiles + "/config." + type + ".json";
238
+ try {
239
+ const configBuf = (0, fs_1.readFileSync)(fn);
240
+ const configStr = configBuf.toString();
241
+ return (types_1.Sanitizers[type])(JSON.parse(configStr));
242
+ }
243
+ catch (err) {
244
+ (0, logger_1.log)("system", "Couldn't read my config file (" + fn + ") -- setting to 'false'");
245
+ return false;
246
+ }
247
+ }
248
+ this.config.system = readFile("system");
249
+ this.config.smartapp = readFile("smartapp");
250
+ this.config.scenes = readFile("scenes");
251
+ this.config.settings = readFile("settings");
252
+ this.config.smappee = readFile("smappee");
253
+ this.config.p1 = readFile("p1");
254
+ this.config.shelly = readFile("shelly");
255
+ (0, config_1.setConfig)(this.config);
256
+ (0, logger_1.log)("homebridge", "Upgraded the config file -> NOW: log in and save something...");
257
+ }
228
258
  }
229
259
  exports.Platform = Platform;
230
260
  //# sourceMappingURL=platform.js.map
@@ -1,4 +1,5 @@
1
- import { log, setLogFunction, LogLevel, logSettings, PlatformConfig, UnitExtendedType } from "../duotecno/types";
1
+ import { PlatformConfig, Sanitizers, UnitExtendedType } from "../duotecno/types";
2
+ import { log, setLogFunction, LogLevel, logSettings } from "../duotecno/logger";
2
3
  import { API, Logger } from "homebridge";
3
4
  import { System } from "../duotecno/system";
4
5
  import { Smappee } from "./smappee";
@@ -18,6 +19,8 @@ import { Door } from "../accessories/door";
18
19
  import { Lock } from "../accessories/lock";
19
20
  import { P1 } from "./p1";
20
21
  import { Shelly } from "./shelly";
22
+ import { kConfigFiles, setConfig } from "../duotecno/config";
23
+ import { fstat, readFileSync } from "fs";
21
24
 
22
25
 
23
26
  export class Platform extends Base {
@@ -31,25 +34,31 @@ export class Platform extends Base {
31
34
  ready = false;
32
35
  startWaiting = 0;
33
36
 
34
- constructor(logger: Logger, config: PlatformConfig, api: API) {
35
- // set debug to true for new config files
37
+ constructor(logger: Logger, pConfig: PlatformConfig, api: API) {
36
38
  super("homebridge");
37
39
  if (logger.info) setLogFunction(logger.info);
38
40
 
39
- this.config = {... config};
40
- this.config.debug = (config && ("debug" in config)) ? config.debug : false;
41
+ this.config = {... pConfig};
42
+ this.config.debug = (pConfig && ("debug" in pConfig)) ? pConfig.debug : false;
41
43
  if (this.config.debug) logSettings["homebridge"] = LogLevel.debug;
42
44
 
45
+ if (typeof this.config.system.cmasters === "undefined") {
46
+ log("homebridge", "try doing upgrade from pre v6.2 versions");
47
+ this.doUpgradeV62();
48
+ }
49
+
43
50
  log("homebridge", "running in " + ((this.config.debug) ? "debug" : "prod") + " mode in directory: " + process.cwd());
44
- log("homebridge", "config files in " + this.configFiles + "/config.xxx.json");
45
- log("homebridge", "with config:" + JSON.stringify(config, null, 2));
46
- // log("homebridge", "homebridge object:", api);
51
+ log("homebridge", "with config:" + JSON.stringify(this.config, null, 2));
52
+
53
+ // save config for other components
54
+ setConfig(this.config);
47
55
 
56
+ // remember api for later use
48
57
  this.homebridgeAPI = api;
49
58
 
50
59
  if (this.config.system) {
51
60
  try {
52
- this.system = new System(false);
61
+ this.system = new System();
53
62
  this.system.openMasters(true);
54
63
 
55
64
  this.system.emitter.on('ready', this.systemReady.bind(this));
@@ -74,10 +83,10 @@ export class Platform extends Base {
74
83
  this.startPower("shelly", Shelly);
75
84
 
76
85
 
77
- // startup a smartApp if configured -> only on Raspberry's
86
+ // startup a smartApp if configured
78
87
  if (this.config.smartapp) {
79
88
  try {
80
- this.smartapp = new SmartApp(this.system, this.power, this, false);
89
+ this.smartapp = new SmartApp(this.system, this.power, this);
81
90
  this.smartapp.serve();
82
91
 
83
92
  } catch(err) {
@@ -90,7 +99,7 @@ export class Platform extends Base {
90
99
  log("homebridge", "platform - No SmartApp configured.");
91
100
  }
92
101
 
93
- // startup a SocApp if configured -> for servers
102
+ // startup a SocApp if configured -> for proxy (not needed)
94
103
  if (this.config.socapp) {
95
104
  try {
96
105
  // reuse the config file from the smartapp
@@ -249,4 +258,30 @@ export class Platform extends Base {
249
258
  return this.accessoryList;
250
259
  }
251
260
 
261
+
262
+ doUpgradeV62() {
263
+ function readFile(type: string): object | boolean {
264
+ const fn = kConfigFiles + "/config." + type + ".json";
265
+ try {
266
+ const configBuf = readFileSync(fn);
267
+ const configStr = configBuf.toString();
268
+ return (Sanitizers[type])(JSON.parse(configStr));
269
+
270
+ } catch(err) {
271
+ log("system", "Couldn't read my config file (" + fn + ") -- setting to 'false'");
272
+ return false;
273
+ }
274
+ }
275
+ this.config.system = readFile("system");
276
+ this.config.smartapp = readFile("smartapp");
277
+ this.config.scenes = readFile("scenes");
278
+ this.config.settings = readFile("settings");
279
+ this.config.smappee = readFile("smappee");
280
+ this.config.p1 = readFile("p1");
281
+ this.config.shelly = readFile("shelly");
282
+ setConfig(this.config);
283
+
284
+ log("homebridge", "Upgraded the config file -> NOW: log in and save something...");
285
+ }
286
+
252
287
  }