homebridge-smartsystem 6.0.6 → 6.0.9

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 CHANGED
@@ -237,7 +237,9 @@ switch =>
237
237
  ## v5.14.1 - todo
238
238
  - listen on gpio pin
239
239
 
240
-
240
+ ## v6.0.x - 01-07-2022
241
+ - .1: first version running on Homebridge UI
242
+ - .9: read version from package.json
241
243
 
242
244
  ## Hardware
243
245
  A Raspberry Pi that connects to a Duotecno IP Node
@@ -304,7 +306,112 @@ this $ is replaced by the value of the attached unit
304
306
  Example: http://192.168.0.101/relay/0?turn=on&brightness=$
305
307
 
306
308
 
307
- ## How to set up a Raspberry Pi
309
+ ## How to set up a Raspberry Pi - from V6.0 on
310
+ ```
311
+ 1. Setup Debian in Pi on 192.168.0.9
312
+
313
+ - download “Raspberry Pi Imager” from https://www.raspberrypi.com/software/
314
+ - install “Raspberry PI OS Lite 32bit” in settings: user, password, name, enable ssh, etc… in settings
315
+ - add “ip=192.168.0.9” to /boot/cmdline.txt (or whatever free address)
316
+ - put the card into a Pi and power on
317
+ - try to connect with ssh pi@192.168.0.9
318
+
319
+
320
+ 2. Install Homebridge
321
+
322
+ (see instructions on https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian)
323
+
324
+ Execute on the Pi via ssh:
325
+
326
+ # if forgotten:
327
+ # 1. for better security enable public key
328
+ mkdir ~/.ssh
329
+ chmod 700 ~/.ssh
330
+ cat "Mac/PC .ssh/id_rsa.pub" >> ~/.ssh/authorized_keys
331
+ chmod 600 ~/.ssh/authorized_keys
332
+ rm ~/id_rsa.pub
333
+
334
+ # 2. use pi-config
335
+ sudo raspi-config
336
+ -> enable ssh
337
+ -> boot to cmdline
338
+
339
+ # Add Homebridge to repo’s
340
+ curl -sSfL https://repo.homebridge.io/KEY.gpg | sudo gpg --dearmor | sudo tee /usr/share/keyrings/homebridge.gpg > /dev/null
341
+ echo "deb [signed-by=/usr/share/keyrings/homebridge.gpg] https://repo.homebridge.io stable main" | sudo tee /etc/apt/sources.list.d/homebridge.list > /dev/null
342
+
343
+ # Install Homebridge
344
+ sudo apt-get update
345
+ sudo apt-get --yes install homebridge
346
+ sudo ln -s /opt/homebridge/bin/node /usr/bin/node
347
+ sudo ln -s /opt/homebridge/bin/npm /usr/bin/npm
348
+
349
+ # install smappee and mqtt
350
+ sudo npm install -g --force mqtt
351
+ sudo ln -s /opt/homebridge/bin/mqtt /usr/bin/mqtt
352
+
353
+ # connect to homebridge UI with a browser
354
+ http://192.168.0.9:8581
355
+ add user, for example: pi / pw…
356
+
357
+ # add duotecno plugin to Homebridge config
358
+ go to "Plugins"
359
+ search for "smartsystem"
360
+ click "install"
361
+
362
+ # or in advance:
363
+ cd /var/lib/homebridge
364
+ sudo npm install --save homebridge-smartsystem
365
+
366
+
367
+ # set config to:
368
+         {
369
+             "manufacturer": "Duotecno-Coppieters",
370
+             "name": "Duotecno",
371
+             "platform": "DuotecnoPlatform",
372
+             "smappee": true,
373
+             "smartapp": true,
374
+             "system": true,
375
+             "socapp": false
376
+         }
377
+
378
+ # restart Homebridge in webbrowser (right top icon)
379
+
380
+ # connect to Duotecno gateway
381
+ http://192.168.0.9:5002
382
+ add master and off you go… see "setup" a little bit higher
383
+
384
+
385
+ 3. Various optional
386
+
387
+ Updates
388
+ sudo apt-get update
389
+ sudo apt-get install homebridge
390
+ sudo hb-service update-node
391
+
392
+
393
+ Uninstall
394
+ sudo apt-get remove homebridge
395
+ sudo rm -rf /etc/apt/sources.list.d/homebridge.list
396
+ sudo apt-get purge homebridge
397
+
398
+
399
+ 4. Smappee
400
+
401
+ #find uuid
402
+ mqtt sub -t 'servicelocation/#' -h '192.168.0.186’ -v
403
+ # -> 57e3e0d8-bb05-4b04-8662-1a9871998f3f
404
+
405
+ #add uuid
406
+ mqtt sub -t 'servicelocation/57e3e0d8-bb05-4b04-8662-1a9871998f3f/#' -h '192.168.0.186' -v
407
+
408
+ # http://pro.smappee.net
409
+ # duotecno/duotecno1234
410
+ # 192.168.0.2
411
+
412
+ ```
413
+
414
+ ## How to set up a Raspberry Pi - V1
308
415
 
309
416
  ### Copy SD Card
310
417
  dump ->
@@ -9,9 +9,10 @@ class Accessory {
9
9
  constructor(log, api, unit) {
10
10
  this.homebridge = api.hap;
11
11
  this.log = log; // : function(message)
12
- this.unit = unit; // : Unit
12
+ this.unit = unit; // : Duotecno Unit
13
13
  this.name = unit.getDisplayName();
14
14
  this.uuid_base = unit.getSerialNr();
15
+ // get all services and add ours
15
16
  this.services = this.getAccessoryServices();
16
17
  this.services.push(this.getInformationService());
17
18
  }
@@ -85,7 +86,7 @@ class Accessory {
85
86
  }
86
87
  updateState() {
87
88
  this.me.getCharacteristic(this.homebridge.Characteristic.On).updateValue(this.unit.status);
88
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> on = " + this.unit.status);
89
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> on = " + this.unit.status);
89
90
  }
90
91
  }
91
92
  exports.Accessory = Accessory;
@@ -1,5 +1,6 @@
1
- import { LogFunction, Service } from "../duotecno/types";
1
+ import { LogFunction } from "../duotecno/types";
2
2
  import { Unit } from "../duotecno/protocol";
3
+ import { API, HAP, Service } from "homebridge";
3
4
 
4
5
  // Johan Coppieters Jan 2019
5
6
  //
@@ -7,27 +8,29 @@ import { Unit } from "../duotecno/protocol";
7
8
  // handling the homekit required services.
8
9
 
9
10
  export class Accessory {
10
- homebridge: any; // homebridge api endpoint
11
+ homebridge: HAP; // homebridge api endpoint
11
12
  log: LogFunction;
12
13
  unit: Unit;
13
14
  config: any; // all config params
14
15
  name: string;
15
16
  uuid_base: string;
16
17
  services: Array<Service>;
17
- me: any; // some homebridge type... sorry. PlatformAccessory? Accessory?
18
+ me: Service;
18
19
 
19
20
 
20
- constructor(log: LogFunction, api, unit: Unit ) {
21
+ constructor(log: LogFunction, api: API, unit: Unit) {
21
22
  this.homebridge = api.hap;
22
23
  this.log = log; // : function(message)
23
- this.unit = unit; // : Unit
24
+ this.unit = unit; // : Duotecno Unit
24
25
  this.name = unit.getDisplayName();
25
26
  this.uuid_base = unit.getSerialNr();
27
+
28
+ // get all services and add ours
26
29
  this.services = this.getAccessoryServices();
27
30
  this.services.push(this.getInformationService());
28
31
  }
29
32
 
30
- makeService(service: Service): any {
33
+ makeService(service: any): Service {
31
34
  this.log("accessory - Making service: " + this.name + ", serial: " + this.uuid_base);
32
35
  this.me = new service(this.name);
33
36
  return this.me;
@@ -106,7 +109,7 @@ export class Accessory {
106
109
 
107
110
  updateState() {
108
111
  this.me.getCharacteristic(this.homebridge.Characteristic.On).updateValue(this.unit.status);
109
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> on = " + this.unit.status);
112
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> on = " + this.unit.status);
110
113
  }
111
114
 
112
115
  }
@@ -1,6 +1,7 @@
1
1
  import { Accessory } from "./accessory";
2
2
  import { LogFunction } from "../duotecno/types";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters Jan 2019
6
7
  //
@@ -12,7 +13,7 @@ import { Unit } from "../duotecno/protocol";
12
13
 
13
14
  export class Bulb extends Accessory {
14
15
 
15
- constructor(log: LogFunction, homebridge, unit: Unit) {
16
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
16
17
  super(log, homebridge, unit);
17
18
  }
18
19
 
@@ -68,7 +68,7 @@ class Dimmer extends accessory_1.Accessory {
68
68
  }
69
69
  updateState() {
70
70
  this.me.getCharacteristic(this.homebridge.Characteristic.Brightness).updateValue(this.unit.value);
71
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> Brightness = " + this.unit.value);
71
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> Brightness = " + this.unit.value);
72
72
  }
73
73
  }
74
74
  exports.Dimmer = Dimmer;
@@ -1,6 +1,7 @@
1
1
  import { Accessory } from "./accessory";
2
2
  import { LogFunction } from "../duotecno/types";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters Jan 2019
6
7
  //
@@ -14,7 +15,7 @@ export class Dimmer extends Accessory {
14
15
  preventSetPower: boolean;
15
16
  waitingSetPower: boolean;
16
17
 
17
- constructor(log: LogFunction, homebridge, unit: Unit) {
18
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
18
19
  super(log, homebridge, unit);
19
20
  this.currValue = 0;
20
21
  this.preventSetPower = false;
@@ -83,7 +84,7 @@ export class Dimmer extends Accessory {
83
84
 
84
85
  updateState() {
85
86
  this.me.getCharacteristic(this.homebridge.Characteristic.Brightness).updateValue(this.unit.value);
86
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> Brightness = " + this.unit.value);
87
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> Brightness = " + this.unit.value);
87
88
  }
88
89
 
89
90
  }
@@ -1,6 +1,8 @@
1
1
  import { Accessory } from "./accessory";
2
- import { UnitMotorCmd, UnitState } from "../duotecno/types";
2
+ import { LogFunction, UnitMotorCmd, UnitState } from "../duotecno/types";
3
3
  import { WindowCovering } from "./windowcovering";
4
+ import { Unit } from "../duotecno/protocol";
5
+ import { API } from "homebridge";
4
6
 
5
7
  // Johan Coppieters Jun 2020
6
8
  //
@@ -51,7 +53,7 @@ import { WindowCovering } from "./windowcovering";
51
53
  export class Door extends WindowCovering {
52
54
  targetState;
53
55
 
54
- constructor(log, homebridge, unit) {
56
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
55
57
  super(log, homebridge, unit);
56
58
  }
57
59
 
@@ -86,7 +86,7 @@ class GarageDoor extends accessory_1.Accessory {
86
86
  // in response to Duotecno status messages
87
87
  updateState() {
88
88
  const value = this.DT2HB(this.unit.status);
89
- this.log("Received updateState -> Homekit GarageDoor for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing to HB: " + value);
89
+ // this.log("Received updateState -> Homekit GarageDoor for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing to HB: " + value);
90
90
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentDoorState).updateValue(value);
91
91
  }
92
92
  }
@@ -1,4 +1,6 @@
1
- import { UnitMotorCmd, UnitState } from "../duotecno/types";
1
+ import { API } from "homebridge";
2
+ import { Unit } from "../duotecno/protocol";
3
+ import { LogFunction, UnitMotorCmd, UnitState } from "../duotecno/types";
2
4
  import { Accessory } from "./accessory";
3
5
 
4
6
  // Johan Coppieters Jun 2020
@@ -14,7 +16,7 @@ import { Accessory } from "./accessory";
14
16
  export class GarageDoor extends Accessory {
15
17
  targetState;
16
18
 
17
- constructor(log, homebridge, unit) {
19
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
18
20
  super(log, homebridge, unit);
19
21
  }
20
22
 
@@ -114,7 +116,7 @@ export class GarageDoor extends Accessory {
114
116
  // in response to Duotecno status messages
115
117
  updateState() {
116
118
  const value = this.DT2HB(this.unit.status);
117
- this.log("Received updateState -> Homekit GarageDoor for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing to HB: " + value);
119
+ // this.log("Received updateState -> Homekit GarageDoor for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing to HB: " + value);
118
120
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentDoorState).updateValue(value);
119
121
  }
120
122
 
@@ -67,7 +67,7 @@ class Lock extends accessory_1.Accessory {
67
67
  }
68
68
  // in response to Duotecno status messages
69
69
  updateState() {
70
- this.log("Received updateState -> Homekit Lock for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
70
+ // this.log("Received updateState -> Homekit Lock for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
71
71
  this.me.getCharacteristic(this.homebridge.Characteristic.LockCurrentState).updateValue(this.unit.status);
72
72
  }
73
73
  }
@@ -1,4 +1,6 @@
1
- import { UnitExtendedType } from "../duotecno/types";
1
+ import { API } from "homebridge";
2
+ import { Unit } from "../duotecno/protocol";
3
+ import { LogFunction, UnitExtendedType } from "../duotecno/types";
2
4
  import { Accessory } from "./accessory";
3
5
 
4
6
  // Johan Coppieters Jun 2020
@@ -14,7 +16,7 @@ import { Accessory } from "./accessory";
14
16
  export class Lock extends Accessory {
15
17
  targetState;
16
18
 
17
- constructor(log, homebridge, unit) {
19
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
18
20
  super(log, homebridge, unit);
19
21
  this.log("created Lock -> " + unit.getDescription());
20
22
 
@@ -86,7 +88,7 @@ export class Lock extends Accessory {
86
88
 
87
89
  // in response to Duotecno status messages
88
90
  updateState() {
89
- this.log("Received updateState -> Homekit Lock for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
91
+ // this.log("Received updateState -> Homekit Lock for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status);
90
92
  this.me.getCharacteristic(this.homebridge.Characteristic.LockCurrentState).updateValue(this.unit.status);
91
93
  }
92
94
 
@@ -50,7 +50,7 @@ class Mood extends accessory_1.Accessory {
50
50
  }
51
51
  updateState() {
52
52
  this.me.getCharacteristic(this.homebridge.Characteristic.On).updateValue(!!this.unit.value);
53
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> On = " + !!this.unit.value);
53
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> On = " + !!this.unit.value);
54
54
  }
55
55
  }
56
56
  exports.Mood = Mood;
@@ -1,6 +1,7 @@
1
1
  import { Accessory } from "./accessory";
2
2
  import { LogFunction, UnitExtendedType } from "../duotecno/types";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters Jan 2019
6
7
  //
@@ -12,7 +13,7 @@ import { Unit } from "../duotecno/protocol";
12
13
  export class Mood extends Accessory {
13
14
  myService;
14
15
 
15
- constructor(log: LogFunction, homebridge, unit: Unit) {
16
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
16
17
  super(log, homebridge, unit);
17
18
 
18
19
  }
@@ -60,7 +61,7 @@ export class Mood extends Accessory {
60
61
  }
61
62
  updateState() {
62
63
  this.me.getCharacteristic(this.homebridge.Characteristic.On).updateValue(!!this.unit.value);
63
- this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> On = " + !!this.unit.value);
64
+ // this.log("Received status change -> update accessory -> " + this.unit.getName() + " -> On = " + !!this.unit.value);
64
65
  }
65
66
 
66
67
  }
@@ -1,6 +1,7 @@
1
1
  import { LogFunction } from "../duotecno/types";
2
2
  import { Accessory } from "./accessory";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters Jan 2019
6
7
  //
@@ -10,7 +11,7 @@ import { Unit } from "../duotecno/protocol";
10
11
 
11
12
  export class Switch extends Accessory {
12
13
 
13
- constructor(log: LogFunction, homebridge, unit: Unit) {
14
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
14
15
  super(log, homebridge, unit);
15
16
 
16
17
  }
@@ -33,7 +33,7 @@ class Temperature extends accessory_1.Accessory {
33
33
  }
34
34
  updateState() {
35
35
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentTemperature).updateValue(this.unit.value / 10.0);
36
- this.log("Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " + this.unit.value / 10.0);
36
+ // this.log("Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " +(<number>this.unit.value) / 10.0);
37
37
  }
38
38
  }
39
39
  exports.Temperature = Temperature;
@@ -1,6 +1,7 @@
1
1
  import { Accessory } from "./accessory";
2
2
  import { LogFunction } from "../duotecno/types";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters Jan 2019
6
7
  //
@@ -11,7 +12,7 @@ import { Unit } from "../duotecno/protocol";
11
12
 
12
13
  export class Temperature extends Accessory {
13
14
 
14
- constructor(log: LogFunction, homebridge, unit: Unit) {
15
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
15
16
  super(log, homebridge, unit);
16
17
 
17
18
  }
@@ -41,7 +42,7 @@ export class Temperature extends Accessory {
41
42
 
42
43
  updateState() {
43
44
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentTemperature).updateValue((<number>this.unit.value) / 10.0);
44
- this.log("Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " +(<number>this.unit.value) / 10.0);
45
+ // this.log("Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " +(<number>this.unit.value) / 10.0);
45
46
  }
46
47
 
47
48
  }
@@ -133,7 +133,7 @@ class WindowCovering extends accessory_1.Accessory {
133
133
  // called in response to Duotecno status update
134
134
  updateState() {
135
135
  const value = this.DT2HB(this.unit.status);
136
- this.log("Received updateState -> Homekit WindowCovering for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing: " + value);
136
+ // this.log("Received updateState -> Homekit WindowCovering for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing: " + value);
137
137
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentPosition).updateValue(value);
138
138
  if (this.unit.status == types_1.UnitState.kClosing) {
139
139
  this.me.getCharacteristic(this.homebridge.Characteristic.TargetPosition).updateValue(0);
@@ -1,6 +1,7 @@
1
1
  import { Accessory } from "./accessory";
2
2
  import { LogFunction, UnitMotorCmd, UnitState } from "../duotecno/types";
3
3
  import { Unit } from "../duotecno/protocol";
4
+ import { API } from "homebridge";
4
5
 
5
6
  // Johan Coppieters v1: Jan 2019, v2: Jun 2020
6
7
  //
@@ -58,7 +59,7 @@ import { Unit } from "../duotecno/protocol";
58
59
  export class WindowCovering extends Accessory {
59
60
  targetState;
60
61
 
61
- constructor(log: LogFunction, homebridge, unit: Unit) {
62
+ constructor(log: LogFunction, homebridge: API, unit: Unit) {
62
63
  super(log, homebridge, unit);
63
64
  this.targetState = 0; // down or closed by default ??
64
65
 
@@ -159,7 +160,7 @@ export class WindowCovering extends Accessory {
159
160
  // called in response to Duotecno status update
160
161
  updateState() {
161
162
  const value = this.DT2HB(this.unit.status);
162
- this.log("Received updateState -> Homekit WindowCovering for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing: " + value);
163
+ // this.log("Received updateState -> Homekit WindowCovering for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.status + " / " + this.unit.value + " -> passing: " + value);
163
164
 
164
165
  this.me.getCharacteristic(this.homebridge.Characteristic.CurrentPosition).updateValue(value);
165
166
 
@@ -447,7 +447,8 @@ exports.Protocol = {
447
447
  emitter: null,
448
448
  setLogger(logger, debug) {
449
449
  this.logger = logger;
450
- this.debugger = debug || ((message, ...optionalParams) => { });
450
+ if (debug)
451
+ this.debugger = debug;
451
452
  },
452
453
  setEmitter(emitter) {
453
454
  this.emitter = emitter;
@@ -525,7 +525,7 @@ export const Protocol = {
525
525
 
526
526
  setLogger(logger: LogFunction, debug?: LogFunction) {
527
527
  this.logger = logger;
528
- this.debugger = debug || ((message: any, ...optionalParams: any[]) => {});
528
+ if (debug) this.debugger = debug;
529
529
  },
530
530
  setEmitter(emitter: EventEmitter) {
531
531
  this.emitter = emitter;
package/duotecno/types.ts CHANGED
@@ -273,7 +273,6 @@ export interface SmappeeConfig extends BaseConfig {
273
273
  // coming from Homebridge or from unit tests
274
274
  export type LogFunction = (message: any, ...optionalParams: any[]) => void;
275
275
  // needed as return objects to Homebridge
276
- export type Service = new (nodeName: string) => any;
277
276
 
278
277
 
279
278
  export interface Bridge {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-smartsystem",
3
3
  "displayname": "Duotecno Bridge",
4
- "version": "6.0.6",
4
+ "version": "6.0.9",
5
5
  "description": "SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
6
6
  "main": "index.js",
7
7
  "author": "Johan Coppieters",
package/server/base.js CHANGED
@@ -4,11 +4,17 @@ exports.Base = void 0;
4
4
  const fs = require("fs");
5
5
  const protocol_1 = require("../duotecno/protocol");
6
6
  const types_1 = require("../duotecno/types");
7
+ const fs_1 = require("fs");
8
+ const os_1 = require("os");
9
+ const kConfigFiles = (0, os_1.homedir)() + "/duotecno";
10
+ if (!(0, fs_1.existsSync)(kConfigFiles))
11
+ (0, fs_1.mkdirSync)(kConfigFiles);
7
12
  ///////////////
8
13
  // Log Class //
9
14
  ///////////////
10
15
  class Base {
11
16
  constructor(type, logger, config) {
17
+ this.configFiles = kConfigFiles;
12
18
  this.type = type || "base";
13
19
  this.logger = console.log; // logger || console.log;
14
20
  if (config)
@@ -43,7 +49,7 @@ class Base {
43
49
  this.write(this.type, this.config);
44
50
  }
45
51
  read(type, fname = "") {
46
- const fn = fname || ("~/.homebridge/config." + type + ".json");
52
+ const fn = fname || (this.configFiles + "/config." + type + ".json");
47
53
  let config = null;
48
54
  try {
49
55
  const configBuf = fs.readFileSync(fn);
@@ -61,7 +67,7 @@ class Base {
61
67
  return temp;
62
68
  }
63
69
  write(type, config, fname = "") {
64
- const fn = fname || ("~/.homebridge/config." + type + ".json");
70
+ const fn = fname || (this.configFiles + "/config." + type + ".json");
65
71
  try {
66
72
  config = types_1.Sanitizers[type](config);
67
73
  fs.writeFileSync(fn, JSON.stringify(config, null, 2));
package/server/base.ts CHANGED
@@ -3,6 +3,13 @@ import { Protocol } from "../duotecno/protocol";
3
3
  import { LogFunction, now, Sanitizers } from "../duotecno/types";
4
4
 
5
5
 
6
+ import { existsSync, mkdirSync } from "fs";
7
+ import { homedir } from "os";
8
+
9
+ const kConfigFiles = homedir() + "/duotecno";
10
+ if (! existsSync(kConfigFiles)) mkdirSync(kConfigFiles);
11
+
12
+
6
13
  ///////////////
7
14
  // Log Class //
8
15
  ///////////////
@@ -12,6 +19,7 @@ export class Base {
12
19
  debug: boolean;
13
20
  logger: LogFunction;
14
21
  config: any;
22
+ configFiles = kConfigFiles;
15
23
 
16
24
  constructor(type: string, logger?: LogFunction, config?) {
17
25
  this.type = type || "base";
@@ -57,7 +65,7 @@ export class Base {
57
65
 
58
66
 
59
67
  read(type: string, fname: string = "") {
60
- const fn = fname || ("~/.homebridge/config." + type + ".json");
68
+ const fn = fname || (this.configFiles + "/config." + type + ".json");
61
69
  let config = null;
62
70
 
63
71
  try {
@@ -78,7 +86,7 @@ export class Base {
78
86
  }
79
87
 
80
88
  write(type: string, config, fname: string = "") {
81
- const fn = fname || ("~/.homebridge/config." + type + ".json");
89
+ const fn = fname || (this.configFiles + "/config." + type + ".json");
82
90
  try {
83
91
  config = Sanitizers[type](config);
84
92
  fs.writeFileSync(fn, JSON.stringify(config, null, 2));
@@ -25,9 +25,6 @@ const base_1 = require("./base");
25
25
  const socapp_1 = require("./socapp");
26
26
  const door_1 = require("../accessories/door");
27
27
  const lock_1 = require("../accessories/lock");
28
- const fs_1 = require("fs");
29
- if (!(0, fs_1.existsSync)("~/homebridge"))
30
- (0, fs_1.mkdirSync)("~/homebridge");
31
28
  class Platform extends base_1.Base {
32
29
  constructor(log, config, api) {
33
30
  // set debug to true for new config files
@@ -38,6 +35,7 @@ class Platform extends base_1.Base {
38
35
  this.config = Object.assign({}, config);
39
36
  this.config.debug = (config && ("debug" in config)) ? config.debug : false;
40
37
  this.log("running in " + ((this.config.debug) ? "debug" : "prod") + " mode in directory: " + process.cwd());
38
+ this.log("config files in " + this.configFiles + "/config.xxx.json");
41
39
  this.log("with config:" + JSON.stringify(config, null, 2));
42
40
  // this.log("homebridge object:", api);
43
41
  this.homebridgeAPI = api;
@@ -1,4 +1,4 @@
1
- import { LogFunction, PlatformConfig, UnitExtendedType } from "../duotecno/types";
1
+ import { PlatformConfig, UnitExtendedType } from "../duotecno/types";
2
2
  import { API, Logger } from "homebridge";
3
3
  import { System } from "../duotecno/system";
4
4
  import { Smappee } from "./smappee";
@@ -16,11 +16,8 @@ import { Accessory } from "../accessories/accessory";
16
16
  import { SocApp } from "./socapp";
17
17
  import { Door } from "../accessories/door";
18
18
  import { Lock } from "../accessories/lock";
19
- import { existsSync, mkdirSync } from "fs";
20
19
 
21
20
 
22
- if (! existsSync("~/homebridge")) mkdirSync("~/homebridge");
23
-
24
21
  export class Platform extends Base {
25
22
  homebridgeAPI: API;
26
23
  config: PlatformConfig;
@@ -40,6 +37,7 @@ export class Platform extends Base {
40
37
  this.config.debug = (config && ("debug" in config)) ? config.debug : false;
41
38
 
42
39
  this.log("running in " + ((this.config.debug) ? "debug" : "prod") + " mode in directory: " + process.cwd());
40
+ this.log("config files in " + this.configFiles + "/config.xxx.json");
43
41
  this.log("with config:" + JSON.stringify(config, null, 2));
44
42
  // this.log("homebridge object:", api);
45
43
 
@@ -1,3 +1,3 @@
1
1
  <footer class="page-footer">
2
- <p>Johan Coppieters - Duotecno, 2019-2022 - v5.14.1</p>
2
+ <p>Johan Coppieters - Duotecno, 2019-<%= year %> - v<%= version %></p>
3
3
  </footer>
package/server/webapp.js CHANGED
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  });
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.WebApp = exports.Context = exports.single = void 0;
15
+ exports.WebApp = exports.Context = exports.kVersion = exports.single = void 0;
16
16
  const ejs = require("ejs");
17
17
  const http = require("http");
18
18
  const fs = require("fs");
@@ -30,6 +30,8 @@ function single(val) {
30
30
  return (val instanceof Array) ? val[0] : val;
31
31
  }
32
32
  exports.single = single;
33
+ exports.kVersion = require("../package.json").version;
34
+ console.log("stolen version: " + exports.kVersion);
33
35
  ///////////////////
34
36
  // Context Class //
35
37
  ///////////////////
@@ -61,6 +63,10 @@ class Context {
61
63
  this.res = res;
62
64
  // can be used for sending different answers
63
65
  this.jsonrequest = !!(((_a = req.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toLowerCase().indexOf('application/json')) > -1);
66
+ // helpers for ejs
67
+ this.today = new Date();
68
+ this.year = this.today.getFullYear();
69
+ this.version = exports.kVersion;
64
70
  this.nums = [0, 0, 0];
65
71
  // check short urls with numbers a parts
66
72
  const p1 = parseInt(this.request);
package/server/webapp.ts CHANGED
@@ -54,6 +54,8 @@ export function single(val: string | Array<string>): string {
54
54
  return (val instanceof Array) ? val[0] : val;
55
55
  }
56
56
 
57
+ export const kVersion = require("../package.json").version;
58
+ console.log("stolen version: " + kVersion);
57
59
 
58
60
  ///////////////////
59
61
  // Context Class //
@@ -70,6 +72,9 @@ export class Context {
70
72
  res: http.ServerResponse; // from http request
71
73
  jsonrequest: boolean; // from http request
72
74
  message = ""; // display if not empty
75
+ today: Date;
76
+ year: number;
77
+ version: string;
73
78
 
74
79
  time = types.time;
75
80
  hex = types.hex;
@@ -102,6 +107,11 @@ export class Context {
102
107
  // can be used for sending different answers
103
108
  this.jsonrequest = !!(req.headers['content-type']?.toLowerCase().indexOf('application/json')> -1);
104
109
 
110
+ // helpers for ejs
111
+ this.today = new Date();
112
+ this.year = this.today.getFullYear();
113
+ this.version = kVersion;
114
+
105
115
  this.nums = [0,0,0];
106
116
  // check short urls with numbers a parts
107
117
  const p1 = parseInt(this.request);