iobroker-ucl 1.0.47 → 1.0.49
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/!!!_INSTRUCTIONS_!!!.ts +20 -0
- package/homematicFunctions.js +1 -1
- package/homematicFunctions.ts +10 -10
- package/main.js +37 -1
- package/main.ts +10 -1
- package/package.json +1 -1
- package/zigbeeClasses.js +1229 -0
- package/zigbeeClasses.ts +1346 -0
- package/zigbeeFunctions.js +936 -0
- package/zigbeeFunctions.ts +1085 -0
package/zigbeeClasses.ts
ADDED
@@ -0,0 +1,1346 @@
|
|
1
|
+
// https://stackoverflow.com/questions/8595509/how-do-you-share-constants-in-nodejs-modules
|
2
|
+
const deviceZigbeeSteckdose: string = "Steckdose";
|
3
|
+
const deviceZigbeeBewegungsmelder: string = "Bewegungsmelder";
|
4
|
+
const deviceZigbeeLampeRGB: string = "LampeRGB";
|
5
|
+
const deviceZigbeeLampeWeiss: string = "LampeWeiss";
|
6
|
+
const deviceZigbeeRauchmelder: string = "Rauchmelder";
|
7
|
+
const deviceZigbeeWandtaster: string = "Wandtaster";
|
8
|
+
const deviceZigbeeDosenrelais: string = "Dosenrelais";
|
9
|
+
const deviceZigbeeSchalter: string = "Schalter";
|
10
|
+
const deviceZigbeeRepeater: string = "Repeater";
|
11
|
+
const deviceZigbeeFenstersensor: string = "Fenstersensor";
|
12
|
+
|
13
|
+
export abstract class AbstractZigbee {
|
14
|
+
protected id: number;
|
15
|
+
protected baseState: string;
|
16
|
+
protected etage: string;
|
17
|
+
protected device: string;
|
18
|
+
protected raum: string;
|
19
|
+
protected adapter: any;
|
20
|
+
|
21
|
+
constructor(adapter: any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
22
|
+
this.adapter = adapter;
|
23
|
+
this.id = id;
|
24
|
+
this.baseState = baseState;
|
25
|
+
this.etage = etage;
|
26
|
+
this.raum = raum;
|
27
|
+
this.device = device;
|
28
|
+
}
|
29
|
+
|
30
|
+
public getDeviceId(): string {
|
31
|
+
return "Z" + this.id.toString().padStart(3, '0');
|
32
|
+
}
|
33
|
+
|
34
|
+
public getOriginalDeviceName(): string {
|
35
|
+
return this.adapter.getObject(this.baseState).common.name;
|
36
|
+
}
|
37
|
+
|
38
|
+
public getDeviceIdAsRawNumber(): number {
|
39
|
+
return this.id;
|
40
|
+
}
|
41
|
+
|
42
|
+
public getEtage(): string {
|
43
|
+
return this.etage;
|
44
|
+
}
|
45
|
+
|
46
|
+
public getRaum(): string {
|
47
|
+
return this.raum;
|
48
|
+
}
|
49
|
+
|
50
|
+
public getDevice(): string {
|
51
|
+
return this.device;
|
52
|
+
}
|
53
|
+
|
54
|
+
public getBaseState(): string {
|
55
|
+
return this.baseState;
|
56
|
+
}
|
57
|
+
|
58
|
+
public getType(): string {
|
59
|
+
var result = "";
|
60
|
+
var m1 = this.adapter.getObject(this.baseState).native.manufacturername;
|
61
|
+
var m2 = this.adapter.getObject(this.baseState).native.modelid;
|
62
|
+
if (m1 != undefined && m2 != undefined) {
|
63
|
+
result += m1;
|
64
|
+
}
|
65
|
+
if (m2 != null) {
|
66
|
+
if (result != "") {
|
67
|
+
result += " (" + m2 + ")";
|
68
|
+
} else {
|
69
|
+
result += m2;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return result;
|
73
|
+
}
|
74
|
+
|
75
|
+
public isStatusTotal(): boolean {
|
76
|
+
return this.isStatusReachable();
|
77
|
+
}
|
78
|
+
|
79
|
+
public isStatusReachable(): boolean {
|
80
|
+
return this.adapter.getState(this.baseState + ".reachable").val; // hue.0.Steckdose_Backstube.reachable
|
81
|
+
}
|
82
|
+
|
83
|
+
abstract getCategory(): string;
|
84
|
+
|
85
|
+
protected createIOTAdapterSmartDevices(smartName) {
|
86
|
+
|
87
|
+
// Level:
|
88
|
+
// ----------------------------------------------------------------------------------
|
89
|
+
var alexaLampeLevel = "0_userdata.0.alexa." + smartName + ".level";
|
90
|
+
this.adapter.createState(alexaLampeLevel, 0, {
|
91
|
+
name: alexaLampeLevel,
|
92
|
+
desc: alexaLampeLevel,
|
93
|
+
type: 'number',
|
94
|
+
read: true,
|
95
|
+
write: true
|
96
|
+
});
|
97
|
+
|
98
|
+
// @ts-ignore
|
99
|
+
let objLevel = this.adapter.getObject(alexaLampeLevel) as unknown as iobJS.StateObject;
|
100
|
+
objLevel.common = {
|
101
|
+
"type": "number",
|
102
|
+
"name": alexaLampeLevel,
|
103
|
+
"read": true,
|
104
|
+
"write": true,
|
105
|
+
"role": "level.dimmer",
|
106
|
+
"min": 0,
|
107
|
+
"max": 100,
|
108
|
+
"def": 0,
|
109
|
+
"smartName": {
|
110
|
+
"de": smartName,
|
111
|
+
"smartType": "LIGHT"
|
112
|
+
}
|
113
|
+
};
|
114
|
+
this.adapter.setObject(alexaLampeLevel, objLevel);
|
115
|
+
|
116
|
+
// HUE:
|
117
|
+
// ----------------------------------------------------------------------------------
|
118
|
+
var alexaLampeHue = "0_userdata.0.alexa." + smartName + ".hue";
|
119
|
+
this.adapter.createState(alexaLampeHue, 0, {
|
120
|
+
name: alexaLampeHue,
|
121
|
+
desc: alexaLampeHue,
|
122
|
+
type: 'number',
|
123
|
+
read: true,
|
124
|
+
write: true
|
125
|
+
});
|
126
|
+
// @ts-ignore
|
127
|
+
let objHue = this.adapter.getObject(alexaLampeHue) as unknown as iobJS.StateObject;
|
128
|
+
objHue.common = {
|
129
|
+
"name": alexaLampeHue,
|
130
|
+
"desc": alexaLampeHue,
|
131
|
+
"type": "number",
|
132
|
+
"read": true,
|
133
|
+
"write": true,
|
134
|
+
"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
|
135
|
+
"smartName": {
|
136
|
+
"de": smartName,
|
137
|
+
"smartType": "LIGHT"
|
138
|
+
}
|
139
|
+
};
|
140
|
+
this.adapter.setObject(alexaLampeHue, objHue);
|
141
|
+
|
142
|
+
// SAT:
|
143
|
+
// ----------------------------------------------------------------------------------
|
144
|
+
var alexaLampeSat = "0_userdata.0.alexa." + smartName + ".sat";
|
145
|
+
this.adapter.createState(alexaLampeSat, 0, {
|
146
|
+
name: alexaLampeSat,
|
147
|
+
desc: alexaLampeSat,
|
148
|
+
type: 'number',
|
149
|
+
read: true,
|
150
|
+
write: true
|
151
|
+
});
|
152
|
+
// @ts-ignore
|
153
|
+
let obSat = this.adapter.getObject(alexaLampeSat) as unknown as iobJS.StateObject;
|
154
|
+
obSat.common = {
|
155
|
+
"name": alexaLampeSat,
|
156
|
+
"desc": alexaLampeSat,
|
157
|
+
"type": "number",
|
158
|
+
"read": true,
|
159
|
+
"write": true,
|
160
|
+
"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
|
161
|
+
"smartName": {
|
162
|
+
"de": smartName,
|
163
|
+
"smartType": "LIGHT"
|
164
|
+
}
|
165
|
+
};
|
166
|
+
this.adapter.setObject(alexaLampeSat, obSat);
|
167
|
+
|
168
|
+
// CT:
|
169
|
+
// ----------------------------------------------------------------------------------
|
170
|
+
var alexaLampeCT = "0_userdata.0.alexa." + smartName + ".ct";
|
171
|
+
this.adapter.createState(alexaLampeCT, 0, {
|
172
|
+
name: alexaLampeCT,
|
173
|
+
desc: alexaLampeCT,
|
174
|
+
type: 'number',
|
175
|
+
read: true,
|
176
|
+
write: true
|
177
|
+
});
|
178
|
+
// @ts-ignore
|
179
|
+
let objCT = this.adapter.getObject(alexaLampeCT) as unknown as iobJS.StateObject;
|
180
|
+
objCT.common = {
|
181
|
+
"type": "number",
|
182
|
+
"name": alexaLampeCT,
|
183
|
+
"read": true,
|
184
|
+
"write": true,
|
185
|
+
"role": "level.color.temperature",
|
186
|
+
"smartName": {
|
187
|
+
"de": smartName,
|
188
|
+
"smartType": "LIGHT"
|
189
|
+
}
|
190
|
+
};
|
191
|
+
this.adapter.setObject(alexaLampeCT, objCT);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
export class ColorScheme {
|
196
|
+
protected alexaName: string;
|
197
|
+
protected level: number;
|
198
|
+
protected device: ZigbeeLampeRGB;
|
199
|
+
|
200
|
+
constructor(alexaName: string, level: number) {
|
201
|
+
this.alexaName = alexaName;
|
202
|
+
this.level = level;
|
203
|
+
}
|
204
|
+
|
205
|
+
public getAlexaName(): string {
|
206
|
+
return this.alexaName;
|
207
|
+
}
|
208
|
+
|
209
|
+
public getLevel(): number {
|
210
|
+
return this.level;
|
211
|
+
}
|
212
|
+
|
213
|
+
public setDevice(device: ZigbeeLampeRGB) {
|
214
|
+
this.device = device;
|
215
|
+
}
|
216
|
+
|
217
|
+
public getDevice(): ZigbeeLampeRGB {
|
218
|
+
return this.device;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
export class RGBColorScheme extends ColorScheme {
|
223
|
+
protected hue: number;
|
224
|
+
protected sat: number;
|
225
|
+
|
226
|
+
constructor(alexaName: string, level: number, hue: number, sat: number) {
|
227
|
+
super(alexaName, level);
|
228
|
+
this.hue = hue;
|
229
|
+
this.sat = sat;
|
230
|
+
}
|
231
|
+
|
232
|
+
public getHue(): number {
|
233
|
+
return this.hue;
|
234
|
+
}
|
235
|
+
|
236
|
+
public getSat(): number {
|
237
|
+
return this.sat;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
export class WhiteColorScheme extends ColorScheme {
|
242
|
+
protected ct: number;
|
243
|
+
|
244
|
+
constructor(alexaName: string, level: number, ct: number) {
|
245
|
+
super(alexaName, level);
|
246
|
+
this.ct = ct;
|
247
|
+
}
|
248
|
+
|
249
|
+
public getCt(): number {
|
250
|
+
return this.ct;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
export class ZigbeeLampeRGB extends AbstractZigbee {
|
255
|
+
protected isGroup_: boolean;
|
256
|
+
protected groupMembers: string[];
|
257
|
+
protected alexaSmartNamesForOn: string[];
|
258
|
+
protected alexaSmartNamesForOff: string[];
|
259
|
+
protected alexaActionNamesForOn: string[];
|
260
|
+
protected alexaActionNamesForOff: string[];
|
261
|
+
protected tasterBooleanOn: string[];
|
262
|
+
protected tasterBooleanOff: string[];
|
263
|
+
protected colorSchemes: ColorScheme[];
|
264
|
+
protected alexaColorSchemeForOn: ColorScheme;
|
265
|
+
protected colorConverter: ColorConverter;
|
266
|
+
private nachtbeleuchtung: boolean;
|
267
|
+
private turnOffExitHouseSummer: boolean;
|
268
|
+
private turnOffExitHouseWinter: boolean;
|
269
|
+
private turnOnEnterHouseSummer: boolean;
|
270
|
+
private turnOnEnterHouseWinter: boolean;
|
271
|
+
|
272
|
+
constructor(adapter: any, id: number, baseState: string, etage: string, raum: string, device: string, isGroup: boolean, groupMembers: string[], alexaSmartNamesForOn: string[], alexaActionNamesForOn: string[], alexaColorSchemeForOn: ColorScheme, alexaSmartNamesForOff: string[], alexaActionNamesForOff: string[], colorSchemes: ColorScheme[], tasterBooleanOn: string[], tasterBooleanOff: string[], nachtbeleuchtung: boolean, turnOffExitHouseSummer: boolean, turnOffExitHouseWinter: boolean, turnOnEnterHouseSummer: boolean, turnOnEnterHouseWinter: boolean) {
|
273
|
+
super(adapter, id, baseState, etage, raum, device);
|
274
|
+
this.adapter = adapter;
|
275
|
+
this.isGroup_ = isGroup;
|
276
|
+
this.groupMembers = groupMembers;
|
277
|
+
this.alexaSmartNamesForOn = alexaSmartNamesForOn;
|
278
|
+
this.alexaSmartNamesForOff = alexaSmartNamesForOff;
|
279
|
+
this.alexaActionNamesForOn = alexaActionNamesForOn;
|
280
|
+
this.alexaActionNamesForOff = alexaActionNamesForOff;
|
281
|
+
this.nachtbeleuchtung = nachtbeleuchtung;
|
282
|
+
this.turnOffExitHouseSummer = turnOffExitHouseSummer;
|
283
|
+
this.turnOffExitHouseWinter = turnOffExitHouseWinter;
|
284
|
+
this.turnOnEnterHouseSummer = turnOnEnterHouseSummer;
|
285
|
+
this.turnOnEnterHouseWinter = turnOnEnterHouseWinter;
|
286
|
+
|
287
|
+
this.alexaColorSchemeForOn = alexaColorSchemeForOn;
|
288
|
+
this.colorSchemes = colorSchemes;
|
289
|
+
this.colorConverter = new ColorConverter();
|
290
|
+
this.tasterBooleanOn = tasterBooleanOn;
|
291
|
+
this.tasterBooleanOff = tasterBooleanOff;
|
292
|
+
|
293
|
+
this.tasterBooleanOn.forEach(booleanOnObj => {
|
294
|
+
this.createState(booleanOnObj);
|
295
|
+
});
|
296
|
+
this.tasterBooleanOff.forEach(tasterBooleanOffObj => {
|
297
|
+
this.createState(tasterBooleanOffObj);
|
298
|
+
});
|
299
|
+
|
300
|
+
this.alexaSmartNamesForOn.forEach(alexaSmartName => {
|
301
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
302
|
+
});
|
303
|
+
this.alexaSmartNamesForOff.forEach(alexaSmartName => {
|
304
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
305
|
+
});
|
306
|
+
this.alexaActionNamesForOn.forEach(alexaSmartName => {
|
307
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
308
|
+
});
|
309
|
+
this.alexaActionNamesForOff.forEach(alexaSmartName => {
|
310
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
311
|
+
});
|
312
|
+
|
313
|
+
this.colorSchemes.forEach(scheme => {
|
314
|
+
if (scheme.getAlexaName() != null) {
|
315
|
+
this.createIOTAdapterSmartDevices(scheme.getAlexaName());
|
316
|
+
}
|
317
|
+
});
|
318
|
+
|
319
|
+
this.initRGB();
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
public isNachtbeleuchtung(): boolean {
|
324
|
+
return this.nachtbeleuchtung;
|
325
|
+
}
|
326
|
+
|
327
|
+
public isTurnOffExitHouseSummer(): boolean {
|
328
|
+
return this.turnOffExitHouseSummer;
|
329
|
+
}
|
330
|
+
|
331
|
+
public isTurnOffExitHouseWinter(): boolean {
|
332
|
+
return this.turnOffExitHouseWinter;
|
333
|
+
}
|
334
|
+
|
335
|
+
public isTurnOnEnterHouseSummer(): boolean {
|
336
|
+
return this.turnOnEnterHouseSummer;
|
337
|
+
}
|
338
|
+
|
339
|
+
public isTurnOnEnterHouseWinter(): boolean {
|
340
|
+
return this.turnOnEnterHouseWinter;
|
341
|
+
}
|
342
|
+
|
343
|
+
private initRGB(): void {
|
344
|
+
this.colorSchemes.forEach(colorscheme => {
|
345
|
+
colorscheme.setDevice(this);
|
346
|
+
});
|
347
|
+
if (this.alexaColorSchemeForOn != null) {
|
348
|
+
this.alexaColorSchemeForOn.setDevice(this);
|
349
|
+
}
|
350
|
+
this.createAlias(this.getBaseState() + ".on", "alias.0.rgb." + this.getDeviceId() + ".on");
|
351
|
+
this.createAlias(this.getBaseState() + ".ct", "alias.0.rgb." + this.getDeviceId() + ".ct");
|
352
|
+
this.createAlias(this.getBaseState() + ".level", "alias.0.rgb." + this.getDeviceId() + ".level");
|
353
|
+
if (this.isGroup_ == false) {
|
354
|
+
this.createAlias(this.getBaseState() + ".reachable", "alias.0.rgb." + this.getDeviceId() + ".reachable");
|
355
|
+
} else {
|
356
|
+
var groupReachable = "0_userdata.0.rgb." + this.getDeviceId() + ".reachable";
|
357
|
+
this.adapter.createState(groupReachable, true, {
|
358
|
+
name: groupReachable,
|
359
|
+
desc: groupReachable,
|
360
|
+
type: 'boolean',
|
361
|
+
read: true,
|
362
|
+
write: true
|
363
|
+
});
|
364
|
+
this.createAlias("0_userdata.0.rgb." + this.getDeviceId() + ".reachable", "alias.0.rgb." + this.getDeviceId() + ".reachable");
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
private createAlias(originalDatenpunkt, aliasDatenpunkt) {
|
369
|
+
this.adapter.setObject(aliasDatenpunkt, {
|
370
|
+
type: 'state',
|
371
|
+
common: {
|
372
|
+
name: this.adapter.getObject(originalDatenpunkt).common.name, //'Heizung Ist Temperatur',
|
373
|
+
type: this.adapter.getObject(originalDatenpunkt).common.type, // 'number',
|
374
|
+
unit: this.adapter.getObject(originalDatenpunkt).common.unit, //'°C',
|
375
|
+
read: true,
|
376
|
+
write: true,
|
377
|
+
role: this.adapter.getObject(originalDatenpunkt).common.role, //'value.temperature',
|
378
|
+
alias: {
|
379
|
+
id: originalDatenpunkt
|
380
|
+
}
|
381
|
+
},
|
382
|
+
native: {}
|
383
|
+
});
|
384
|
+
}
|
385
|
+
|
386
|
+
public getColorSchemes(): ColorScheme[] {
|
387
|
+
return this.colorSchemes;
|
388
|
+
}
|
389
|
+
|
390
|
+
public getColorSchemeForOn(): ColorScheme {
|
391
|
+
return this.alexaColorSchemeForOn;
|
392
|
+
}
|
393
|
+
|
394
|
+
public getTasterBooleanOn(): string[] {
|
395
|
+
return this.tasterBooleanOn;
|
396
|
+
}
|
397
|
+
|
398
|
+
public getTasterBooleanOff(): string[] {
|
399
|
+
return this.tasterBooleanOff;
|
400
|
+
}
|
401
|
+
|
402
|
+
private createState(key_in) {
|
403
|
+
var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
|
404
|
+
//log(">>> CREATE STATE: " + jarvisDatenpunkt);
|
405
|
+
this.adapter.createState(jarvisDatenpunkt, false, {
|
406
|
+
name: jarvisDatenpunkt,
|
407
|
+
desc: jarvisDatenpunkt,
|
408
|
+
type: 'boolean',
|
409
|
+
read: true,
|
410
|
+
write: true
|
411
|
+
});
|
412
|
+
}
|
413
|
+
|
414
|
+
public changeColor(colorscheme: ColorScheme) {
|
415
|
+
if (colorscheme.getDevice().getBaseState().includes("deconz")) {
|
416
|
+
this.adapter.setState(this.getBaseState() + ".level", colorscheme.getLevel());
|
417
|
+
if (colorscheme instanceof RGBColorScheme) {
|
418
|
+
const rgbColorscheme = colorscheme as RGBColorScheme;
|
419
|
+
this.adapter.setState(this.getBaseState() + ".xy", this.colorConverter.convertHSL2XY(rgbColorscheme.getHue(), rgbColorscheme.getSat()));
|
420
|
+
} else {
|
421
|
+
const whiteColorscheme = colorscheme as WhiteColorScheme;
|
422
|
+
this.adapter.setState(this.getBaseState() + ".ct", whiteColorscheme.getCt());
|
423
|
+
}
|
424
|
+
} else {
|
425
|
+
this.adapter.log(">>> hue changeColor: Set Level to: " + colorscheme.getLevel());
|
426
|
+
|
427
|
+
setTimeout(obj => {
|
428
|
+
this.adapter.setState(this.getBaseState() + ".level", colorscheme.getLevel());
|
429
|
+
|
430
|
+
setTimeout(obj2 => {
|
431
|
+
if (colorscheme instanceof RGBColorScheme) {
|
432
|
+
this.adapter.log(">>> hue changeColor: Set Hue to: " + colorscheme.getHue());
|
433
|
+
this.adapter.log(">>> hue changeColor: Set Sat to: " + colorscheme.getSat());
|
434
|
+
|
435
|
+
const rgbColorscheme = colorscheme as RGBColorScheme;
|
436
|
+
//setState(this.getBaseState() + ".xy", this.colorConverter.convertHSL2XY(rgbColorscheme.getHue(), rgbColorscheme.getSat()));
|
437
|
+
this.adapter.setState(this.getBaseState() + ".hue", rgbColorscheme.getHue());//, rgbColorscheme.getSat()));
|
438
|
+
this.adapter.setState(this.getBaseState() + ".sat", rgbColorscheme.getSat());
|
439
|
+
} else {
|
440
|
+
const whiteColorscheme = colorscheme as WhiteColorScheme;
|
441
|
+
this.adapter.setState(this.getBaseState() + ".ct", whiteColorscheme.getCt());
|
442
|
+
//log(">>> deconz changeColor: Set ct to: " + whiteColorscheme.getCt());
|
443
|
+
}
|
444
|
+
|
445
|
+
}, 300);
|
446
|
+
|
447
|
+
}, 600);
|
448
|
+
}
|
449
|
+
}
|
450
|
+
|
451
|
+
public turnOn() {
|
452
|
+
if (this.alexaColorSchemeForOn == null) { // Schalte Licht nur ein, d.h. lass die Farbwerte so wie sie sind
|
453
|
+
this.adapter.setState(this.getBaseState() + ".on", true);
|
454
|
+
} else {
|
455
|
+
this.changeColor(this.alexaColorSchemeForOn);
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
public turnOff() {
|
460
|
+
this.adapter.setState(this.getBaseState() + ".on", false);
|
461
|
+
}
|
462
|
+
|
463
|
+
public getAlexaNamesForOnAsString(): string {
|
464
|
+
var result = "";
|
465
|
+
|
466
|
+
this.alexaSmartNamesForOn.forEach(alexaOnName => {
|
467
|
+
if (result == "") {
|
468
|
+
result += alexaOnName
|
469
|
+
} else {
|
470
|
+
result += ", " + alexaOnName;
|
471
|
+
}
|
472
|
+
});
|
473
|
+
this.alexaActionNamesForOn.forEach(alexaOnName => {
|
474
|
+
if (result == "") {
|
475
|
+
result += alexaOnName
|
476
|
+
} else {
|
477
|
+
result += ", " + alexaOnName;
|
478
|
+
}
|
479
|
+
});
|
480
|
+
|
481
|
+
return result;
|
482
|
+
}
|
483
|
+
|
484
|
+
public getAlexaNamesForOffAsString(): string {
|
485
|
+
var result = "";
|
486
|
+
|
487
|
+
this.alexaSmartNamesForOff.forEach(alexaOffName => {
|
488
|
+
if (result == "") {
|
489
|
+
result += alexaOffName
|
490
|
+
} else {
|
491
|
+
result += ", " + alexaOffName;
|
492
|
+
}
|
493
|
+
});
|
494
|
+
this.alexaActionNamesForOff.forEach(alexaOffName => {
|
495
|
+
if (result == "") {
|
496
|
+
result += alexaOffName
|
497
|
+
} else {
|
498
|
+
result += ", " + alexaOffName;
|
499
|
+
}
|
500
|
+
});
|
501
|
+
|
502
|
+
return result;
|
503
|
+
}
|
504
|
+
|
505
|
+
public isSwitchedOn(): boolean {
|
506
|
+
if (this.adapter.getState(this.baseState + ".on").val == false) { // hue.0.Steckdose_Backstube.on
|
507
|
+
return false;
|
508
|
+
}
|
509
|
+
return true;
|
510
|
+
}
|
511
|
+
|
512
|
+
public getGroupMembers(): string[] {
|
513
|
+
return this.groupMembers;
|
514
|
+
}
|
515
|
+
|
516
|
+
public getAlexaSmartNamesForOn(): string[] {
|
517
|
+
return this.alexaSmartNamesForOn;
|
518
|
+
}
|
519
|
+
|
520
|
+
public getAlexaSmartNamesForOff(): string[] {
|
521
|
+
return this.alexaSmartNamesForOff;
|
522
|
+
}
|
523
|
+
|
524
|
+
public getAlexaActionNamesForOn(): string[] {
|
525
|
+
return this.alexaActionNamesForOn;
|
526
|
+
}
|
527
|
+
|
528
|
+
public getAlexaActionNamesForOff(): string[] {
|
529
|
+
return this.alexaActionNamesForOff;
|
530
|
+
}
|
531
|
+
|
532
|
+
public isGroup(): boolean {
|
533
|
+
return this.isGroup_;
|
534
|
+
}
|
535
|
+
|
536
|
+
public getDeviceId(): string {
|
537
|
+
if (this.isGroup_) {
|
538
|
+
return "ZG" + this.id.toString().padStart(3, '0');
|
539
|
+
} else {
|
540
|
+
return "Z" + this.id.toString().padStart(3, '0');
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
544
|
+
public isStatusReachable(): boolean {
|
545
|
+
if (this.isGroup_) {
|
546
|
+
return true;
|
547
|
+
} else {
|
548
|
+
return this.adapter.getState(this.baseState + ".reachable").val; // hue.0.Steckdose_Backstube.reachable
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
public getLevel(): number { // Helligkeit
|
553
|
+
return this.adapter.getState(this.baseState + ".level").val;
|
554
|
+
}
|
555
|
+
|
556
|
+
public getCategory(): string {
|
557
|
+
return deviceZigbeeLampeRGB;
|
558
|
+
}
|
559
|
+
}
|
560
|
+
|
561
|
+
export class LampeWeissTasterScheme {
|
562
|
+
protected tasterBooleanOn: string;
|
563
|
+
protected level: number;
|
564
|
+
protected ct: number;
|
565
|
+
|
566
|
+
constructor(tasterBooleanOn: string, level: number, ct: number) {
|
567
|
+
this.tasterBooleanOn = tasterBooleanOn;
|
568
|
+
this.level = level;
|
569
|
+
this.ct = ct;
|
570
|
+
}
|
571
|
+
|
572
|
+
public getTasterBooleanOnName(): string {
|
573
|
+
return this.tasterBooleanOn;
|
574
|
+
}
|
575
|
+
|
576
|
+
public getLevel(): number {
|
577
|
+
return this.level;
|
578
|
+
}
|
579
|
+
|
580
|
+
public getCt(): number {
|
581
|
+
return this.ct;
|
582
|
+
}
|
583
|
+
}
|
584
|
+
|
585
|
+
export class LampeWeissAlexaScheme {
|
586
|
+
protected alexaName: string;
|
587
|
+
protected level: number;
|
588
|
+
protected ct: number;
|
589
|
+
protected device: ZigbeeLampeWeiss;
|
590
|
+
|
591
|
+
constructor(alexaName: string, level: number, ct: number) {
|
592
|
+
this.alexaName = alexaName;
|
593
|
+
this.level = level;
|
594
|
+
this.ct = ct;
|
595
|
+
}
|
596
|
+
|
597
|
+
public getAlexaName(): string {
|
598
|
+
return this.alexaName;
|
599
|
+
}
|
600
|
+
|
601
|
+
public getLevel(): number {
|
602
|
+
return this.level;
|
603
|
+
}
|
604
|
+
|
605
|
+
public setDevice(device: ZigbeeLampeWeiss) {
|
606
|
+
this.device = device;
|
607
|
+
}
|
608
|
+
|
609
|
+
public getDevice(): ZigbeeLampeWeiss {
|
610
|
+
return this.device;
|
611
|
+
}
|
612
|
+
|
613
|
+
public getCt(): number {
|
614
|
+
return this.ct;
|
615
|
+
}
|
616
|
+
}
|
617
|
+
|
618
|
+
export class ZigbeeLampeWeiss extends AbstractZigbee {
|
619
|
+
protected alexaLevelSchemeForOn: LampeWeissAlexaScheme;
|
620
|
+
protected alexaSmartNamesForOn: string[];
|
621
|
+
protected alexaSmartNamesForOff: string[];
|
622
|
+
protected alexaActionNamesForOn: string[];
|
623
|
+
protected alexaActionNamesForOff: string[];
|
624
|
+
protected isGroup_: boolean;
|
625
|
+
protected tasterBooleanOn: LampeWeissTasterScheme[];
|
626
|
+
protected tasterBooleanOff: string[];
|
627
|
+
protected levelSchemes: LampeWeissAlexaScheme[];
|
628
|
+
private nachtbeleuchtung: boolean;
|
629
|
+
private turnOffExitHouseSummer: boolean;
|
630
|
+
private turnOffExitHouseWinter: boolean;
|
631
|
+
private turnOnEnterHouseSummer: boolean;
|
632
|
+
private turnOnEnterHouseWinter: boolean;
|
633
|
+
|
634
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string, alexaSmartNamesForOn: string[], alexaActionNamesForOn: string[], alexaLevelSchemeForOn: LampeWeissAlexaScheme, alexaSmartNamesForOff: string[], alexaActionNamesForOff: string[], levelSchemes: LampeWeissAlexaScheme[], isGroup_: boolean, tasterBooleanOn: LampeWeissTasterScheme[], tasterBooleanOff: string[], nachtbeleuchtung: boolean, turnOffExitHouseSummer: boolean, turnOffExitHouseWinter: boolean, turnOnEnterHouseSummer: boolean, turnOnEnterHouseWinter: boolean) {
|
635
|
+
super(adapter, id, baseState, etage, raum, device);
|
636
|
+
this.adapter = adapter;
|
637
|
+
this.alexaLevelSchemeForOn = alexaLevelSchemeForOn;
|
638
|
+
this.alexaSmartNamesForOn = alexaSmartNamesForOn;
|
639
|
+
this.alexaSmartNamesForOff = alexaSmartNamesForOff;
|
640
|
+
this.alexaActionNamesForOn = alexaActionNamesForOn;
|
641
|
+
this.alexaActionNamesForOff = alexaActionNamesForOff;
|
642
|
+
this.nachtbeleuchtung = nachtbeleuchtung;
|
643
|
+
this.turnOffExitHouseSummer = turnOffExitHouseSummer;
|
644
|
+
this.turnOffExitHouseWinter = turnOffExitHouseWinter;
|
645
|
+
this.turnOnEnterHouseSummer = turnOnEnterHouseSummer;
|
646
|
+
this.turnOnEnterHouseWinter = turnOnEnterHouseWinter;
|
647
|
+
this.isGroup_ = isGroup_;
|
648
|
+
this.tasterBooleanOn = tasterBooleanOn;
|
649
|
+
this.tasterBooleanOff = tasterBooleanOff;
|
650
|
+
this.levelSchemes = levelSchemes;
|
651
|
+
|
652
|
+
// States anlegen:
|
653
|
+
this.tasterBooleanOn.forEach(tasterScheme => {
|
654
|
+
if (tasterScheme.getTasterBooleanOnName() != null) {
|
655
|
+
this.createState(tasterScheme.getTasterBooleanOnName());
|
656
|
+
}
|
657
|
+
});
|
658
|
+
this.tasterBooleanOff.forEach(offName => {
|
659
|
+
this.createState(offName);
|
660
|
+
});
|
661
|
+
|
662
|
+
this.alexaSmartNamesForOn.forEach(alexaSmartName => {
|
663
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
664
|
+
});
|
665
|
+
this.alexaSmartNamesForOff.forEach(alexaSmartName => {
|
666
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
667
|
+
});
|
668
|
+
this.alexaActionNamesForOn.forEach(alexaSmartName => {
|
669
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
670
|
+
});
|
671
|
+
this.alexaActionNamesForOff.forEach(alexaSmartName => {
|
672
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
673
|
+
});
|
674
|
+
|
675
|
+
this.levelSchemes.forEach(scheme => {
|
676
|
+
if (scheme.getAlexaName() != null) {
|
677
|
+
this.createIOTAdapterSmartDevices(scheme.getAlexaName());
|
678
|
+
}
|
679
|
+
});
|
680
|
+
}
|
681
|
+
|
682
|
+
public isNachtbeleuchtung(): boolean {
|
683
|
+
return this.nachtbeleuchtung;
|
684
|
+
}
|
685
|
+
|
686
|
+
public isTurnOffExitHouseSummer(): boolean {
|
687
|
+
return this.turnOffExitHouseSummer;
|
688
|
+
}
|
689
|
+
|
690
|
+
public isTurnOffExitHouseWinter(): boolean {
|
691
|
+
return this.turnOffExitHouseWinter;
|
692
|
+
}
|
693
|
+
|
694
|
+
public isTurnOnEnterHouseSummer(): boolean {
|
695
|
+
return this.turnOnEnterHouseSummer;
|
696
|
+
}
|
697
|
+
|
698
|
+
public isTurnOnEnterHouseWinter(): boolean {
|
699
|
+
return this.turnOnEnterHouseWinter;
|
700
|
+
}
|
701
|
+
|
702
|
+
public getAlexaSmartNamesForOn(): string[] {
|
703
|
+
return this.alexaSmartNamesForOn;
|
704
|
+
}
|
705
|
+
|
706
|
+
public getAlexaSmartNamesForOff(): string[] {
|
707
|
+
return this.alexaSmartNamesForOff;
|
708
|
+
}
|
709
|
+
|
710
|
+
public getAlexaActionNamesForOn(): string[] {
|
711
|
+
return this.alexaActionNamesForOn;
|
712
|
+
}
|
713
|
+
|
714
|
+
public getAlexaActionNamesForOff(): string[] {
|
715
|
+
return this.alexaActionNamesForOff;
|
716
|
+
}
|
717
|
+
|
718
|
+
public getAlexaSchemes(): LampeWeissAlexaScheme[] {
|
719
|
+
return this.levelSchemes;
|
720
|
+
}
|
721
|
+
|
722
|
+
public getAlexaSchemeForOn(): LampeWeissAlexaScheme {
|
723
|
+
return this.alexaLevelSchemeForOn;
|
724
|
+
}
|
725
|
+
|
726
|
+
public getAlexaNamesForOnAsString(): string {
|
727
|
+
var result = "";
|
728
|
+
|
729
|
+
this.alexaSmartNamesForOn.forEach(alexaOnName => {
|
730
|
+
if (result == "") {
|
731
|
+
result += alexaOnName
|
732
|
+
} else {
|
733
|
+
result += ", " + alexaOnName;
|
734
|
+
}
|
735
|
+
});
|
736
|
+
this.alexaActionNamesForOn.forEach(alexaOnName => {
|
737
|
+
if (result == "") {
|
738
|
+
result += alexaOnName
|
739
|
+
} else {
|
740
|
+
result += ", " + alexaOnName;
|
741
|
+
}
|
742
|
+
});
|
743
|
+
|
744
|
+
return result;
|
745
|
+
}
|
746
|
+
|
747
|
+
public getAlexaNamesForOffAsString(): string {
|
748
|
+
var result = "";
|
749
|
+
|
750
|
+
this.alexaSmartNamesForOff.forEach(alexaOffName => {
|
751
|
+
if (result == "") {
|
752
|
+
result += alexaOffName
|
753
|
+
} else {
|
754
|
+
result += ", " + alexaOffName;
|
755
|
+
}
|
756
|
+
});
|
757
|
+
this.alexaActionNamesForOff.forEach(alexaOffName => {
|
758
|
+
if (result == "") {
|
759
|
+
result += alexaOffName
|
760
|
+
} else {
|
761
|
+
result += ", " + alexaOffName;
|
762
|
+
}
|
763
|
+
});
|
764
|
+
|
765
|
+
|
766
|
+
return result;
|
767
|
+
}
|
768
|
+
|
769
|
+
public getTasterBooleanOn(): LampeWeissTasterScheme[] {
|
770
|
+
return this.tasterBooleanOn;
|
771
|
+
}
|
772
|
+
|
773
|
+
public getTasterBooleanOff(): string[] {
|
774
|
+
return this.tasterBooleanOff;
|
775
|
+
}
|
776
|
+
|
777
|
+
private createState(key_in) {
|
778
|
+
var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
|
779
|
+
//log(">>> CREATE STATE: " + jarvisDatenpunkt);
|
780
|
+
this.adapter.createState(jarvisDatenpunkt, false, {
|
781
|
+
name: jarvisDatenpunkt,
|
782
|
+
desc: jarvisDatenpunkt,
|
783
|
+
type: 'boolean',
|
784
|
+
read: true,
|
785
|
+
write: true
|
786
|
+
});
|
787
|
+
}
|
788
|
+
|
789
|
+
public isSwitchedOn(): boolean {
|
790
|
+
if (this.adapter.getState(this.baseState + ".on").val == false) { // hue.0.Steckdose_Backstube.on
|
791
|
+
return false;
|
792
|
+
}
|
793
|
+
return true;
|
794
|
+
}
|
795
|
+
|
796
|
+
public turnOn() {
|
797
|
+
if (this.alexaLevelSchemeForOn == null) { // Schalte Licht nur ein
|
798
|
+
if (this.adapter.getState(this.baseState + ".on").val != true) {
|
799
|
+
this.adapter.setState(this.baseState + ".on", true);
|
800
|
+
}
|
801
|
+
} else {
|
802
|
+
this.changeLevel(this.alexaLevelSchemeForOn);
|
803
|
+
}
|
804
|
+
}
|
805
|
+
|
806
|
+
public turnOff() {
|
807
|
+
if (this.adapter.getState(this.baseState + ".on").val != false) {
|
808
|
+
this.adapter.setState(this.baseState + ".on", false);
|
809
|
+
}
|
810
|
+
}
|
811
|
+
|
812
|
+
public changeLevel(levelScheme: LampeWeissAlexaScheme) {
|
813
|
+
this.adapter.log("LampeWeiß --> ChangeLevel: Level:" + levelScheme.getLevel() + ", ct: " + levelScheme.getCt());
|
814
|
+
this.adapter.setState(this.baseState + ".on", true);
|
815
|
+
this.adapter.setState(this.baseState + ".level", levelScheme.getLevel());
|
816
|
+
if (levelScheme.getCt() != -1) {
|
817
|
+
this.adapter.setState(this.baseState + ".ct", levelScheme.getCt());
|
818
|
+
}
|
819
|
+
}
|
820
|
+
|
821
|
+
public isStatusReachable(): boolean {
|
822
|
+
if (this.isGroup_) {
|
823
|
+
return true;
|
824
|
+
} else {
|
825
|
+
return this.adapter.getState(this.baseState + ".reachable").val; // hue.0.Steckdose_Backstube.reachable
|
826
|
+
}
|
827
|
+
}
|
828
|
+
|
829
|
+
public isGroup(): boolean {
|
830
|
+
return this.isGroup_;
|
831
|
+
}
|
832
|
+
|
833
|
+
public getDeviceId(): string {
|
834
|
+
if (this.isGroup_) {
|
835
|
+
return "ZG" + this.id.toString().padStart(3, '0');
|
836
|
+
} else {
|
837
|
+
return "Z" + this.id.toString().padStart(3, '0');
|
838
|
+
}
|
839
|
+
}
|
840
|
+
|
841
|
+
public getLevel(): number { // Helligkeit
|
842
|
+
return this.adapter.getState(this.baseState + ".level").val;
|
843
|
+
}
|
844
|
+
|
845
|
+
public getCategory(): string {
|
846
|
+
return deviceZigbeeLampeWeiss;
|
847
|
+
}
|
848
|
+
}
|
849
|
+
|
850
|
+
class ColorConverter {
|
851
|
+
public convertXY2HSL(x, y) {
|
852
|
+
var bri = 254;
|
853
|
+
let xy = {
|
854
|
+
x: x,
|
855
|
+
y: y
|
856
|
+
};
|
857
|
+
|
858
|
+
let z = 1.0 - xy.x - xy.y;
|
859
|
+
let Y = bri / 255;
|
860
|
+
let X = (Y / xy.y) * xy.x;
|
861
|
+
let Z = (Y / xy.y) * z;
|
862
|
+
var r = X * 1.656492 - Y * 0.354851 - Z * 0.255038;
|
863
|
+
var g = -X * 0.707196 + Y * 1.655397 + Z * 0.036152;
|
864
|
+
var b = X * 0.051713 - Y * 0.121364 + Z * 1.011530;
|
865
|
+
|
866
|
+
r = r <= 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math.pow(r, (1.0 / 2.4)) - 0.055;
|
867
|
+
g = g <= 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math.pow(g, (1.0 / 2.4)) - 0.055;
|
868
|
+
b = b <= 0.0031308 ? 12.92 * b : (1.0 + 0.055) * Math.pow(b, (1.0 / 2.4)) - 0.055;
|
869
|
+
|
870
|
+
var r_new = (r * 255).toString();
|
871
|
+
var g_new = (g * 255).toString();
|
872
|
+
var b_new = (b * 255).toString();
|
873
|
+
|
874
|
+
let red = parseInt(r_new) > 255 ? 255 : parseInt(r_new);
|
875
|
+
let green = parseInt(g_new) > 255 ? 255 : parseInt(g_new);
|
876
|
+
let blue = parseInt(b_new) > 255 ? 255 : parseInt(b_new);
|
877
|
+
|
878
|
+
red = Math.abs(red);
|
879
|
+
green = Math.abs(green);
|
880
|
+
blue = Math.abs(blue);
|
881
|
+
var
|
882
|
+
min = Math.min(r, g, b),
|
883
|
+
max = Math.max(r, g, b),
|
884
|
+
delta = max - min,
|
885
|
+
h, s, v = max;
|
886
|
+
|
887
|
+
v = Math.floor(max / 255 * 100);
|
888
|
+
if (max != 0)
|
889
|
+
s = Math.floor(delta / max * 100);
|
890
|
+
else {
|
891
|
+
// black
|
892
|
+
return [0, 0, 0];
|
893
|
+
}
|
894
|
+
|
895
|
+
if (r == max)
|
896
|
+
h = (g - b) / delta; // between yellow & magenta
|
897
|
+
else if (g == max)
|
898
|
+
h = 2 + (b - r) / delta; // between cyan & yellow
|
899
|
+
else
|
900
|
+
h = 4 + (r - g) / delta; // between magenta & cyan
|
901
|
+
|
902
|
+
h = Math.floor(h * 60); // degrees
|
903
|
+
if (h < 0) h += 360;
|
904
|
+
|
905
|
+
return [h, s, v];
|
906
|
+
}
|
907
|
+
|
908
|
+
public convertHSL2XY(h, s) {
|
909
|
+
var l = 50;
|
910
|
+
// Must be fractions of 1
|
911
|
+
s /= 100;
|
912
|
+
l /= 100;
|
913
|
+
|
914
|
+
let c = (1 - Math.abs(2 * l - 1)) * s,
|
915
|
+
x = c * (1 - Math.abs((h / 60) % 2 - 1)),
|
916
|
+
m = l - c / 2,
|
917
|
+
r = 0,
|
918
|
+
g = 0,
|
919
|
+
b = 0;
|
920
|
+
|
921
|
+
if (0 <= h && h < 60) {
|
922
|
+
r = c; g = x; b = 0;
|
923
|
+
} else if (60 <= h && h < 120) {
|
924
|
+
r = x; g = c; b = 0;
|
925
|
+
} else if (120 <= h && h < 180) {
|
926
|
+
r = 0; g = c; b = x;
|
927
|
+
} else if (180 <= h && h < 240) {
|
928
|
+
r = 0; g = x; b = c;
|
929
|
+
} else if (240 <= h && h < 300) {
|
930
|
+
r = x; g = 0; b = c;
|
931
|
+
} else if (300 <= h && h < 360) {
|
932
|
+
r = c; g = 0; b = x;
|
933
|
+
}
|
934
|
+
r = Math.round((r + m) * 255);
|
935
|
+
g = Math.round((g + m) * 255);
|
936
|
+
b = Math.round((b + m) * 255);
|
937
|
+
|
938
|
+
let red = r;
|
939
|
+
let green = g;
|
940
|
+
let blue = b;
|
941
|
+
|
942
|
+
if (red > 0.04045) red = Math.pow((red + 0.055) / (1.0 + 0.055), 2.4)
|
943
|
+
else red = red / 12.92;
|
944
|
+
|
945
|
+
if (green > 0.04045) green = Math.pow((green + 0.055) / (1.0 + 0.055), 2.4)
|
946
|
+
else green = green / 12.92;
|
947
|
+
|
948
|
+
if (blue > 0.04045) blue = Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4)
|
949
|
+
else blue = blue / 12.92;
|
950
|
+
|
951
|
+
const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
|
952
|
+
const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
|
953
|
+
const Z = red * 0.000088 + green * 0.07231 + blue * 0.986039;
|
954
|
+
|
955
|
+
const x2 = X / (X + Y + Z);
|
956
|
+
const y2 = Y / (X + Y + Z);
|
957
|
+
|
958
|
+
return new Array(x2, y2);
|
959
|
+
}
|
960
|
+
}
|
961
|
+
|
962
|
+
export class ZigbeeSteckdose extends AbstractZigbee {
|
963
|
+
protected alexaSmartNamesForOn:string[];
|
964
|
+
protected alexaSmartNamesForOff: string[];
|
965
|
+
protected alexaActionNamesForOn:string[];
|
966
|
+
protected alexaActionNamesForOff: string[];
|
967
|
+
|
968
|
+
private additionalStates4TurnOn:string[];
|
969
|
+
private additionalStates4TurnOff:string[];
|
970
|
+
|
971
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string, alexaSmartNamesForOn:string[],alexaActionNamesForOn:string[], alexaSmartNamesForOff: string[],alexaActionNamesForOff: string[], additionalStates4TurnOn:string[], additionalStates4TurnOff:string[]) {
|
972
|
+
super(adapter, id, baseState, etage, raum, device);
|
973
|
+
this.adapter = adapter;
|
974
|
+
|
975
|
+
this.alexaSmartNamesForOn = alexaSmartNamesForOn;
|
976
|
+
this.alexaSmartNamesForOff = alexaSmartNamesForOff;
|
977
|
+
this.alexaActionNamesForOn = alexaActionNamesForOn;
|
978
|
+
this.alexaActionNamesForOff = alexaActionNamesForOff;
|
979
|
+
|
980
|
+
this.additionalStates4TurnOn = additionalStates4TurnOn;
|
981
|
+
this.additionalStates4TurnOff = additionalStates4TurnOff;
|
982
|
+
|
983
|
+
// Diese boolean States können auch das Licht einschalten. Wird benötigt z.B. bei einem RGB-Farbschema "hell" (realisiert über boolean-Datenpunkt). Dann soll auch die Shelly-Lampe eingeschalten werden
|
984
|
+
this.additionalStates4TurnOn.forEach(turnOnState => {
|
985
|
+
this.createState(turnOnState);
|
986
|
+
});
|
987
|
+
// Diese boolean States können auch das Licht ausschalten. Wird benötigt z.B. bei einem RGB-Farbschema "hell" (realisiert über boolean-Datenpunkt). Dann soll auch die Shelly-Lampe eingeschalten werden
|
988
|
+
this.additionalStates4TurnOff.forEach(turnOffState => {
|
989
|
+
this.createState(turnOffState);
|
990
|
+
});
|
991
|
+
|
992
|
+
this.alexaSmartNamesForOn.forEach(alexaSmartName => {
|
993
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
994
|
+
});
|
995
|
+
this.alexaSmartNamesForOff.forEach(alexaSmartName => {
|
996
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
997
|
+
});
|
998
|
+
this.alexaActionNamesForOn.forEach(alexaSmartName => {
|
999
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
1000
|
+
});
|
1001
|
+
this.alexaActionNamesForOff.forEach(alexaSmartName => {
|
1002
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
1003
|
+
});
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
private createState(key_in) {
|
1007
|
+
var jarvisDatenpunkt = key_in;//.replace(/\./g,'_'); // wegen Wohnzimmer T.V.
|
1008
|
+
this.adapter.createState(jarvisDatenpunkt, false, {
|
1009
|
+
name: jarvisDatenpunkt,
|
1010
|
+
desc: jarvisDatenpunkt,
|
1011
|
+
type: 'boolean',
|
1012
|
+
read: true,
|
1013
|
+
write: true
|
1014
|
+
});
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
public getAdditionalStates4TurnOn() : string[] {
|
1018
|
+
return this.additionalStates4TurnOn;
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
public getAdditionalStates4TurnOff() : string[] {
|
1022
|
+
return this.additionalStates4TurnOff;
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
public getAlexaSmartNamesForOn() : string[] {
|
1026
|
+
return this.alexaSmartNamesForOn;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
public getAlexaSmartNamesForOff() : string[] {
|
1030
|
+
return this.alexaSmartNamesForOff;
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
public getAlexaActionNamesForOn() : string[] {
|
1034
|
+
return this.alexaActionNamesForOn;
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
public getAlexaActionNamesForOff() : string[] {
|
1038
|
+
return this.alexaActionNamesForOff;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
public getSwitchState() : string {
|
1042
|
+
return this.baseState + ".on";
|
1043
|
+
}
|
1044
|
+
|
1045
|
+
public isSwitchedOn(): boolean {
|
1046
|
+
if (this.adapter.getState(this.baseState + ".on").val == false) { // hue.0.Steckdose_Backstube.on
|
1047
|
+
return false;
|
1048
|
+
}
|
1049
|
+
return true;
|
1050
|
+
}
|
1051
|
+
|
1052
|
+
public getCategory(): string {
|
1053
|
+
return deviceZigbeeSteckdose;
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
public getAlexaNamesForOnAsString() : string {
|
1057
|
+
var result = "";
|
1058
|
+
|
1059
|
+
this.alexaSmartNamesForOn.forEach(alexaOnName => {
|
1060
|
+
if (result == "") {
|
1061
|
+
result += alexaOnName
|
1062
|
+
} else {
|
1063
|
+
result += ", " + alexaOnName;
|
1064
|
+
}
|
1065
|
+
});
|
1066
|
+
this.alexaActionNamesForOn.forEach(alexaOnName => {
|
1067
|
+
if (result == "") {
|
1068
|
+
result += alexaOnName
|
1069
|
+
} else {
|
1070
|
+
result += ", " + alexaOnName;
|
1071
|
+
}
|
1072
|
+
});
|
1073
|
+
|
1074
|
+
return result;
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
public getAlexaNamesForOffAsString() : string {
|
1078
|
+
var result = "";
|
1079
|
+
|
1080
|
+
this.alexaSmartNamesForOff.forEach(alexaOffName => {
|
1081
|
+
if (result == "") {
|
1082
|
+
result += alexaOffName
|
1083
|
+
} else {
|
1084
|
+
result += ", " + alexaOffName;
|
1085
|
+
}
|
1086
|
+
});
|
1087
|
+
this.alexaActionNamesForOff.forEach(alexaOffName => {
|
1088
|
+
if (result == "") {
|
1089
|
+
result += alexaOffName
|
1090
|
+
} else {
|
1091
|
+
result += ", " + alexaOffName;
|
1092
|
+
}
|
1093
|
+
});
|
1094
|
+
|
1095
|
+
return result;
|
1096
|
+
}
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
export class ZigbeeSchalter extends AbstractZigbee {
|
1100
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1101
|
+
super(adapter, id, baseState, etage,raum, device);
|
1102
|
+
this.adapter = adapter;
|
1103
|
+
}
|
1104
|
+
|
1105
|
+
public getCategory(): string {
|
1106
|
+
return deviceZigbeeSchalter;
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
export class ZigbeeRepeater extends AbstractZigbee {
|
1111
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1112
|
+
super(adapter, id, baseState, etage,raum, device);
|
1113
|
+
this.adapter = adapter;
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
public getCategory(): string {
|
1117
|
+
return deviceZigbeeRepeater;
|
1118
|
+
}
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
export class ZigbeeFenstersensor extends AbstractZigbee {
|
1122
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1123
|
+
super(adapter, id, baseState, etage,raum, device);
|
1124
|
+
this.adapter = adapter;
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
public isOpen(): boolean {
|
1128
|
+
if (this.adapter.getState(this.baseState + ".open").val == false) { // deconz.0.Sensors.117.open
|
1129
|
+
return false;
|
1130
|
+
}
|
1131
|
+
return true;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
public isStatusReachable() : boolean {
|
1135
|
+
var reachable = this.adapter.getState(this.baseState + ".reachable").val; // hue.0.Steckdose_Backstube.reachable
|
1136
|
+
return reachable;
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
public getBattery(): number {
|
1140
|
+
return this.adapter.getState(this.baseState + ".battery").val;// // alias.0.Z021.battery
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
public getCategory(): string {
|
1144
|
+
return deviceZigbeeFenstersensor;
|
1145
|
+
}
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
export class ZigbeeRauchmelder extends AbstractZigbee {
|
1149
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1150
|
+
super(adapter, id, baseState, etage,raum, device);
|
1151
|
+
this.adapter = adapter;
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
public isFire(): boolean {
|
1155
|
+
if (this.adapter.getState(this.baseState + ".fire").val == false) { // hue.0.Steckdose_Backstube.on
|
1156
|
+
return false;
|
1157
|
+
}
|
1158
|
+
return true;
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
public isStatusReachable() : boolean {
|
1162
|
+
var reachable = this.adapter.getState(this.baseState + ".reachable").val; // hue.0.Steckdose_Backstube.reachable
|
1163
|
+
return reachable;
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
public getBattery(): number {
|
1167
|
+
return this.adapter.getState(this.baseState + ".battery").val;// // alias.0.Z021.battery
|
1168
|
+
}
|
1169
|
+
|
1170
|
+
public getCategory(): string {
|
1171
|
+
return deviceZigbeeRauchmelder;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
export class ZigbeeBewegungsmelder extends AbstractZigbee {
|
1177
|
+
|
1178
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1179
|
+
super(adapter, id, baseState, etage,raum, device);
|
1180
|
+
this.adapter = adapter;
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
public getCategory(): string {
|
1184
|
+
return deviceZigbeeBewegungsmelder;
|
1185
|
+
}
|
1186
|
+
|
1187
|
+
public getBattery(): number {
|
1188
|
+
return this.adapter.getState(this.baseState + ".battery").val;// // alias.0.Z021.battery
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
|
1192
|
+
export class ZigbeeWandtaster extends AbstractZigbee {
|
1193
|
+
|
1194
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string) {
|
1195
|
+
super(adapter, id, baseState, etage,raum, device);
|
1196
|
+
this.adapter = adapter;
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
public getCategory(): string {
|
1200
|
+
return deviceZigbeeWandtaster;
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
public getBattery(): number {
|
1204
|
+
return this.adapter.getState(this.baseState + ".battery").val;// // alias.0.Z021.battery
|
1205
|
+
}
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
export class ZigbeeDosenrelais extends AbstractZigbee {
|
1209
|
+
protected alexaSmartNames:string[];
|
1210
|
+
|
1211
|
+
constructor(adapter:any, id: number, baseState: string, etage: string, raum: string, device: string, alexaSmartNames:string[]) {
|
1212
|
+
super(adapter, id, baseState, etage,raum, device);
|
1213
|
+
this.adapter = adapter;
|
1214
|
+
this.alexaSmartNames = alexaSmartNames;
|
1215
|
+
this.alexaSmartNames.forEach(alexaSmartName => {
|
1216
|
+
this.createIOTAdapterSmartDevices(alexaSmartName);
|
1217
|
+
});
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
public getSwitchState() : string {
|
1221
|
+
return this.baseState + ".on";
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
public isSwitchedOn(): boolean {
|
1225
|
+
if (this.adapter.getState(this.baseState + ".on").val == false) {
|
1226
|
+
return false;
|
1227
|
+
}
|
1228
|
+
return true;
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
public turnOn() {
|
1232
|
+
this.adapter.setState(this.baseState + ".on", true);
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
public turnOff() {
|
1236
|
+
this.adapter.setState(this.baseState + ".on", false);
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
public getCategory(): string {
|
1240
|
+
return deviceZigbeeDosenrelais;
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
public getAlexaSmartNames() : string[] {
|
1244
|
+
return this.alexaSmartNames;
|
1245
|
+
}
|
1246
|
+
}
|
1247
|
+
|
1248
|
+
export class AlexaInputConverter {
|
1249
|
+
private value: string;
|
1250
|
+
private actionTurnOn = false;
|
1251
|
+
private actionTurnOff = false;
|
1252
|
+
private actionChangeLevel = false;
|
1253
|
+
private actionChangeColor = false;
|
1254
|
+
private actionChangeCT = false;
|
1255
|
+
private smartName = "?";
|
1256
|
+
private levelNew = -1;
|
1257
|
+
private hueNew = -1;
|
1258
|
+
private ctNew = -1;
|
1259
|
+
private adapter:any;
|
1260
|
+
|
1261
|
+
constructor(adapter:any, value: string, logContext: string) {
|
1262
|
+
this.adapter = adapter;
|
1263
|
+
this.value = value;
|
1264
|
+
if (this.value.toString().endsWith('.level')) {
|
1265
|
+
this.smartName = this.value.replace("0_userdata.0.alexa.", "").replace(".level", "");
|
1266
|
+
this.levelNew = this.adapter.getState(value).val;
|
1267
|
+
if (this.levelNew == 100) {
|
1268
|
+
this.actionTurnOn = true;
|
1269
|
+
} else if (this.levelNew == 0) {
|
1270
|
+
this.actionTurnOff = true;
|
1271
|
+
} else {
|
1272
|
+
this.actionChangeLevel = true;
|
1273
|
+
}
|
1274
|
+
} else if (value.endsWith('.hue')) {
|
1275
|
+
this.smartName = value.replace("0_userdata.0.alexa.", "").replace(".hue", "");
|
1276
|
+
this.hueNew = this.adapter.getState(this.value).val;
|
1277
|
+
this.actionChangeColor = true;
|
1278
|
+
} else if (value.endsWith('.ct')) {
|
1279
|
+
this.smartName = value.replace("0_userdata.0.alexa.", "").replace(".ct", "");
|
1280
|
+
this.ctNew = this.adapter.getState(value).val;
|
1281
|
+
this.actionChangeCT = true;
|
1282
|
+
}
|
1283
|
+
this.adapter.log("");
|
1284
|
+
this.adapter.log(">>> ALEXA (" + logContext + ") >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
1285
|
+
this.adapter.log(" Value : " + this.value);
|
1286
|
+
this.adapter.log(" smartName : " + this.smartName);
|
1287
|
+
this.adapter.log(" actionTurnOn : " + this.actionTurnOn);
|
1288
|
+
this.adapter.log(" actionTurnOff : " + this.actionTurnOff);
|
1289
|
+
if (this.actionChangeLevel) {
|
1290
|
+
this.adapter.log(" actionChangeLevel: " + this.actionChangeLevel + " (" + this.levelNew + ")");
|
1291
|
+
} else {
|
1292
|
+
this.adapter.log(" actionChangeLevel: " + this.actionChangeLevel);
|
1293
|
+
}
|
1294
|
+
if (this.actionChangeColor) {
|
1295
|
+
this.adapter.log(" actionChangeColor: " + this.actionChangeColor + " (" + this.hueNew + ")");
|
1296
|
+
} else {
|
1297
|
+
this.adapter.log(" actionChangeColor: " + this.actionChangeColor);
|
1298
|
+
}
|
1299
|
+
if (this.actionChangeCT) {
|
1300
|
+
this.adapter.log(" actionChangeCT: " + this.actionChangeCT + " (" + this.ctNew + ")");
|
1301
|
+
} else {
|
1302
|
+
this.adapter.log(" actionChangeCT: " + this.actionChangeCT);
|
1303
|
+
}
|
1304
|
+
this.adapter.log("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
public isActionTurnedOn() : boolean {
|
1308
|
+
return this.actionTurnOn;
|
1309
|
+
}
|
1310
|
+
public isActionTurnedOff() : boolean {
|
1311
|
+
return this.actionTurnOff;
|
1312
|
+
}
|
1313
|
+
public isActionChangedLevel() : boolean {
|
1314
|
+
return this.actionChangeLevel;
|
1315
|
+
}
|
1316
|
+
public isActionChangedColor() : boolean {
|
1317
|
+
return this.actionChangeColor;
|
1318
|
+
}
|
1319
|
+
public isActionChangedColorTemperature() : boolean {
|
1320
|
+
return this.actionChangeCT;
|
1321
|
+
}
|
1322
|
+
|
1323
|
+
public getSmartName() : string {
|
1324
|
+
return this.smartName;
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
public getLevel() : number {
|
1328
|
+
return this.levelNew;
|
1329
|
+
}
|
1330
|
+
|
1331
|
+
public getHue() : number {
|
1332
|
+
return this.hueNew;
|
1333
|
+
}
|
1334
|
+
|
1335
|
+
public getColorTemperature() : number {
|
1336
|
+
return this.ctNew;
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
|
1340
|
+
module.exports = {
|
1341
|
+
AbstractZigbee, ColorScheme, RGBColorScheme, WhiteColorScheme, ZigbeeLampeRGB, LampeWeissTasterScheme, LampeWeissAlexaScheme, ZigbeeLampeWeiss, ZigbeeSteckdose, ZigbeeSchalter, ZigbeeRepeater, ZigbeeFenstersensor, ZigbeeRauchmelder, ZigbeeBewegungsmelder, ZigbeeWandtaster, ZigbeeDosenrelais,AlexaInputConverter,
|
1342
|
+
deviceZigbeeSteckdose, deviceZigbeeBewegungsmelder, deviceZigbeeLampeRGB, deviceZigbeeLampeWeiss, deviceZigbeeRauchmelder, deviceZigbeeWandtaster, deviceZigbeeDosenrelais, deviceZigbeeSchalter, deviceZigbeeRepeater, deviceZigbeeFenstersensor
|
1343
|
+
};
|
1344
|
+
|
1345
|
+
|
1346
|
+
|