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/duotecno/types.ts
CHANGED
|
@@ -34,7 +34,7 @@ export enum UnitExtendedType /* extends UnitType */ {
|
|
|
34
34
|
kGarageDoor = 201, kDoor = 202, kLock = 203, kUnlocker = 204
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
// kPower == kTemperature name starting with "<" or ">"
|
|
38
38
|
// kLightbulb == kSwitch with no "*" or "$" in the name
|
|
39
39
|
// kDoor == kSwitchingMotor with "*" in the name
|
|
40
40
|
// kGarageDoor == kSwitchingMotor with "$" in the name
|
|
@@ -43,44 +43,6 @@ export enum UnitExtendedType /* extends UnitType */ {
|
|
|
43
43
|
// kUnlocker = kMood with $ in the name
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
/////////////
|
|
47
|
-
// Logging //
|
|
48
|
-
/////////////
|
|
49
|
-
|
|
50
|
-
// add LogLevels per type at runtime
|
|
51
|
-
export enum LogLevel { noLog = 0, log = 1, debug = 2 };
|
|
52
|
-
export const logSettings = {
|
|
53
|
-
"*": LogLevel.log,
|
|
54
|
-
"master": LogLevel.log,
|
|
55
|
-
"protocol": LogLevel.noLog,
|
|
56
|
-
"webapp": LogLevel.log,
|
|
57
|
-
"p1": LogLevel.log,
|
|
58
|
-
"power": LogLevel.log
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// can be overriden with server log function
|
|
62
|
-
export let logFunction = console.log;
|
|
63
|
-
export function setLogFunction(F) {
|
|
64
|
-
console.log(">>>>>>>>> NOT changing logfunction to: " + F.name + " <<<<<<<<<<");
|
|
65
|
-
// logFunction = (m) => { F(m) };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function err(type: string, message: string | object) {
|
|
69
|
-
logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
70
|
-
}
|
|
71
|
-
export function log(type: string, message: string | object) {
|
|
72
|
-
const level = logSettings[type] ?? logSettings["*"];
|
|
73
|
-
if (level) {
|
|
74
|
-
logFunction(type + ": " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export function debug(type: string, message: string | object) {
|
|
78
|
-
const level = logSettings[type] ?? logSettings["*"];
|
|
79
|
-
if (level === LogLevel.debug) {
|
|
80
|
-
logFunction(type + "> " + ((typeof message === "string") ? message : JSON.stringify(message)));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
46
|
//////////////
|
|
85
47
|
// Duotecno //
|
|
86
48
|
//////////////
|
|
@@ -90,9 +52,6 @@ export interface SystemConfig {
|
|
|
90
52
|
socketserver: string;
|
|
91
53
|
socketport: number;
|
|
92
54
|
mood: string;
|
|
93
|
-
language: string;
|
|
94
|
-
stores: boolean;
|
|
95
|
-
multiple: boolean;
|
|
96
55
|
debug?: boolean;
|
|
97
56
|
cmasters: Array<MasterConfig>;
|
|
98
57
|
cunits: Array<UnitConfig>;
|
|
@@ -281,6 +240,7 @@ export interface Switch extends UnitDef {
|
|
|
281
240
|
type: SwitchType,
|
|
282
241
|
plug: number | string,
|
|
283
242
|
data: string,
|
|
243
|
+
header: string,
|
|
284
244
|
method: string,
|
|
285
245
|
unit?: Unit;
|
|
286
246
|
status?: number | boolean,
|
|
@@ -289,11 +249,13 @@ export interface Switch extends UnitDef {
|
|
|
289
249
|
nostop: string;
|
|
290
250
|
};
|
|
291
251
|
export const kEmptySwitch: Switch =
|
|
292
|
-
{ ...kEmptyUnit, plug: 0, type: SwitchType.kNoType, unitName: "", name: "", data: "", method: "GET", nomacro: "N", nostop: "N"} as const;
|
|
252
|
+
{ ...kEmptyUnit, plug: 0, type: SwitchType.kNoType, unitName: "", name: "", data: "", method: "GET", header: "", nomacro: "N", nostop: "N"} as const;
|
|
293
253
|
|
|
294
254
|
|
|
295
255
|
export interface SmartAppConfig extends BaseConfig {
|
|
296
256
|
port: number;
|
|
257
|
+
apiHost: string;
|
|
258
|
+
apiPort: number;
|
|
297
259
|
switches: Array<Switch>;
|
|
298
260
|
}
|
|
299
261
|
|
|
@@ -350,7 +312,6 @@ export interface HomebridgeConfig {
|
|
|
350
312
|
password: string;
|
|
351
313
|
};
|
|
352
314
|
|
|
353
|
-
|
|
354
315
|
//////////////////
|
|
355
316
|
// SocketServer //
|
|
356
317
|
//////////////////
|
|
@@ -399,13 +360,12 @@ export const Sanitizers = {
|
|
|
399
360
|
if (!config) config = <PlatformConfig>{};
|
|
400
361
|
config.manufacturer = config.manufacturer || "Duotecno-Coppieters";
|
|
401
362
|
config.platform = config.platform || "DuotecnoPlatform";
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
363
|
+
config.smappee = config.smappee || false;
|
|
364
|
+
config.p1 = config.p1 || false;
|
|
365
|
+
config.shelly = config.shelly || false;
|
|
366
|
+
config.smartapp = config.smartapp || null;
|
|
367
|
+
config.system = Sanitizers.system(config.system);
|
|
368
|
+
|
|
409
369
|
return config;
|
|
410
370
|
},
|
|
411
371
|
|
|
@@ -418,23 +378,23 @@ export const Sanitizers = {
|
|
|
418
378
|
config.bridge.port = config.bridge.port || 51827;
|
|
419
379
|
config.bridge.pin = config.bridge.pin || "577-03-001";
|
|
420
380
|
|
|
421
|
-
config.description = config.description || "Duotecno Platform";
|
|
422
|
-
config.password = config.password || ("!@#$%^&*()" + new Date().getTime());
|
|
423
|
-
|
|
424
381
|
config.platforms = config.platforms || [<PlatformConfig>{}];
|
|
425
|
-
for (let p in config.platforms)
|
|
382
|
+
for (let p in config.platforms)
|
|
383
|
+
if (config.platforms[p].platform == "DuotecnoPlatform")
|
|
384
|
+
config.platforms[p] = Sanitizers.platform(config.platforms[p]);
|
|
426
385
|
|
|
427
386
|
config.accessories = []; //config.accessories || [<AccessoryConfig>{}];
|
|
428
|
-
//for (let a in config.accessories)
|
|
387
|
+
//for (let a in config.accessories) Sanitizers.accessory(config.accessories[a]);
|
|
429
388
|
|
|
430
389
|
return config;
|
|
431
390
|
},
|
|
432
391
|
|
|
433
392
|
settings: function(config: SettingsConfig): SettingsConfig {
|
|
434
393
|
if (!config) config = <SettingsConfig>{};
|
|
435
|
-
config.network =
|
|
394
|
+
config.network = Sanitizers.networkConfig(config.network);
|
|
436
395
|
return config;
|
|
437
396
|
},
|
|
397
|
+
|
|
438
398
|
networkConfig: function(config: NetworkConfig): NetworkConfig {
|
|
439
399
|
if (!config) config = <NetworkConfig>{};
|
|
440
400
|
config.ip1 = config.ip1 || kEmptyNetworkConfig.ip1;
|
|
@@ -458,8 +418,11 @@ export const Sanitizers = {
|
|
|
458
418
|
if (!config) config = <SmartAppConfig>{};
|
|
459
419
|
config.port = config.port || 5002;
|
|
460
420
|
config.switches = config.switches || [];
|
|
461
|
-
config.switches.
|
|
421
|
+
config.switches = config.switches.map(sw => Sanitizers.switchConfig(sw));
|
|
462
422
|
config.debug = config.debug || false;
|
|
423
|
+
config.apiHost = config.apiHost || "localhost";
|
|
424
|
+
config.apiPort = config.apiPort || 8581;
|
|
425
|
+
|
|
463
426
|
return config;
|
|
464
427
|
},
|
|
465
428
|
|
|
@@ -467,55 +430,59 @@ export const Sanitizers = {
|
|
|
467
430
|
if (!config) config = <PowerBaseConfig>{};
|
|
468
431
|
|
|
469
432
|
config.rules = config.rules || [];
|
|
470
|
-
config.rules = config.rules.map(sw =>
|
|
433
|
+
config.rules = config.rules.map(sw => Sanitizers.ruleConfig(sw));
|
|
471
434
|
|
|
472
435
|
config.bindings = config.bindings || [];
|
|
473
|
-
config.bindings = config.bindings.map(b =>
|
|
436
|
+
config.bindings = config.bindings.map(b => Sanitizers.bindingConfig(b));
|
|
474
437
|
|
|
475
438
|
config.address = config.address || "";
|
|
476
439
|
return config;
|
|
477
440
|
},
|
|
478
441
|
|
|
479
442
|
smappee: function(config: SmappeeConfig): SmappeeConfig {
|
|
480
|
-
config =
|
|
443
|
+
if (!config) config = <SmappeeConfig>{};
|
|
481
444
|
|
|
482
|
-
|
|
483
|
-
|
|
445
|
+
const cfg = <SmappeeConfig> Sanitizers.powerbase(config);
|
|
446
|
+
|
|
447
|
+
cfg.uid = config.uid || "--none--";
|
|
448
|
+
return cfg;
|
|
484
449
|
},
|
|
485
450
|
p1: function(config: P1Config): P1Config {
|
|
486
|
-
config =
|
|
451
|
+
config = Sanitizers.powerbase(config);
|
|
487
452
|
|
|
488
453
|
return config;
|
|
489
454
|
},
|
|
490
455
|
shelly: function(config: ShellyConfig): ShellyConfig {
|
|
491
|
-
config =
|
|
456
|
+
config = Sanitizers.powerbase(config);
|
|
492
457
|
|
|
493
458
|
return config;
|
|
494
459
|
},
|
|
495
460
|
|
|
496
461
|
switchConfig: function(aSwitch): Switch {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
462
|
+
const sw = <Switch>Sanitizers.unitDef(aSwitch);
|
|
463
|
+
sw.nomacro = aSwitch.nomacro || "N";
|
|
464
|
+
sw.nostop = aSwitch.nostop || "N";
|
|
465
|
+
sw.name = aSwitch.name || "--";
|
|
466
|
+
sw.unitName = aSwitch.unitName || "";
|
|
467
|
+
sw.value = aSwitch.value || 0;
|
|
468
|
+
sw.data = aSwitch.data || "";
|
|
469
|
+
sw.header = aSwitch.header || "";
|
|
470
|
+
sw.method = aSwitch.method || "GET";
|
|
471
|
+
sw.type = aSwitch.type || SwitchType.kNoType;
|
|
506
472
|
// don't destroy 0 plug
|
|
507
473
|
if (typeof aSwitch.plug === "string")
|
|
508
|
-
|
|
474
|
+
sw.plug = aSwitch.plug || "";
|
|
509
475
|
|
|
510
|
-
return
|
|
476
|
+
return sw;
|
|
511
477
|
},
|
|
512
478
|
|
|
513
479
|
makeSwitchConfig: function(aSwitch): Switch {
|
|
514
|
-
return
|
|
480
|
+
return Sanitizers.switchConfig({ name: aSwitch.name, unitName: aSwitch.unitName,
|
|
515
481
|
masterAddress: aSwitch.masterAddress, masterPort: aSwitch.masterPort,
|
|
516
482
|
nomacro: aSwitch.nomacro, nostop: aSwitch.nostop,
|
|
517
483
|
logicalAddress: aSwitch.logicalAddress, logicalNodeAddress: aSwitch.logicalNodeAddress,
|
|
518
|
-
type: aSwitch.type, plug: aSwitch.plug,
|
|
484
|
+
type: aSwitch.type, plug: aSwitch.plug,
|
|
485
|
+
data: aSwitch.data, method: aSwitch.method, header: aSwitch.header });
|
|
519
486
|
},
|
|
520
487
|
|
|
521
488
|
ruleConfig(rule): Rule {
|
|
@@ -536,11 +503,11 @@ export const Sanitizers = {
|
|
|
536
503
|
},
|
|
537
504
|
|
|
538
505
|
bindingConfig(binding): Binding {
|
|
539
|
-
|
|
506
|
+
const b = <Binding>Sanitizers.unitDef({... binding});
|
|
540
507
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
return
|
|
508
|
+
b.channel = binding.channel || "0";
|
|
509
|
+
b.power = binding.power || NaN;
|
|
510
|
+
return b;
|
|
544
511
|
},
|
|
545
512
|
|
|
546
513
|
masterConfig: function(config?: MasterConfig): MasterConfig {
|
|
@@ -561,10 +528,7 @@ export const Sanitizers = {
|
|
|
561
528
|
system: function(config?: SystemConfig): SystemConfig {
|
|
562
529
|
if (!config) config = <SystemConfig>{};
|
|
563
530
|
config.mood = config.mood || "sfeer";
|
|
564
|
-
config.language = config.language || "EN";
|
|
565
531
|
config.debug = config.debug || false;
|
|
566
|
-
config.stores = config.stores || false;
|
|
567
|
-
config.multiple = config.multiple || false;
|
|
568
532
|
|
|
569
533
|
config.socketserver = config.socketserver || 'ws.duotecno.eu';
|
|
570
534
|
// correct old settings
|
|
@@ -572,32 +536,14 @@ export const Sanitizers = {
|
|
|
572
536
|
config.socketport = config.socketport || 9999;
|
|
573
537
|
|
|
574
538
|
config.cmasters = config.cmasters || [];
|
|
575
|
-
config.cmasters.
|
|
539
|
+
config.cmasters = config.cmasters.map(m => Sanitizers.masterConfig(m));
|
|
576
540
|
|
|
577
541
|
config.cunits = config.cunits || [];
|
|
578
|
-
config.cunits.
|
|
542
|
+
config.cunits = config.cunits.map(u => Sanitizers.unitConfig(u));
|
|
579
543
|
|
|
580
544
|
return config;
|
|
581
545
|
},
|
|
582
546
|
|
|
583
|
-
////////////
|
|
584
|
-
// Groups //
|
|
585
|
-
group: function(config?: GroupConfig): GroupConfig {
|
|
586
|
-
if (!config) return kEmptyGroup;
|
|
587
|
-
|
|
588
|
-
config.name = config.name || kEmptyGroup.name;
|
|
589
|
-
config.id = config.id || kEmptyGroup.id;
|
|
590
|
-
config.order = config.order || kEmptyGroup.order;
|
|
591
|
-
config.visible = (typeof config.visible === "boolean") ? config.visible : kEmptyGroup.visible;
|
|
592
|
-
return config;
|
|
593
|
-
},
|
|
594
|
-
|
|
595
|
-
groups: function(config?: Array<GroupConfig>): Array<GroupConfig> {
|
|
596
|
-
if (!config) return [{... kEmptyGroup}];
|
|
597
|
-
|
|
598
|
-
config.forEach(g => Sanitizers["group"](g));
|
|
599
|
-
return config;
|
|
600
|
-
},
|
|
601
547
|
|
|
602
548
|
//////////
|
|
603
549
|
// Node //
|
|
@@ -613,18 +559,18 @@ export const Sanitizers = {
|
|
|
613
559
|
//////////
|
|
614
560
|
// Unit //
|
|
615
561
|
unitDef: function(info: UnitDef) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
562
|
+
return {
|
|
563
|
+
logicalNodeAddress: info.logicalNodeAddress || 0,
|
|
564
|
+
logicalAddress: info.logicalAddress || 0,
|
|
565
|
+
masterAddress: info.masterAddress || '',
|
|
566
|
+
masterPort: info.masterPort || 5001
|
|
567
|
+
};
|
|
622
568
|
},
|
|
623
569
|
|
|
624
570
|
|
|
625
571
|
unitConfig: function(config?: UnitConfig) { // unitDef + active + group
|
|
626
572
|
if (!config) { config = <UnitConfig>{}; }
|
|
627
|
-
|
|
573
|
+
config = <UnitConfig>Sanitizers.unitDef(config);
|
|
628
574
|
|
|
629
575
|
config.active = config.active || 'N';
|
|
630
576
|
config.used = config.used || config.active;
|
|
@@ -639,7 +585,7 @@ export const Sanitizers = {
|
|
|
639
585
|
unitScene: function(config?: UnitScene) { // unitDef + value
|
|
640
586
|
// change + create new clean record for writing to config files
|
|
641
587
|
if (!config) { config = <UnitScene>{}; }
|
|
642
|
-
|
|
588
|
+
config = <UnitScene>Sanitizers.unitDef(config);
|
|
643
589
|
if (typeof config.value === "undefined") config.value = 0;
|
|
644
590
|
if (typeof config.value === "string") config.value = parseInt(config.value);
|
|
645
591
|
|
|
@@ -647,7 +593,8 @@ export const Sanitizers = {
|
|
|
647
593
|
logicalAddress: config.logicalAddress,
|
|
648
594
|
masterAddress: config.masterAddress,
|
|
649
595
|
masterPort: config.masterPort,
|
|
650
|
-
value: config.value
|
|
596
|
+
value: config.value,
|
|
597
|
+
name: config.name };
|
|
651
598
|
},
|
|
652
599
|
|
|
653
600
|
|
|
@@ -662,18 +609,18 @@ export const Sanitizers = {
|
|
|
662
609
|
if (typeof config.order === 'string') { newConfig.order = parseInt(config.order); }
|
|
663
610
|
newConfig.order = config.order || kEmptyScene.order;
|
|
664
611
|
|
|
665
|
-
newConfig.trigger =
|
|
612
|
+
newConfig.trigger = Sanitizers.unitScene(config.trigger);
|
|
666
613
|
|
|
667
614
|
config.units = config.units || kEmptyScene.units;
|
|
668
|
-
newConfig.units = config.units.map(u =>
|
|
615
|
+
newConfig.units = config.units.map(u => Sanitizers.unitScene(u));
|
|
669
616
|
|
|
670
617
|
return newConfig;
|
|
671
618
|
},
|
|
672
619
|
|
|
673
620
|
scenes: function(config?: Array<SceneConfig>): Array<SceneConfig> {
|
|
674
|
-
if (!config) { return [
|
|
621
|
+
if (!config) { return [Sanitizers.sceneConfig()]; }
|
|
675
622
|
|
|
676
|
-
config.
|
|
623
|
+
config = config.map(s => Sanitizers.sceneConfig(s));
|
|
677
624
|
return config;
|
|
678
625
|
},
|
|
679
626
|
|
|
@@ -712,13 +659,6 @@ export const Sanitizers = {
|
|
|
712
659
|
|
|
713
660
|
};
|
|
714
661
|
|
|
715
|
-
// add dev entries for dev configs
|
|
716
|
-
Sanitizers["system-dev"] = Sanitizers["system"];
|
|
717
|
-
Sanitizers["smartapp-dev"] = Sanitizers["smartapp"];
|
|
718
|
-
Sanitizers["smappee-dev"] = Sanitizers["smappee"];
|
|
719
|
-
Sanitizers["p1-dev"] = Sanitizers["p1"];
|
|
720
|
-
Sanitizers["shelly-dev"] = Sanitizers["shelly"];
|
|
721
|
-
|
|
722
662
|
|
|
723
663
|
//////////////////////
|
|
724
664
|
// Helper functions //
|
package/index.spec.js
CHANGED
|
@@ -3,54 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const platform_1 = require("./server/platform");
|
|
4
4
|
const protocol_1 = require("./duotecno/protocol");
|
|
5
5
|
const types_1 = require("./duotecno/types");
|
|
6
|
+
const logger_1 = require("./duotecno/logger");
|
|
6
7
|
const master_1 = require("./duotecno/master");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(0,
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
(0, logger_1.setLogFunction)(console.log);
|
|
11
|
+
logger_1.logSettings["spec"] = logger_1.LogLevel.debug;
|
|
12
|
+
let platform;
|
|
13
|
+
(0, logger_1.log)("spec", "running in directory: " + process.cwd());
|
|
14
|
+
const isMac = (os.platform() === "darwin");
|
|
15
|
+
const kConfigFiles = (isMac) ? (__dirname) : (os.homedir() + "/duotecno");
|
|
16
|
+
if (!fs.existsSync(kConfigFiles))
|
|
17
|
+
fs.mkdirSync(kConfigFiles);
|
|
18
|
+
const fn = kConfigFiles + "/config.json";
|
|
19
|
+
(0, logger_1.log)("spec", "Config in " + fn);
|
|
13
20
|
function adder(plugin, platform, list) {
|
|
14
|
-
(0,
|
|
15
|
-
(0,
|
|
21
|
+
(0, logger_1.log)("spec", "************* plugin: " + plugin + ", platform: " + platform);
|
|
22
|
+
(0, logger_1.log)("spec", "************* list: " + JSON.stringify(list));
|
|
16
23
|
}
|
|
17
24
|
function tester() {
|
|
18
|
-
const platform = new platform_1.Platform(console, { debug: false, smappee: true, smartapp: true, socapp: false, system: true,
|
|
19
|
-
manufacturer: "Duotecno", platform: "ssoc", password: "TesterSpec" }, { registerPlatformAccessories: adder });
|
|
20
25
|
// testing
|
|
21
26
|
let m = new master_1.Master(platform.system, types_1.Sanitizers.masterConfig({ name: "master1", address: "12", port: 21, password: "x", active: true, nodenames: {} }));
|
|
22
27
|
let n = new protocol_1.Node(m, types_1.Sanitizers.nodeInfo({ name: "node1" }));
|
|
23
28
|
let u = new protocol_1.Unit(n, types_1.Sanitizers.unitInfo({ name: "unit|123 $", type: 7 }));
|
|
24
|
-
(0,
|
|
29
|
+
(0, logger_1.log)("spec", "Testing names -> getName = " + u.getName() + ", getDisplayname = " + u.getDisplayName() + ", type " + u.type + ", extType = " + u.extendedType + ", getTypeName = " + u.typeName());
|
|
25
30
|
u = new protocol_1.Unit(n, types_1.Sanitizers.unitInfo({ name: "unit|20", type: 1 }));
|
|
26
|
-
(0,
|
|
31
|
+
(0, logger_1.log)("spec", "Testing names -> getName = " + u.getName() + ", getDisplayname = " + u.getDisplayName() + ", type " + u.type + ", extType = " + u.extendedType + ", getTypeName = " + u.typeName());
|
|
27
32
|
}
|
|
28
|
-
function alertS(a, b) {
|
|
29
|
-
(0, types_1.log)("spec", a);
|
|
30
|
-
if (b)
|
|
31
|
-
(0, types_1.log)("spec", b);
|
|
32
|
-
}
|
|
33
|
-
let system;
|
|
34
33
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const p1 = new p1_1.P1(system, true);
|
|
40
|
-
const platform = new platform_1.Platform(console, { debug: false, smappee: true, smartapp: true, socapp: false, system: true,
|
|
41
|
-
manufacturer: "Duotecno", platform: "ssoc", password: "TesterSpec" }, { registerPlatformAccessories: adder });
|
|
42
|
-
//const smartapp = new SmartApp(system, {smappee, p1}, platform, true);
|
|
43
|
-
//const smartapp = new SocApp(system, "smartapp", console.log, 9999);
|
|
44
|
-
//smartapp.serve();
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
(0, types_1.log)("spec", err);
|
|
48
|
-
}
|
|
34
|
+
const configBuf = fs.readFileSync(fn);
|
|
35
|
+
const configStr = configBuf.toString();
|
|
36
|
+
const config = JSON.parse(configStr);
|
|
37
|
+
platform = new platform_1.Platform(console, config, { registerPlatformAccessories: adder });
|
|
49
38
|
}
|
|
50
39
|
catch (err) {
|
|
51
|
-
(0,
|
|
52
|
-
if (!system) {
|
|
53
|
-
(0, types_1.log)("spec", "Can't run without a System.");
|
|
54
|
-
}
|
|
40
|
+
(0, logger_1.log)("spec", err);
|
|
55
41
|
}
|
|
56
42
|
//# sourceMappingURL=index.spec.js.map
|
package/index.spec.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { Platform } from "./server/platform";
|
|
2
2
|
import { Unit, Node } from "./duotecno/protocol";
|
|
3
|
-
import {
|
|
3
|
+
import { Sanitizers } from "./duotecno/types";
|
|
4
|
+
import { log, LogLevel, logSettings, setLogFunction } from "./duotecno/logger";
|
|
4
5
|
import { Master } from "./duotecno/master";
|
|
5
|
-
import { System } from "./duotecno/system";
|
|
6
|
-
import { SmartApp } from "./server/smartapp";
|
|
7
|
-
import { Smappee } from "./server/smappee";
|
|
8
6
|
import { API } from "homebridge";
|
|
9
|
-
import
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as os from "os";
|
|
10
9
|
|
|
11
10
|
setLogFunction(console.log);
|
|
12
11
|
logSettings["spec"] = LogLevel.debug;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
let platform;
|
|
15
14
|
log("spec", "running in directory: " + process.cwd());
|
|
16
15
|
|
|
16
|
+
const isMac = (os.platform() === "darwin");
|
|
17
|
+
const kConfigFiles = (isMac) ? (__dirname) : (os.homedir() + "/duotecno");
|
|
18
|
+
if (! fs.existsSync(kConfigFiles)) fs.mkdirSync(kConfigFiles);
|
|
19
|
+
|
|
20
|
+
const fn = kConfigFiles + "/config.json";
|
|
21
|
+
log("spec", "Config in " + fn);
|
|
22
|
+
|
|
17
23
|
function adder(plugin: string, platform: string, list: any[]) {
|
|
18
24
|
log("spec", "************* plugin: " + plugin + ", platform: " + platform);
|
|
19
25
|
log("spec", "************* list: " + JSON.stringify(list));
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
function tester() {
|
|
23
|
-
const platform = new Platform(console, {debug: false, smappee: true, smartapp: true, socapp: false, system: true,
|
|
24
|
-
manufacturer: "Duotecno", platform: "ssoc", password: "TesterSpec"}, <API>{registerPlatformAccessories: adder});
|
|
25
|
-
|
|
26
|
-
|
|
27
29
|
// testing
|
|
28
30
|
let m = new Master(platform.system, Sanitizers.masterConfig({name: "master1", address: "12", port: 21, password:"x", active: true, nodenames: {}}));
|
|
29
31
|
let n = new Node(m, Sanitizers.nodeInfo({name: "node1"}));
|
|
@@ -32,32 +34,17 @@ function tester() {
|
|
|
32
34
|
u = new Unit(n, Sanitizers.unitInfo({name: "unit|20", type: 1}));
|
|
33
35
|
log("spec", "Testing names -> getName = " + u.getName() + ", getDisplayname = " + u.getDisplayName() + ", type " + u.type + ", extType = " + u.extendedType + ", getTypeName = " + u.typeName());
|
|
34
36
|
}
|
|
35
|
-
function alertS(a, b) {
|
|
36
|
-
log("spec", a);
|
|
37
|
-
if (b) log("spec", b)
|
|
38
|
-
}
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
|
|
39
|
+
|
|
41
40
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const p1 = new P1(system, true);
|
|
48
|
-
const platform = new Platform(console, {debug: false, smappee: true, smartapp: true, socapp: false, system: true,
|
|
49
|
-
manufacturer: "Duotecno", platform: "ssoc", password: "TesterSpec"}, <API>{registerPlatformAccessories: adder});
|
|
50
|
-
|
|
51
|
-
//const smartapp = new SmartApp(system, {smappee, p1}, platform, true);
|
|
52
|
-
//const smartapp = new SocApp(system, "smartapp", console.log, 9999);
|
|
53
|
-
//smartapp.serve();
|
|
54
|
-
} catch(err) {
|
|
55
|
-
log("spec", err);
|
|
56
|
-
}
|
|
41
|
+
const configBuf = fs.readFileSync(fn);
|
|
42
|
+
const configStr = configBuf.toString();
|
|
43
|
+
const config = JSON.parse(configStr);
|
|
44
|
+
|
|
45
|
+
platform = new Platform(console, config, <API>{registerPlatformAccessories: adder});
|
|
57
46
|
|
|
58
47
|
} catch(err) {
|
|
59
48
|
log("spec", err);
|
|
60
|
-
if (!system) {
|
|
61
|
-
log("spec", "Can't run without a System.");
|
|
62
|
-
}
|
|
63
49
|
}
|
|
50
|
+
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-smartsystem",
|
|
3
3
|
"displayname": "Duotecno Bridge",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.2.2",
|
|
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",
|
|
8
8
|
"homepage": "http://www.duotecno.be",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"start": "DEBUG=* homebridge -D -P '/Users/johan/
|
|
11
|
+
"start": "DEBUG=* homebridge -D -P '/Users/johan/Development/duotecno/smartsocket'",
|
|
12
12
|
"watch": "npx tsc --build . --watch"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
package/server/base.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Base = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const os_1 = require("os");
|
|
8
|
-
const isMac = ((0, os_1.platform)() === "darwin");
|
|
9
|
-
const kConfigFiles = (isMac) ? (__dirname + "/..") : ((0, os_1.homedir)() + "/duotecno");
|
|
10
|
-
if (!(0, fs_1.existsSync)(kConfigFiles))
|
|
11
|
-
(0, fs_1.mkdirSync)(kConfigFiles);
|
|
4
|
+
const logger_1 = require("../duotecno/logger");
|
|
5
|
+
const config_1 = require("../duotecno/config");
|
|
12
6
|
///////////////
|
|
13
7
|
// Log Class //
|
|
14
8
|
///////////////
|
|
15
9
|
class Base {
|
|
16
10
|
constructor(type, config) {
|
|
17
|
-
this.configFiles = kConfigFiles;
|
|
18
11
|
this.type = type || "base";
|
|
19
12
|
if (config)
|
|
20
13
|
this.config = config;
|
|
21
14
|
else
|
|
22
15
|
this.readConfig();
|
|
23
16
|
if (this.debug)
|
|
24
|
-
|
|
25
|
-
(0,
|
|
17
|
+
logger_1.logSettings["system"] = logger_1.LogLevel.debug;
|
|
18
|
+
(0, logger_1.debug)("system", "==== read config -> " + JSON.stringify(this.config));
|
|
26
19
|
}
|
|
27
20
|
//////////////////
|
|
28
21
|
// Config stuff //
|
|
@@ -34,34 +27,13 @@ class Base {
|
|
|
34
27
|
writeConfig() {
|
|
35
28
|
this.write(this.type, this.config);
|
|
36
29
|
}
|
|
37
|
-
read(type
|
|
38
|
-
|
|
39
|
-
let config = null;
|
|
40
|
-
try {
|
|
41
|
-
const configBuf = fs.readFileSync(fn);
|
|
42
|
-
const configStr = configBuf.toString();
|
|
43
|
-
config = JSON.parse(configStr);
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
(0, types_1.log)("system", "Couldn't read my config file (" + fn + ") -- Creating empty config.");
|
|
47
|
-
}
|
|
48
|
-
// sanitize the config
|
|
49
|
-
const temp = types_1.Sanitizers[type](config);
|
|
50
|
-
// write if we created it (new intallations or new config params)
|
|
51
|
-
if (!config && temp)
|
|
52
|
-
this.write(type, temp, fname);
|
|
53
|
-
return temp;
|
|
30
|
+
read(type) {
|
|
31
|
+
return (0, config_1.getSubConfig)(type);
|
|
54
32
|
}
|
|
55
|
-
write(type, config
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
fs.writeFileSync(fn, JSON.stringify(config, null, 2));
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
(0, types_1.err)(this.type, "Couldn't write my " + type + " config file (" + fn + ")");
|
|
63
|
-
}
|
|
64
|
-
return config;
|
|
33
|
+
write(type, config) {
|
|
34
|
+
(0, config_1.setSubConfig)(type, config);
|
|
35
|
+
// but better to much than not enough
|
|
36
|
+
(0, config_1.setAPIConfig)();
|
|
65
37
|
}
|
|
66
38
|
}
|
|
67
39
|
exports.Base = Base;
|