iobroker-ucl 1.1.8 → 1.1.10

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.
@@ -0,0 +1,873 @@
1
+ const deviceShellyLampeWeiss: string = "Lampe Weiss";
2
+ const deviceShellyDimmer: string = "Dimmer";
3
+ const deviceShellyLampeRGB: string = "Lampe RGB"
4
+ const deviceShellySteckdose: string = "Steckdose"
5
+ const deviceShellyRollladen: string = "Rollladen"
6
+ const deviceShellySensor: string = "Sensor"
7
+
8
+ export abstract class AbstractShelly {
9
+ protected baseState: string;
10
+ protected etage: string;
11
+ protected raum: string;
12
+ protected device: string;
13
+ private id: number;
14
+ protected adapter:any;
15
+
16
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string) {
17
+ this.adapter = adapter;
18
+ this.id = id;
19
+ this.etage = etage;
20
+ this.raum = raum;
21
+ this.device = device;
22
+ this.baseState = baseState;
23
+ }
24
+
25
+ public getDeviceId() : string {
26
+ return "S" + this.id.toString().padStart(2, '0');
27
+ }
28
+
29
+ public getDeviceIdAsRawNumber() : number {
30
+ return this.id;
31
+ }
32
+
33
+ abstract getCategory(): string;
34
+
35
+ public getEtage() : string {
36
+ return this.etage;
37
+ }
38
+
39
+ public getRaum() : string {
40
+ return this.raum;
41
+ }
42
+
43
+ public getDevice() : string {
44
+ return this.device;
45
+ }
46
+
47
+ public getBezeichnung() : string {
48
+ return this.etage + " " + this.raum + " " + this.device;
49
+ }
50
+
51
+ public getIP() : string {
52
+ return this.adapter.getState(this.baseState + ".hostname").val;
53
+ }
54
+
55
+ public isNewFirmwareAvailable() : boolean {
56
+ return this.adapter.getState(this.baseState + ".firmware").val;
57
+ }
58
+
59
+ public getBaseState() : string {
60
+ return this.baseState;
61
+ }
62
+
63
+ public getReducedBaseState() : string {
64
+ return this.baseState.replace("shelly.0.", "");
65
+ }
66
+
67
+ // Shelly1, Shelly2.5,...
68
+ public getType() : string {
69
+ var typ = this.adapter.getState(this.baseState + ".id").val;
70
+ if (typ == "shelly1") {
71
+ return "1";
72
+ } else if (typ == "shellyswitch25") {
73
+ return "2.5";
74
+ } else if (typ == "shellyswitch") {
75
+ return "2.0";
76
+ } else if (typ == "shellyplug-s") {
77
+ return "Plug";
78
+ } else if (typ == "shellyem3") {
79
+ return "3EM";
80
+ } else {
81
+ return typ;
82
+ }
83
+ }
84
+
85
+ public getSignal() : string {
86
+ return this.adapter.getState(this.baseState + ".rssi").val;
87
+ }
88
+
89
+ public getUptime() : string {
90
+ return this.adapter.getState(this.baseState + ".uptime").val;
91
+ }
92
+
93
+ public getFirmware() : string {
94
+ var versionState = this.baseState + ".version";
95
+ var version = this.adapter.getState(versionState).val;
96
+ version= version.substr(0, version.indexOf('-'));
97
+ return version;
98
+ }
99
+
100
+ protected createIOTAdapterSmartDevices(smartName) {
101
+
102
+ // Level:
103
+ // ----------------------------------------------------------------------------------
104
+ var alexaLampeLevel = "0_userdata.0.alexa." + smartName + ".level";
105
+ this.adapter.createState(alexaLampeLevel, 0, {
106
+ name: alexaLampeLevel,
107
+ desc: alexaLampeLevel,
108
+ type: 'number',
109
+ read: true,
110
+ write: true
111
+ });
112
+
113
+ // @ts-ignore
114
+ let objLevel = this.adapter.getObject(alexaLampeLevel) as unknown as iobJS.StateObject;
115
+ objLevel.common = {
116
+ "type": "number",
117
+ "name": alexaLampeLevel,
118
+ "read": true,
119
+ "write": true,
120
+ "role": "level.dimmer",
121
+ "min": 0,
122
+ "max": 100,
123
+ "def": 0,
124
+ "smartName": {
125
+ "de": smartName,
126
+ "smartType": "LIGHT"
127
+ }
128
+ };
129
+ this.adapter.setObject(alexaLampeLevel, objLevel);
130
+
131
+ // HUE:
132
+ // ----------------------------------------------------------------------------------
133
+ var alexaLampeHue = "0_userdata.0.alexa." + smartName + ".hue";
134
+ this.adapter.createState(alexaLampeHue, 0, {
135
+ name: alexaLampeHue,
136
+ desc: alexaLampeHue,
137
+ type: 'number',
138
+ read: true,
139
+ write: true
140
+ });
141
+ // @ts-ignore
142
+ let objHue = this.adapter.getObject(alexaLampeHue) as unknown as iobJS.StateObject;
143
+ objHue.common = {
144
+ "name": alexaLampeHue,
145
+ "desc": alexaLampeHue,
146
+ "type": "number",
147
+ "read": true,
148
+ "write": true,
149
+ "role": "level.color.hue", // <---- Das ist wichtig, ohne dieses Common-Zeugs würde hier "state" stehen und die ALexa-App würde dieses Gerär nicht als "Farbe-Lampe" akzeptieren/erkennen
150
+ "smartName": {
151
+ "de": smartName,
152
+ "smartType": "LIGHT"
153
+ }
154
+ };
155
+ this.adapter.setObject(alexaLampeHue, objHue);
156
+
157
+ // SAT:
158
+ // ----------------------------------------------------------------------------------
159
+ var alexaLampeSat = "0_userdata.0.alexa." + smartName + ".sat";
160
+ this.adapter.createState(alexaLampeSat, 0, {
161
+ name: alexaLampeSat,
162
+ desc: alexaLampeSat,
163
+ type: 'number',
164
+ read: true,
165
+ write: true
166
+ });
167
+ // @ts-ignore
168
+ let obSat = this.adapter.getObject(alexaLampeSat) as unknown as iobJS.StateObject;
169
+ obSat.common = {
170
+ "name": alexaLampeSat,
171
+ "desc": alexaLampeSat,
172
+ "type": "number",
173
+ "read": true,
174
+ "write": true,
175
+ "role": "level.color.saturation", // <---- Das ist wichtig, ohne dieses Common-Zeugs würde hier "state" stehen und die ALexa-App würde dieses Gerär nicht als "Farbe-Lampe" akzeptieren/erkennen
176
+ "smartName": {
177
+ "de": smartName,
178
+ "smartType": "LIGHT"
179
+ }
180
+ };
181
+ this.adapter.setObject(alexaLampeSat, obSat);
182
+
183
+ // CT:
184
+ // ----------------------------------------------------------------------------------
185
+ var alexaLampeCT = "0_userdata.0.alexa." + smartName + ".ct";
186
+ this.adapter.createState(alexaLampeCT, 0, {
187
+ name: alexaLampeCT,
188
+ desc: alexaLampeCT,
189
+ type: 'number',
190
+ read: true,
191
+ write: true
192
+ });
193
+ // @ts-ignore
194
+ let objCT = this.adapter.getObject(alexaLampeCT) as unknown as iobJS.StateObject;
195
+ objCT.common = {
196
+ "type": "number",
197
+ "name": alexaLampeCT,
198
+ "read": true,
199
+ "write": true,
200
+ "role": "level.color.temperature",
201
+ "smartName": {
202
+ "de": smartName,
203
+ "smartType": "LIGHT"
204
+ }
205
+ };
206
+ this.adapter.setObject(alexaLampeCT, objCT);
207
+ }
208
+ }
209
+
210
+ export class ShellyLampeWeiss extends AbstractShelly {
211
+ protected alexaSmartNamesForOn:string[];
212
+ protected alexaSmartNamesForOff: string[];
213
+ protected alexaActionNamesForOn:string[];
214
+ protected alexaActionNamesForOff: string[];
215
+
216
+ private channel: number;
217
+ private additionalStates4TurnOn:string[];
218
+ private additionalStates4TurnOff:string[];
219
+ private nachtbeleuchtung:boolean;
220
+ private turnOffExitHouseSummer:boolean;
221
+ private turnOffExitHouseWinter:boolean;
222
+ private turnOnEnterHouseSummer:boolean;
223
+ private turnOnEnterHouseWinter:boolean;
224
+
225
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string, channel: number, alexaSmartNamesForOn:string[], alexaActionNamesForOn:string[], alexaSmartNamesForOff: string[],alexaActionNamesForOff: string[], additionalStates4TurnOn:string[], additionalStates4TurnOff:string[], nachtbeleuchtung:boolean, turnOffExitHouseSummer:boolean, turnOffExitHouseWinter:boolean, turnOnEnterHouseSummer:boolean, turnOnEnterHouseWinter:boolean) {
226
+ super(adapter, id, etage, raum, device, baseState);
227
+ this.turnOffExitHouseSummer = turnOffExitHouseSummer;
228
+ this.turnOffExitHouseWinter = turnOffExitHouseWinter;
229
+ this.turnOnEnterHouseSummer = turnOnEnterHouseSummer;
230
+ this.turnOnEnterHouseWinter = turnOnEnterHouseWinter;
231
+
232
+ this.nachtbeleuchtung = nachtbeleuchtung;
233
+ this.channel = channel;
234
+ this.alexaSmartNamesForOn = alexaSmartNamesForOn;
235
+ this.alexaSmartNamesForOff = alexaSmartNamesForOff;
236
+ this.alexaActionNamesForOn = alexaActionNamesForOn;
237
+ this.alexaActionNamesForOff = alexaActionNamesForOff;
238
+
239
+ this.additionalStates4TurnOn = additionalStates4TurnOn;
240
+ this.additionalStates4TurnOff = additionalStates4TurnOff;
241
+
242
+ this.additionalStates4TurnOn.forEach(booleanOnObj => {
243
+ this.createState(booleanOnObj);
244
+ });
245
+ this.additionalStates4TurnOff.forEach(tasterBooleanOffObj => {
246
+ this.createState(tasterBooleanOffObj);
247
+ });
248
+ this.alexaSmartNamesForOn.forEach(alexaSmartName => {
249
+ this.createIOTAdapterSmartDevices(alexaSmartName);
250
+ });
251
+ this.alexaSmartNamesForOff.forEach(alexaSmartName => {
252
+ this.createIOTAdapterSmartDevices(alexaSmartName);
253
+ });
254
+ this.alexaActionNamesForOn.forEach(alexaSmartName => {
255
+ this.createIOTAdapterSmartDevices(alexaSmartName);
256
+ });
257
+ this.alexaActionNamesForOff.forEach(alexaSmartName => {
258
+ this.createIOTAdapterSmartDevices(alexaSmartName);
259
+ });
260
+ }
261
+
262
+ private createState(key_in) {
263
+ var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
264
+ //log(">>> CREATE STATE: " + jarvisDatenpunkt);
265
+ this.adapter.createState(jarvisDatenpunkt, false, {
266
+ name: jarvisDatenpunkt,
267
+ desc: jarvisDatenpunkt,
268
+ type: 'boolean',
269
+ read: true,
270
+ write: true
271
+ });
272
+ }
273
+
274
+ public isTurnOffExitHouseSummer() : boolean {
275
+ return this.turnOffExitHouseSummer;
276
+ }
277
+
278
+ public isTurnOffExitHouseWinter() : boolean {
279
+ return this.turnOffExitHouseWinter;
280
+ }
281
+
282
+ public isTurnOnEnterHouseSummer() : boolean {
283
+ return this.turnOnEnterHouseSummer;
284
+ }
285
+
286
+ public isTurnOnEnterHouseWinter() : boolean {
287
+ return this.turnOnEnterHouseWinter;
288
+ }
289
+
290
+ public isNachtbeleuchtung() : boolean {
291
+ return this.nachtbeleuchtung;
292
+ }
293
+
294
+ public getAdditionalStates4TurnOn() : string[] {
295
+ return this.additionalStates4TurnOn;
296
+ }
297
+
298
+ public getAdditionalStates4TurnOff() : string[] {
299
+ return this.additionalStates4TurnOff;
300
+ }
301
+
302
+ public getSwitchState() : string {
303
+ return this.baseState + ".Relay" + this.channel + ".Switch";
304
+ }
305
+
306
+ public isDeviceOn() : boolean {
307
+ return this.adapter.getState(this.getSwitchState()).val;
308
+ }
309
+
310
+ public getCategory() : string {
311
+ return deviceShellyLampeWeiss;
312
+ }
313
+
314
+ public getAlexaNamesForOnAsString() : string {
315
+ var result = "";
316
+
317
+ this.alexaSmartNamesForOn.forEach(alexaOnName => {
318
+ if (result == "") {
319
+ result += alexaOnName
320
+ } else {
321
+ result += ", " + alexaOnName;
322
+ }
323
+ });
324
+ this.alexaActionNamesForOn.forEach(alexaOnName => {
325
+ if (result == "") {
326
+ result += alexaOnName
327
+ } else {
328
+ result += ", " + alexaOnName;
329
+ }
330
+ });
331
+
332
+ return result;
333
+ }
334
+
335
+ public getAlexaNamesForOffAsString() : string {
336
+ var result = "";
337
+
338
+ this.alexaSmartNamesForOff.forEach(alexaOffName => {
339
+ if (result == "") {
340
+ result += alexaOffName
341
+ } else {
342
+ result += ", " + alexaOffName;
343
+ }
344
+ });
345
+ this.alexaActionNamesForOff.forEach(alexaOffName => {
346
+ if (result == "") {
347
+ result += alexaOffName
348
+ } else {
349
+ result += ", " + alexaOffName;
350
+ }
351
+ });
352
+
353
+ return result;
354
+ }
355
+
356
+ public getAlexaSmartNamesForOn() : string[] {
357
+ return this.alexaSmartNamesForOn;
358
+ }
359
+
360
+ public getAlexaSmartNamesForOff() : string[] {
361
+ return this.alexaSmartNamesForOff;
362
+ }
363
+
364
+ public getAlexaActionNamesForOn() : string[] {
365
+ return this.alexaActionNamesForOn;
366
+ }
367
+
368
+ public getAlexaActionNamesForOff() : string[] {
369
+ return this.alexaActionNamesForOff;
370
+ }
371
+ }
372
+
373
+ export class ShellyDimmerAlexaScheme {
374
+ protected alexaName: string;
375
+ protected level: number;
376
+ protected device: ShellyDimmer;
377
+
378
+ constructor(alexaName: string, level: number) {
379
+ this.alexaName = alexaName;
380
+ this.level = level;
381
+ }
382
+
383
+ public getAlexaName() : string {
384
+ return this.alexaName;
385
+ }
386
+
387
+ public getLevel() : number {
388
+ return this.level;
389
+ }
390
+
391
+ public setDevice(device: ShellyDimmer) {
392
+ this.device = device;
393
+ }
394
+
395
+ public getDevice() : ShellyDimmer {
396
+ return this.device;
397
+ }
398
+ }
399
+
400
+ class ShellyDimmerTasterScheme {
401
+ protected tasterBooleanOn: string;
402
+ protected level: number;
403
+
404
+ constructor(tasterBooleanOn: string, level: number) {
405
+ this.tasterBooleanOn = tasterBooleanOn;
406
+ this.level = level;
407
+ }
408
+
409
+ public getTasterBooleanOnName() : string {
410
+ return this.tasterBooleanOn;
411
+ }
412
+
413
+ public getLevel() : number {
414
+ return this.level;
415
+ }
416
+ }
417
+
418
+ export class ShellyDimmer extends AbstractShelly {
419
+ protected alexaSmartNamesForOn:string[];
420
+ protected alexaSmartNamesForOff: string[];
421
+ protected alexaActionNamesForOn:string[];
422
+ protected alexaActionNamesForOff: string[];
423
+ protected alexaLevelSchemeForOn: ShellyDimmerAlexaScheme;
424
+ protected tasterBooleanOn: ShellyDimmerTasterScheme[];
425
+ protected levelSchemes: ShellyDimmerAlexaScheme[];
426
+ protected tasterBooleanOff: string[];
427
+
428
+ private nachtbeleuchtung:boolean;
429
+ private turnOffExitHouseSummer:boolean;
430
+ private turnOffExitHouseWinter:boolean;
431
+ private turnOnEnterHouseSummer:boolean;
432
+ private turnOnEnterHouseWinter:boolean;
433
+
434
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string,
435
+ alexaSmartNamesForOn:string[], alexaActionNamesForOn:string[], alexaLevelSchemeForOn: ShellyDimmerAlexaScheme,
436
+ alexaSmartNamesForOff: string[], alexaActionNamesForOff: string[], levelSchemes: ShellyDimmerAlexaScheme[], tasterBooleanOn: ShellyDimmerTasterScheme[],
437
+ tasterBooleanOff: string[],nachtbeleuchtung:boolean, turnOffExitHouseSummer:boolean, turnOffExitHouseWinter:boolean, turnOnEnterHouseSummer:boolean, turnOnEnterHouseWinter:boolean) {
438
+ super(adapter, id, etage, raum, device, baseState);
439
+ this.alexaSmartNamesForOn = alexaSmartNamesForOn;
440
+ this.alexaSmartNamesForOff = alexaSmartNamesForOff;
441
+ this.alexaActionNamesForOn = alexaActionNamesForOn;
442
+ this.alexaActionNamesForOff = alexaActionNamesForOff;
443
+
444
+ this.nachtbeleuchtung = nachtbeleuchtung;
445
+ this.turnOffExitHouseSummer = turnOffExitHouseSummer;
446
+ this.turnOffExitHouseWinter = turnOffExitHouseWinter;
447
+ this.turnOnEnterHouseSummer = turnOnEnterHouseSummer;
448
+ this.turnOnEnterHouseWinter = turnOnEnterHouseWinter;
449
+
450
+ this.alexaLevelSchemeForOn = alexaLevelSchemeForOn;
451
+ this.tasterBooleanOn = tasterBooleanOn;
452
+ this.levelSchemes = levelSchemes;
453
+ this.tasterBooleanOff = tasterBooleanOff;
454
+
455
+ if (this.alexaLevelSchemeForOn != null) {
456
+ this.alexaLevelSchemeForOn.setDevice(this);
457
+ if (alexaLevelSchemeForOn.getAlexaName() != null) {
458
+ this.createState(alexaLevelSchemeForOn.getAlexaName());
459
+ }
460
+ }
461
+ this.tasterBooleanOn.forEach(tasterScheme => {
462
+ if (tasterScheme.getTasterBooleanOnName() != null) {
463
+ this.createState(tasterScheme.getTasterBooleanOnName());
464
+ }
465
+ });
466
+ this.tasterBooleanOff.forEach(offName => {
467
+ this.createState(offName);
468
+ });
469
+
470
+ this.alexaSmartNamesForOn.forEach(alexaSmartName => {
471
+ this.createIOTAdapterSmartDevices(alexaSmartName);
472
+ });
473
+ this.alexaSmartNamesForOff.forEach(alexaSmartName => {
474
+ this.createIOTAdapterSmartDevices(alexaSmartName);
475
+ });
476
+ this.alexaActionNamesForOn.forEach(alexaSmartName => {
477
+ this.createIOTAdapterSmartDevices(alexaSmartName);
478
+ });
479
+ this.alexaActionNamesForOff.forEach(alexaSmartName => {
480
+ this.createIOTAdapterSmartDevices(alexaSmartName);
481
+ });
482
+ }
483
+
484
+ public isNachtbeleuchtung() : boolean {
485
+ return this.nachtbeleuchtung;
486
+ }
487
+
488
+ public isTurnOffExitHouseSummer() : boolean {
489
+ return this.turnOffExitHouseSummer;
490
+ }
491
+
492
+ public isTurnOffExitHouseWinter() : boolean {
493
+ return this.turnOffExitHouseWinter;
494
+ }
495
+
496
+ public isTurnOnEnterHouseSummer() : boolean {
497
+ return this.turnOnEnterHouseSummer;
498
+ }
499
+
500
+ public isTurnOnEnterHouseWinter() : boolean {
501
+ return this.turnOnEnterHouseWinter;
502
+ }
503
+
504
+ private createState(key_in) {
505
+ var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
506
+ //log(">>> CREATE STATE: " + jarvisDatenpunkt);
507
+ this.adapter.createState(jarvisDatenpunkt, false, {
508
+ name: jarvisDatenpunkt,
509
+ desc: jarvisDatenpunkt,
510
+ type: 'boolean',
511
+ read: true,
512
+ write: true
513
+ });
514
+ }
515
+
516
+ public getAlexaLevelSchemeForOn(): ShellyDimmerAlexaScheme {
517
+ return this.alexaLevelSchemeForOn;
518
+ }
519
+
520
+ public getAlexaSchemes(): ShellyDimmerAlexaScheme[] {
521
+ return this.levelSchemes;
522
+ }
523
+
524
+ public getTasterBooleanOn(): ShellyDimmerTasterScheme[] {
525
+ return this.tasterBooleanOn;
526
+ }
527
+
528
+ public getTasterBooleanOff(): string[] {
529
+ return this.tasterBooleanOff;
530
+ }
531
+
532
+ public getSwitchState() : string {
533
+ return this.baseState + ".lights.Switch"; // shelly.0.SHDM-2#98CDAC0BE168#1.lights.Switch
534
+ }
535
+
536
+ public isDeviceOn() : boolean {
537
+ return this.adapter.getState(this.getSwitchState()).val;
538
+ }
539
+
540
+ public getCategory() : string {
541
+ return deviceShellyDimmer;
542
+ }
543
+
544
+ public getAlexaNamesForOnAsString() : string {
545
+ var result = "";
546
+
547
+ this.alexaSmartNamesForOn.forEach(alexaOnName => {
548
+ if (result == "") {
549
+ result += alexaOnName
550
+ } else {
551
+ result += ", " + alexaOnName;
552
+ }
553
+ });
554
+ this.alexaActionNamesForOn.forEach(alexaOnName => {
555
+ if (result == "") {
556
+ result += alexaOnName
557
+ } else {
558
+ result += ", " + alexaOnName;
559
+ }
560
+ });
561
+
562
+ return result;
563
+ }
564
+
565
+ public getAlexaNamesForOffAsString() : string {
566
+ var result = "";
567
+
568
+ this.alexaSmartNamesForOff.forEach(alexaOffName => {
569
+ if (result == "") {
570
+ result += alexaOffName
571
+ } else {
572
+ result += ", " + alexaOffName;
573
+ }
574
+ });
575
+ this.alexaActionNamesForOff.forEach(alexaOffName => {
576
+ if (result == "") {
577
+ result += alexaOffName
578
+ } else {
579
+ result += ", " + alexaOffName;
580
+ }
581
+ });
582
+ return result;
583
+ }
584
+ public getAlexaSmartNamesForOn() : string[] {
585
+ return this.alexaSmartNamesForOn;
586
+ }
587
+
588
+ public getAlexaSmartNamesForOff() : string[] {
589
+ return this.alexaSmartNamesForOff;
590
+ }
591
+
592
+ public getAlexaActionNamesForOn() : string[] {
593
+ return this.alexaActionNamesForOn;
594
+ }
595
+
596
+ public getAlexaActionNamesForOff() : string[] {
597
+ return this.alexaActionNamesForOff;
598
+ }
599
+ }
600
+
601
+ export class ShellyRGBAlexaScheme {
602
+ protected alexaName: string;
603
+ protected level: number;
604
+ protected device: ShellyLampeRGB;
605
+
606
+ constructor(alexaName: string, level: number) {
607
+ this.alexaName = alexaName;
608
+ this.level = level;
609
+ }
610
+
611
+ public getAlexaName() : string {
612
+ return this.alexaName;
613
+ }
614
+
615
+ public getLevel() : number {
616
+ return this.level;
617
+ }
618
+
619
+ public setDevice(device: ShellyLampeRGB) {
620
+ this.device = device;
621
+ }
622
+
623
+ public getDevice() : ShellyLampeRGB {
624
+ return this.device;
625
+ }
626
+ }
627
+
628
+ export class ShellyRGBTasterScheme {
629
+ protected tasterBooleanOn: string;
630
+ protected level: number;
631
+
632
+ constructor(tasterBooleanOn: string, level: number) {
633
+ this.tasterBooleanOn = tasterBooleanOn;
634
+ this.level = level;
635
+ }
636
+
637
+ public getTasterBooleanOnName() : string {
638
+ return this.tasterBooleanOn;
639
+ }
640
+
641
+ public getLevel() : number {
642
+ return this.level;
643
+ }
644
+ }
645
+
646
+ export class ShellyLampeRGB extends AbstractShelly {
647
+ protected alexaSmartNamesForOn:string[];
648
+ protected alexaSmartNamesForOff: string[];
649
+ protected alexaActionNamesForOn:string[];
650
+ protected alexaActionNamesForOff: string[];
651
+ private channel: number;
652
+
653
+ protected alexaLevelSchemeForOn: ShellyRGBAlexaScheme;
654
+ protected tasterBooleanOn: ShellyRGBTasterScheme[];
655
+ protected levelSchemes: ShellyRGBAlexaScheme[];
656
+ protected tasterBooleanOff: string[];
657
+
658
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string, channel: number, alexaSmartNamesForOn:string[], alexaActionNamesForOn:string[], alexaLevelSchemeForOn: ShellyRGBAlexaScheme, alexaSmartNamesForOff: string[],alexaActionNamesForOff: string[], levelSchemes: ShellyRGBAlexaScheme[], tasterBooleanOn: ShellyRGBTasterScheme[], tasterBooleanOff: string[]) {
659
+ super(adapter, id, etage, raum, device, baseState);
660
+ this.channel = channel;
661
+ this.alexaSmartNamesForOn = alexaSmartNamesForOn;
662
+ this.alexaSmartNamesForOff = alexaSmartNamesForOff;
663
+ this.alexaActionNamesForOn = alexaActionNamesForOn;
664
+ this.alexaActionNamesForOff = alexaActionNamesForOff;
665
+
666
+ this.alexaLevelSchemeForOn = alexaLevelSchemeForOn;
667
+ this.tasterBooleanOn = tasterBooleanOn;
668
+ this.levelSchemes = levelSchemes;
669
+ this.tasterBooleanOff = tasterBooleanOff;
670
+
671
+ if (this.alexaLevelSchemeForOn != null) {
672
+ this.alexaLevelSchemeForOn.setDevice(this);
673
+ if (alexaLevelSchemeForOn.getAlexaName() != null) {
674
+ this.createState(alexaLevelSchemeForOn.getAlexaName());
675
+ }
676
+ }
677
+ this.tasterBooleanOn.forEach(tasterScheme => {
678
+ if (tasterScheme.getTasterBooleanOnName() != null) {
679
+ this.createState(tasterScheme.getTasterBooleanOnName());
680
+ }
681
+ });
682
+ this.tasterBooleanOff.forEach(offName => {
683
+ this.createState(offName);
684
+ });
685
+
686
+ this.alexaSmartNamesForOn.forEach(alexaSmartName => {
687
+ this.createIOTAdapterSmartDevices(alexaSmartName);
688
+ });
689
+ this.alexaSmartNamesForOff.forEach(alexaSmartName => {
690
+ this.createIOTAdapterSmartDevices(alexaSmartName);
691
+ });
692
+ this.alexaActionNamesForOn.forEach(alexaSmartName => {
693
+ this.createIOTAdapterSmartDevices(alexaSmartName);
694
+ });
695
+ this.alexaActionNamesForOff.forEach(alexaSmartName => {
696
+ this.createIOTAdapterSmartDevices(alexaSmartName);
697
+ });
698
+ }
699
+
700
+ private createState(key_in) {
701
+ var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
702
+ //log(">>> CREATE STATE: " + jarvisDatenpunkt);
703
+ this.adapter.createState(jarvisDatenpunkt, false, {
704
+ name: jarvisDatenpunkt,
705
+ desc: jarvisDatenpunkt,
706
+ type: 'boolean',
707
+ read: true,
708
+ write: true
709
+ });
710
+ }
711
+
712
+ public getAlexaLevelSchemeForOn(): ShellyRGBAlexaScheme {
713
+ return this.alexaLevelSchemeForOn;
714
+ }
715
+
716
+ public getAlexaSchemes(): ShellyRGBAlexaScheme[] {
717
+ return this.levelSchemes;
718
+ }
719
+
720
+ public getTasterBooleanOn(): ShellyRGBTasterScheme[] {
721
+ return this.tasterBooleanOn;
722
+ }
723
+
724
+ public getTasterBooleanOff(): string[] {
725
+ return this.tasterBooleanOff;
726
+ }
727
+
728
+ public getSwitchState() : string {
729
+ return this.baseState + ".lights.Switch"; // shelly.0.SHRGBW2#D962D3#1.lights.Switch
730
+ }
731
+
732
+ public isDeviceOn() : boolean {
733
+ return this.adapter.getState(this.getSwitchState()).val;
734
+ }
735
+
736
+
737
+ public getCategory() : string {
738
+ return deviceShellyLampeRGB;
739
+ }
740
+
741
+ public getAlexaNamesForOnAsString() : string {
742
+ var result = "";
743
+
744
+ this.alexaSmartNamesForOn.forEach(alexaOnName => {
745
+ if (result == "") {
746
+ result += alexaOnName
747
+ } else {
748
+ result += ", " + alexaOnName;
749
+ }
750
+ });
751
+ this.alexaActionNamesForOn.forEach(alexaOnName => {
752
+ if (result == "") {
753
+ result += alexaOnName
754
+ } else {
755
+ result += ", " + alexaOnName;
756
+ }
757
+ });
758
+
759
+ return result;
760
+ }
761
+
762
+ public getAlexaNamesForOffAsString() : string {
763
+ var result = "";
764
+
765
+ this.alexaSmartNamesForOff.forEach(alexaOffName => {
766
+ if (result == "") {
767
+ result += alexaOffName
768
+ } else {
769
+ result += ", " + alexaOffName;
770
+ }
771
+ });
772
+
773
+ this.alexaActionNamesForOff.forEach(alexaOffName => {
774
+ if (result == "") {
775
+ result += alexaOffName
776
+ } else {
777
+ result += ", " + alexaOffName;
778
+ }
779
+ });
780
+
781
+ return result;
782
+ }
783
+
784
+ public getAlexaSmartNamesForOn() : string[] {
785
+ return this.alexaSmartNamesForOn;
786
+ }
787
+
788
+ public getAlexaSmartNamesForOff() : string[] {
789
+ return this.alexaSmartNamesForOff;
790
+ }
791
+
792
+ public getAlexaActionNamesForOn() : string[] {
793
+ return this.alexaActionNamesForOn;
794
+ }
795
+
796
+ public getAlexaActionNamesForOff() : string[] {
797
+ return this.alexaActionNamesForOff;
798
+ }
799
+
800
+ }
801
+
802
+ class ShellySteckdose extends ShellyLampeWeiss {
803
+
804
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string, channel: number, alexaNamesForOn:string[], alexaActionNamesForOn:string[], alexaNamesForOff: string[],alexaActionNamesForOff: string[], additionalStates4TurnOn:string[], additionalStates4TurnOff:string[], nachtbeleuchtung:boolean, turnOffExitHouseSummer:boolean, turnOffExitHouseWinter:boolean, turnOnEnterHouseSummer:boolean, turnOnEnterHouseWinter:boolean) {
805
+ super(adapter, id, etage, raum, device, baseState, channel, alexaNamesForOn,alexaActionNamesForOn, alexaNamesForOff,alexaActionNamesForOff, additionalStates4TurnOn, additionalStates4TurnOff, nachtbeleuchtung, turnOffExitHouseSummer, turnOffExitHouseWinter, turnOnEnterHouseSummer, turnOnEnterHouseWinter);
806
+ }
807
+
808
+ public getCategory() : string {
809
+ return deviceShellySteckdose;
810
+ }
811
+ }
812
+
813
+ class ShellyRollladen extends AbstractShelly {
814
+
815
+ constructor(adapter:any, id: number, etage: string, raum: string, device: string, baseState: string) {
816
+ super(adapter, id, etage, raum, device, baseState);
817
+ }
818
+
819
+ public getShutterPositionState() : string {
820
+ if (this.baseState.includes('shellyplus2')) {
821
+ return this.baseState + ".Cover0.Position"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
822
+ } else {
823
+ return this.baseState + ".Shutter.Position"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
824
+ }
825
+ }
826
+
827
+ public getShutterOpenState() : string {
828
+ if (this.baseState.includes('shellyplus2')) {
829
+ return this.baseState + ".Cover0.Open"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
830
+ } else {
831
+ return this.baseState + ".Shutter.Open"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
832
+ }
833
+ }
834
+
835
+ public getShutterCloseState() : string {
836
+ if (this.baseState.includes('shellyplus2')) {
837
+ return this.baseState + ".Cover0.Close"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
838
+ } else {
839
+ return this.baseState + ".Shutter.Close"; // new: shelly.1.shellyplus2pm#4855199b3e38#1.Cover0.Position
840
+ }
841
+ }
842
+
843
+ // Steckdose, Rollladen, Lampe
844
+ public getCategory() : string {
845
+ return deviceShellyRollladen;
846
+ }
847
+ }
848
+
849
+ class ShellySensor extends AbstractShelly {
850
+
851
+ constructor(adapter: any, id: number, etage: string, raum: string, device: string, baseState: string) {
852
+ super(adapter, id, etage, raum, device, baseState);
853
+ }
854
+
855
+ public getTemperature() : number {
856
+ return this.adapter.getState(this.baseState + ".Temperature0.Celsius").val; // shelly.1.shellyhtg3#34b7da8d0234#1.Temperature0.Celsius
857
+ }
858
+
859
+ public getHumidity() : number {
860
+ return this.adapter.getState(this.baseState + ".Humidity0.Relative").val; // shelly.1.shellyhtg3#34b7da8d0234#1.Humidity0.Relative
861
+ }
862
+
863
+ public getCategory() : string {
864
+ return deviceShellySensor;
865
+ }
866
+ }
867
+
868
+ module.exports = {
869
+ ShellyLampeWeiss, ShellyDimmerAlexaScheme, ShellyDimmerTasterScheme, ShellyDimmer, ShellyRGBAlexaScheme, ShellyRGBTasterScheme, ShellyLampeRGB, ShellySteckdose, ShellyRollladen,ShellySensor,
870
+ deviceShellyLampeWeiss, deviceShellyDimmer, deviceShellyLampeRGB, deviceShellySteckdose, deviceShellyRollladen, deviceShellySensor
871
+ };
872
+
873
+