iobroker.digitalstrom 2.3.0 → 3.0.0
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/LICENSE +2 -1
- package/README.md +806 -35
- package/admin/assets/index.js +682 -0
- package/admin/index.html +45 -0
- package/build/lib/activityCounter.js +82 -0
- package/build/lib/activityCounter.js.map +1 -0
- package/build/lib/configUtils.js +125 -0
- package/build/lib/configUtils.js.map +1 -0
- package/build/lib/constants.js +1285 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/dss.js +877 -0
- package/build/lib/dss.js.map +1 -0
- package/build/lib/dssQueue.js +517 -0
- package/build/lib/dssQueue.js.map +1 -0
- package/build/lib/dssSmartHome.js +769 -0
- package/build/lib/dssSmartHome.js.map +1 -0
- package/build/lib/dssSmartHomeSync.js +601 -0
- package/build/lib/dssSmartHomeSync.js.map +1 -0
- package/build/lib/dssStructure.js +3390 -0
- package/build/lib/dssStructure.js.map +1 -0
- package/build/lib/websocket.js +386 -0
- package/build/lib/websocket.js.map +1 -0
- package/build/main.js +2203 -0
- package/build/main.js.map +1 -0
- package/io-package.json +262 -266
- package/package.json +67 -36
- package/admin/admin.d.ts +0 -1
- package/admin/index_m.html +0 -201
- package/admin/style.css +0 -10
- package/admin/words.js +0 -20
- package/img/dss-apartment.png +0 -0
- package/img/dss-devices.png +0 -0
- package/lib/adapter-config.d.ts +0 -16
- package/lib/constants.js +0 -1202
- package/lib/dss.js +0 -193
- package/lib/dssQueue.js +0 -268
- package/lib/dssStructure.js +0 -1662
- package/lib/tools.js +0 -91
- package/main.js +0 -713
package/lib/dssStructure.js
DELETED
|
@@ -1,1662 +0,0 @@
|
|
|
1
|
-
const dssConstants = require('./constants');
|
|
2
|
-
|
|
3
|
-
class DSSStructure {
|
|
4
|
-
|
|
5
|
-
constructor(options) {
|
|
6
|
-
this.options = options || {};
|
|
7
|
-
this.dss = options.dss;
|
|
8
|
-
this.adapter = options.adapter;
|
|
9
|
-
this.dssQueue = options.dssQueue;
|
|
10
|
-
|
|
11
|
-
this.stateMap = {};
|
|
12
|
-
this.dssObjects = {};
|
|
13
|
-
this.initialObjectValues = {};
|
|
14
|
-
this.processedZones = {};
|
|
15
|
-
this.zoneDevices = {};
|
|
16
|
-
this.initialScenes = {};
|
|
17
|
-
|
|
18
|
-
this.apartmentStructure = null;
|
|
19
|
-
this.apartmentCircuits = null;
|
|
20
|
-
this.sensorValues = null;
|
|
21
|
-
this.temperatureControlStatus = null;
|
|
22
|
-
this.propertyUserStates = null;
|
|
23
|
-
this.propertyStates = null;
|
|
24
|
-
this.userActions = null;
|
|
25
|
-
this.reachableGroups = null;
|
|
26
|
-
this.groupTypes = dssConstants.groupTypes;
|
|
27
|
-
|
|
28
|
-
this.basicRoomScenes = [0, 5, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
init(callback) {
|
|
32
|
-
this.dss.requestAsync('apartment', 'getStructure').then((res) => {
|
|
33
|
-
if (!res || !res.ok || !res.result || !res.result.apartment) {
|
|
34
|
-
return void (callback && setImmediate(() => callback('Error on apartment/getStructure: ' + (res.message || res.status_code || res))));
|
|
35
|
-
}
|
|
36
|
-
this.apartmentStructure = res.result.apartment;
|
|
37
|
-
this.adapter.log.debug('getStructure:' + JSON.stringify(this.apartmentStructure));
|
|
38
|
-
|
|
39
|
-
this.dss.requestAsync('apartment', 'getCircuits').then((res) => {
|
|
40
|
-
if (!res || !res.ok || !res.result || !res.result.circuits) {
|
|
41
|
-
return void (callback && callback('Error on apartment/getCircuits: ' + (res.message || res.status_code || res)));
|
|
42
|
-
}
|
|
43
|
-
this.apartmentCircuits = res.result.circuits;
|
|
44
|
-
this.adapter.log.debug('getCircuits:' + JSON.stringify(this.apartmentCircuits));
|
|
45
|
-
|
|
46
|
-
this.dss.requestAsync('apartment', 'getSensorValues').then((res) => {
|
|
47
|
-
if (!res || !res.ok || !res.result) {
|
|
48
|
-
return void (callback && callback('Error on apartment/getSensorValues: ' + (res.message || res.status_code || res)));
|
|
49
|
-
}
|
|
50
|
-
this.sensorValues = res.result;
|
|
51
|
-
this.adapter.log.debug('getSensorValues: ' + JSON.stringify(this.sensorValues));
|
|
52
|
-
|
|
53
|
-
this.dss.requestAsync('apartment', 'getTemperatureControlStatus').then((res) => {
|
|
54
|
-
if (!res || !res.ok || !res.result) {
|
|
55
|
-
return void (callback && callback('Error on apartment/getTemperatureControlStatus: ' + (res.message || res.status_code || res)));
|
|
56
|
-
}
|
|
57
|
-
this.temperatureControlStatus = res.result;
|
|
58
|
-
this.adapter.log.debug('getTemperatureControlStatus: ' + JSON.stringify(this.temperatureControlStatus));
|
|
59
|
-
|
|
60
|
-
this.dss.requestAsync('property', 'query' , {query: '/usr/addon-states/system-addon-user-defined-states/*(*)'}).then((res) => {
|
|
61
|
-
if (!res || !res.ok || !res.result) {
|
|
62
|
-
return void (callback && callback('Error on query user-defined-states: ' + (res.message || res.status_code || res)));
|
|
63
|
-
}
|
|
64
|
-
this.propertyUserStates = res.result['system-addon-user-defined-states'] || [];
|
|
65
|
-
this.adapter.log.debug('property user states: ' + JSON.stringify(this.propertyUserStates));
|
|
66
|
-
|
|
67
|
-
this.dss.requestAsync('property', 'query' , {query: '/usr/states/*(*)'}).then((res) => {
|
|
68
|
-
if (!res || !res.ok || !res.result) {
|
|
69
|
-
return void (callback && callback('Error on query states: ' + (res.message || res.status_code || res)));
|
|
70
|
-
}
|
|
71
|
-
this.propertyStates = res.result.states;
|
|
72
|
-
this.adapter.log.debug('property states: ' + JSON.stringify(this.propertyStates));
|
|
73
|
-
|
|
74
|
-
this.dss.requestAsync('property', 'query' , {query: '/usr/events/*(*)/*(*)/*(*)/*(*)/*(*)'}).then((res) => {
|
|
75
|
-
if (!res || !res.ok || !res.result) {
|
|
76
|
-
return void (callback && callback('Error on query user actions: ' + (res.message || res.status_code || res)));
|
|
77
|
-
}
|
|
78
|
-
this.userActions = res.result.events;
|
|
79
|
-
this.adapter.log.debug('property user actions: ' + JSON.stringify(this.userActions));
|
|
80
|
-
|
|
81
|
-
this.dss.requestAsync('apartment', 'getReachableGroups' , {id: 0}).then((res) => {
|
|
82
|
-
if (!res || !res.ok || !res.result) {
|
|
83
|
-
return void (callback && callback('Error on apartment/getReachableGroups: ' + (res.message || res.status_code || res)));
|
|
84
|
-
}
|
|
85
|
-
this.reachableGroups = res.result;
|
|
86
|
-
this.adapter.log.debug('getReachableGroups: ' + JSON.stringify(this.reachableGroups));
|
|
87
|
-
|
|
88
|
-
this.parseData(callback);
|
|
89
|
-
}, (err) => {
|
|
90
|
-
return void (callback && callback('Error on apartment/getReachableGroups: ' + JSON.stringify(err)));
|
|
91
|
-
});
|
|
92
|
-
}, (err) => {
|
|
93
|
-
return void (callback && callback('Error on apartment/getReachableGroups: ' + JSON.stringify(err)));
|
|
94
|
-
});
|
|
95
|
-
}, (err) => {
|
|
96
|
-
return void (callback && callback('Error on query states: ' + JSON.stringify(err)));
|
|
97
|
-
});
|
|
98
|
-
}, (err) => {
|
|
99
|
-
return void (callback && callback('Error on query user-defined-states: ' + JSON.stringify(err)));
|
|
100
|
-
});
|
|
101
|
-
}, (err) => {
|
|
102
|
-
return void (callback && callback('Error on apartment/getTemperatureControlStatus: ' + JSON.stringify(err)));
|
|
103
|
-
});
|
|
104
|
-
}, (err) => {
|
|
105
|
-
return void (callback && callback('Error on apartment/getSensorValues: ' + JSON.stringify(err)));
|
|
106
|
-
});
|
|
107
|
-
}, (err) => {
|
|
108
|
-
return void (callback && callback('Error on apartment/getCircuits: ' + JSON.stringify(err)));
|
|
109
|
-
});
|
|
110
|
-
}, (err) => {
|
|
111
|
-
return void (callback && callback('Error on apartment/getStructure: ' + JSON.stringify(err)));
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
convertObject(data, nameField, prefilled) {
|
|
116
|
-
const res = prefilled || {};
|
|
117
|
-
if (!data || !Array.isArray(data)) return res;
|
|
118
|
-
data.forEach(el => {
|
|
119
|
-
if (typeof el !== 'object' || el[nameField] === undefined) return;
|
|
120
|
-
res[el[nameField]] = el;
|
|
121
|
-
});
|
|
122
|
-
return res;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
parseData(callback) {
|
|
126
|
-
const apt = {
|
|
127
|
-
clusters: this.convertObject(this.apartmentStructure.clusters, 'id'),
|
|
128
|
-
floors: this.convertObject(this.apartmentStructure.floors, 'id'),
|
|
129
|
-
zones: this.convertObject(this.apartmentStructure.zones, 'id')
|
|
130
|
-
};
|
|
131
|
-
Object.keys(apt.clusters).forEach(groupId => {
|
|
132
|
-
if (!this.groupTypes[groupId]) {
|
|
133
|
-
this.groupTypes[groupId] = apt.clusters[groupId].name;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
if (apt.zones[0]) {
|
|
137
|
-
apt.zone0 = apt.zones[0]; // Zone 0 contains everything
|
|
138
|
-
delete apt.zones[0];
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
return void (callback && setImmediate(() => callback('No devices returned in Zone 0')));
|
|
142
|
-
}
|
|
143
|
-
apt.groups = this.convertObject(apt.zone0.groups, 'id'); // enhance groups from zone 0
|
|
144
|
-
|
|
145
|
-
this.createUserActions();
|
|
146
|
-
|
|
147
|
-
this.createDevices(apt.zone0.devices, () => {
|
|
148
|
-
const reachableZoneGroups = this.convertObject(this.reachableGroups.zones, 'zoneID');
|
|
149
|
-
this.sensorValues.zones = this.convertObject(this.sensorValues.zones, 'id');
|
|
150
|
-
this.temperatureControlStatus.zones = this.convertObject(this.temperatureControlStatus.zones, 'id');
|
|
151
|
-
this.createApartment(apt, reachableZoneGroups, () => {
|
|
152
|
-
callback && callback(null);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
findStates(checkRegEx) {
|
|
158
|
-
const regEx = new RegExp(checkRegEx);
|
|
159
|
-
const res = [];
|
|
160
|
-
this.propertyStates.forEach(state => {
|
|
161
|
-
const match = state.name.match(regEx);
|
|
162
|
-
if (!match) return;
|
|
163
|
-
if (match && match[1]) {
|
|
164
|
-
state.matchedName = match[1];
|
|
165
|
-
}
|
|
166
|
-
res.push(state);
|
|
167
|
-
});
|
|
168
|
-
return res;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
updateMeterData(callback) {
|
|
172
|
-
let updateCounter = 0;
|
|
173
|
-
this.apartmentCircuits.forEach(circuit => {
|
|
174
|
-
if (!circuit.hasMetering) return;
|
|
175
|
-
|
|
176
|
-
updateCounter++;
|
|
177
|
-
this.dssQueue.pushQueryQueue(circuit.dSUID, 'getConsumption', {
|
|
178
|
-
dssClass: 'circuit',
|
|
179
|
-
dssFunction: 'getConsumption',
|
|
180
|
-
params: {
|
|
181
|
-
dsuid: circuit.dSUID
|
|
182
|
-
}
|
|
183
|
-
}, 'low', (err, res) => {
|
|
184
|
-
if (!err && (res && res.ok && res.result)) {
|
|
185
|
-
this.adapter.setState('devices.' + circuit.dSUID + '.PowerConsumption', res.result.consumption, true);
|
|
186
|
-
}
|
|
187
|
-
!--updateCounter && callback && callback();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
updateCounter++;
|
|
191
|
-
this.dssQueue.pushQueryQueue(circuit.dSUID, 'getEnergyMeterValue', {
|
|
192
|
-
dssClass: 'circuit',
|
|
193
|
-
dssFunction: 'getEnergyMeterValue',
|
|
194
|
-
params: {
|
|
195
|
-
dsuid: circuit.dSUID
|
|
196
|
-
}
|
|
197
|
-
}, 'low', (err, res) => {
|
|
198
|
-
if (!err && (res && res.ok && res.result)) {
|
|
199
|
-
this.adapter.setState('devices.' + circuit.dSUID + '.EnergyMeterValue', res.result.meterValue/3600/1000, true);
|
|
200
|
-
}
|
|
201
|
-
!--updateCounter && callback && callback();
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
!updateCounter && callback && setImmediate(() => callback());
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
createDevices(devices, callback) {
|
|
208
|
-
this.addFolderObject('devices', 'Devices');
|
|
209
|
-
|
|
210
|
-
this.apartmentCircuits.forEach(circuit => {
|
|
211
|
-
this.addFolderObject('devices.' + circuit.dSUID, circuit.name || 'Circuit');
|
|
212
|
-
if (!circuit.hasMetering) return;
|
|
213
|
-
this.addStateObject('devices.' + circuit.dSUID + '.PowerConsumption', {
|
|
214
|
-
name: 'Power Consumption',
|
|
215
|
-
role: 'value',
|
|
216
|
-
unit: 'W',
|
|
217
|
-
read: true,
|
|
218
|
-
write: false
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
this.addStateObject('devices.' + circuit.dSUID + '.EnergyMeterValue', {
|
|
222
|
-
name: 'Energy Meter',
|
|
223
|
-
role: 'value.power.consumption',
|
|
224
|
-
unit: 'kWh',
|
|
225
|
-
read: true,
|
|
226
|
-
write: false
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const circuitStates = this.findStates('^dsm\\.' + circuit.dSUID + '\\.(.*)$');
|
|
230
|
-
if (circuitStates && circuitStates.length) {
|
|
231
|
-
this.addFolderObject('devices.' + circuit.dSUID + '.states', 'DSM States', 'channel');
|
|
232
|
-
circuitStates.forEach(state => {
|
|
233
|
-
if (!state.matchedName) return;
|
|
234
|
-
const stateId = 'devices.' + circuit.dSUID + '.states.' + state.matchedName;
|
|
235
|
-
this.addStateObject(stateId, state.name, {
|
|
236
|
-
name: state.matchedName,
|
|
237
|
-
role: 'indicator',
|
|
238
|
-
type: 'string',
|
|
239
|
-
read: true,
|
|
240
|
-
write: false
|
|
241
|
-
}, value => {
|
|
242
|
-
value = !!value;
|
|
243
|
-
this.dssQueue.pushQueryQueue(circuit.dSUID, {
|
|
244
|
-
dssClass: 'state',
|
|
245
|
-
dssFunction: 'set',
|
|
246
|
-
params: {
|
|
247
|
-
name: state.name,
|
|
248
|
-
value: value
|
|
249
|
-
}
|
|
250
|
-
}, 'high', (err, res) => {
|
|
251
|
-
if (err || (res && !res.ok)) {
|
|
252
|
-
this.adapter.log.warn('Error while set State for ' + circuit.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
this.initialObjectValues[stateId] = state.state;
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
let deviceCounter = 0;
|
|
262
|
-
devices.forEach(dev => {
|
|
263
|
-
deviceCounter++;
|
|
264
|
-
setImmediate(() => this.createDevice(dev, () => {
|
|
265
|
-
!--deviceCounter && callback && callback(null);
|
|
266
|
-
}));
|
|
267
|
-
});
|
|
268
|
-
!deviceCounter && callback && setImmediate(() => callback(null));
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
createDevice(dev, callback) {
|
|
272
|
-
if (!dev.isValid || !dev.isPresent) {
|
|
273
|
-
this.adapter.log.debug('IGNORE DEVICE ' + dev.dSUID + ' because invalid');
|
|
274
|
-
callback && setImmediate(() => callback(null));
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
this.zoneDevices[dev.zoneID] = this.zoneDevices[dev.zoneID] || {};
|
|
278
|
-
dev.groups && dev.groups.forEach(group => {
|
|
279
|
-
this.zoneDevices[dev.zoneID][group] = this.zoneDevices[dev.zoneID][group] || [];
|
|
280
|
-
this.zoneDevices[dev.zoneID][group].push(dev.dSUID);
|
|
281
|
-
});
|
|
282
|
-
const devId = 'devices.' + dev.meterDSUID + '.' + dev.dSUID;
|
|
283
|
-
const devName = dev.name ? dev.name + '(' + dev.hwInfo + ')' : dev.hwInfo;
|
|
284
|
-
|
|
285
|
-
this.addFolderObject(devId, devName + ' (' + dssConstants.outputModeToRoleMap[dev.outputMode] + ')', 'device');
|
|
286
|
-
|
|
287
|
-
if (dev.sensorInputCount) {
|
|
288
|
-
let realSensors = false;
|
|
289
|
-
dev.sensors.forEach((sensor, idx) => {
|
|
290
|
-
if (!dssConstants.sensorUnitRoleMap[sensor.type]) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
if (!realSensors) {
|
|
294
|
-
this.addFolderObject(devId + '.sensors', 'Device Sensor Channels', 'channel');
|
|
295
|
-
realSensors = true;
|
|
296
|
-
}
|
|
297
|
-
const sensorId = devId + '.sensors.' + idx;
|
|
298
|
-
this.addStateObject(sensorId, dev.dSUID + '.sensors.' + idx, dssConstants.sensorUnitRoleMap[sensor.type]);
|
|
299
|
-
if (sensor.valid) {
|
|
300
|
-
this.initialObjectValues[sensorId] = sensor.value;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (dev.binaryInputCount) {
|
|
306
|
-
this.addFolderObject(devId + '.binaryInputs', 'Device Binary Inputs', 'channel');
|
|
307
|
-
dev.binaryInputs.forEach((input, idx) => {
|
|
308
|
-
if (!dssConstants.binaryInputTypeNames[input.inputType] && (input.inputType === 0 && !this.groupTypes[input.targetGroup])) {
|
|
309
|
-
this.adapter.log.warn(' INVALID BINARYINPUT TYPE ' + input.inputType + ' / ' + input.targetGroup);
|
|
310
|
-
}
|
|
311
|
-
const inputId = devId + '.binaryInputs.' + idx;
|
|
312
|
-
this.addStateObject(inputId, dev.dSUID + '.binaryInputs.' + idx, {
|
|
313
|
-
name: dssConstants.binaryInputTypeNames[input.inputType] || this.groupTypes[input.targetGroup] || 'Unknown',
|
|
314
|
-
type: 'number',
|
|
315
|
-
read: true,
|
|
316
|
-
write: false
|
|
317
|
-
});
|
|
318
|
-
this.initialObjectValues[inputId] = input.state;
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const devStates = this.findStates('^dev\\.' + dev.dSUID + '\\.(.*)$');
|
|
323
|
-
if (devStates && devStates.length) {
|
|
324
|
-
this.addFolderObject(devId + '.states', 'Device States', 'channel');
|
|
325
|
-
devStates.forEach(state => {
|
|
326
|
-
if (!state.matchedName) return;
|
|
327
|
-
const stateId = devId + '.states.' + state.matchedName;
|
|
328
|
-
this.addStateObject(stateId, state.name, {
|
|
329
|
-
name: state.matchedName,
|
|
330
|
-
role: 'indicator',
|
|
331
|
-
type: 'string',
|
|
332
|
-
read: true,
|
|
333
|
-
write: false
|
|
334
|
-
}, value => {
|
|
335
|
-
this.dssQueue.pushQueryQueue(dev.dSUID, {
|
|
336
|
-
dssClass: 'state',
|
|
337
|
-
dssFunction: 'set',
|
|
338
|
-
params: {
|
|
339
|
-
name: state.name,
|
|
340
|
-
value: value
|
|
341
|
-
}
|
|
342
|
-
}, 'high', (err, res) => {
|
|
343
|
-
if (err || (res && !res.ok)) {
|
|
344
|
-
this.adapter.log.warn('Error while set State for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
this.initialObjectValues[stateId] = state.state;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
dev.outputChannelList = {};
|
|
353
|
-
if (dev.outputMode && dev.outputChannels && dev.outputChannels.length) {
|
|
354
|
-
|
|
355
|
-
dev.outputChannels.forEach(output => {
|
|
356
|
-
if (!dssConstants.outputChannelUnitRoleMap[output.channelType]) {
|
|
357
|
-
this.adapter.log.warn(' INVALID OUTPUTCHANNEL TYPE ' + output.channelType + ': ' + JSON.stringify(output));
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
const outputChannelId = devId + '.' + output.channelId;
|
|
361
|
-
this.addStateObject(outputChannelId, dev.dSUID + '.' + output.channelId, dssConstants.outputChannelUnitRoleMap[output.channelType]);
|
|
362
|
-
dev.outputChannelList[output.channelType] = outputChannelId;
|
|
363
|
-
|
|
364
|
-
// TODO find generic way to get Output value - currently implemented per device type later (light/shade)
|
|
365
|
-
|
|
366
|
-
// TODO add way to SET values!!
|
|
367
|
-
|
|
368
|
-
/* values:/device/getOutputChannelValue2?dsuid=5a11caa06212578280d826428d15c3d700 ((OPTIONAL &channels=brightness;saturation;hue))
|
|
369
|
-
|
|
370
|
-
const channelList = dev.outputChannels.map(output => output.channelId).join(';');
|
|
371
|
-
dss.requestAsync('device', 'getOutputChannelValue' , {dsid: dev.id, channels: channelList}).then((outputChannelValues) => {
|
|
372
|
-
this.adapter.log.debug('getOutputChannelValue for ' + dev.dSUID + ' AND ' + channelList + ': ' + JSON.stringify(outputChannelValues));
|
|
373
|
-
outputChannelValues = this.convertObject(outputChannelValues.result.channels, 'index');
|
|
374
|
-
|
|
375
|
-
queueUpdateOutputValue(dev, dssConstants.outputChannelUnitRoleMap[output.channelType].channelIndex, 'medium', (err, value) => {
|
|
376
|
-
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
set /device/setOutputChannelValue2?dsuid=5a11caa06212578280d826428d15c3d700&channels={”brightness”: {”value”: 10, ”automatic”: false}, ”saturation”: {”value”: 100}, ”hue”: {”value”: 235}}
|
|
380
|
-
*/
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (dev.outputMode) {
|
|
385
|
-
// DEVICE. state (button) true= 5, false = 0
|
|
386
|
-
// sendSceneCommand
|
|
387
|
-
// setDeviceScene: '/device/callScene?dsid=%s&sceneNumber=%s&category=manual',
|
|
388
|
-
// setDeviceValue: '/device/setConfig?&dsuid=%1&class=%2&index=%3&value=%4&category=manual'
|
|
389
|
-
this.addFolderObject(devId + '.scenes', 'Device Scenes', 'channel');
|
|
390
|
-
const sceneList = {};
|
|
391
|
-
Object.keys(dssConstants.zoneSceneCommands).forEach(scene => {
|
|
392
|
-
const sceneId = devId + '.scenes.' + this.convertSceneName(dssConstants.zoneSceneCommands[scene]);
|
|
393
|
-
sceneList[scene] = dssConstants.zoneSceneCommands[scene];
|
|
394
|
-
|
|
395
|
-
this.addStateObject(sceneId, dev.dSUID + '.scenes.' + scene, {
|
|
396
|
-
name: dssConstants.zoneSceneCommands[scene],
|
|
397
|
-
type: 'boolean',
|
|
398
|
-
role: 'switch'
|
|
399
|
-
}, value => {
|
|
400
|
-
value = !!value;
|
|
401
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
402
|
-
dssClass: 'device',
|
|
403
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
404
|
-
params: {
|
|
405
|
-
dsuid: dev.dSUID,
|
|
406
|
-
sceneNumber: scene,
|
|
407
|
-
category: 'manual'
|
|
408
|
-
}
|
|
409
|
-
}, 'high', (err, res) => {
|
|
410
|
-
if (err || (res && !res.ok)) {
|
|
411
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
this.initialObjectValues[sceneId] = false;
|
|
416
|
-
});
|
|
417
|
-
for (let sceneId = 67; sceneId <= 70; sceneId++) {
|
|
418
|
-
const sceneStateId = devId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[sceneId]);
|
|
419
|
-
sceneList[sceneId] = dssConstants.apartmentScenes[sceneId];
|
|
420
|
-
|
|
421
|
-
this.addStateObject(sceneStateId, dev.dSUID + '.scenes.' + sceneId, {
|
|
422
|
-
name: dssConstants.apartmentScenes[sceneId],
|
|
423
|
-
type: 'boolean',
|
|
424
|
-
role: 'switch'
|
|
425
|
-
}, value => {
|
|
426
|
-
value = !!value;
|
|
427
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
428
|
-
dssClass: 'device',
|
|
429
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
430
|
-
params: {
|
|
431
|
-
dsuid: dev.dSUID,
|
|
432
|
-
sceneNumber: sceneId,
|
|
433
|
-
category: 'manual'
|
|
434
|
-
}
|
|
435
|
-
}, 'high', (err, res) => {
|
|
436
|
-
if (err || (res && !res.ok)) {
|
|
437
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
442
|
-
}
|
|
443
|
-
if (Object.keys(sceneList).length) {
|
|
444
|
-
this.addStateObject(devId + '.scenes.sceneId', {
|
|
445
|
-
name: 'Device Scene ID',
|
|
446
|
-
type: 'number',
|
|
447
|
-
role: 'state',
|
|
448
|
-
states: sceneList
|
|
449
|
-
},value => {
|
|
450
|
-
if (!sceneList[value]) {
|
|
451
|
-
this.adapter.log.warn('Invalid Scene ID ' + value + ' for ' + dev.dSUID + '.scenes.sceneId');
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
455
|
-
dssClass: 'device',
|
|
456
|
-
dssFunction: 'callScene',
|
|
457
|
-
params: {
|
|
458
|
-
dsuid: dev.dSUID,
|
|
459
|
-
sceneNumber: value,
|
|
460
|
-
category: 'manual'
|
|
461
|
-
}
|
|
462
|
-
}, 'high', (err, res) => {
|
|
463
|
-
if (err || (res && !res.ok)) {
|
|
464
|
-
this.adapter.log.warn('Error while callScene for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
if (dev.buttonActiveGroup > 0 && dev.buttonActiveGroup <= 8) {
|
|
472
|
-
this.addStateObject(devId + '.button', dev.dSUID + '.0.button', {
|
|
473
|
-
name: dev.name + ' Button State',
|
|
474
|
-
type: 'boolean',
|
|
475
|
-
role: 'indicator',
|
|
476
|
-
read: true,
|
|
477
|
-
write: false
|
|
478
|
-
});
|
|
479
|
-
this.initialObjectValues[devId + '.button'] = false;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (dev.hwInfo.startsWith('SW-') || dev.hwInfo.startsWith('IC SW-')) { // Joker / Tasten
|
|
483
|
-
this.createJokerDevice(dev, devId, callback);
|
|
484
|
-
}
|
|
485
|
-
else if ((dev.hwInfo.startsWith('GE-') || dev.hwInfo.startsWith('IC GE-')) && !dev.hwInfo.includes('-UMV')) { // Yellow: Light
|
|
486
|
-
this.createLightDevice(dev, devId, callback);
|
|
487
|
-
}
|
|
488
|
-
else if (dev.hwInfo.startsWith('GR-') || dev.hwInfo.startsWith('IC GR-')) { // Gray: Shades
|
|
489
|
-
this.createShaderDevice(dev, devId, callback);
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
if (dev.outputMode && dev.outputChannels && dev.outputChannels.length) {
|
|
493
|
-
if (dev.outputChannels.length === 1) {
|
|
494
|
-
const output = dev.outputChannels[0];
|
|
495
|
-
const outputStateId = devId + '.' + output.channelId;
|
|
496
|
-
if (dssConstants.outputChannelUnitRoleMap[output.channelType] && dssConstants.outputChannelUnitRoleMap[output.channelType].native) {
|
|
497
|
-
|
|
498
|
-
const roleDef = dssConstants.outputChannelUnitRoleMap[output.channelType];
|
|
499
|
-
const channelIndex = roleDef.native.channelIndex !== undefined ? roleDef.native.channelIndex : output.channelIndex;
|
|
500
|
-
const nativeMax = roleDef.native.nativeMax;
|
|
501
|
-
|
|
502
|
-
if (output && this.adapter.config.initializeOutputValues) {
|
|
503
|
-
this.dssQueue.queueUpdateOutputValue(dev, channelIndex, nativeMax, 'medium', (err, value) => {
|
|
504
|
-
if (!err) {
|
|
505
|
-
if (roleDef.native.nativeMax && roleDef.max) {
|
|
506
|
-
value = Math.round(value * roleDef.max / roleDef.native.nativeMax);
|
|
507
|
-
}
|
|
508
|
-
this.adapter.setState(outputStateId, value, true);
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
this.dssObjects[outputStateId].onChange = value => {
|
|
513
|
-
if (typeof value !== 'number') {
|
|
514
|
-
this.adapter.log.warn('Only numbers are allowed to set for ' + outputStateId);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
if (nativeMax) {
|
|
518
|
-
// For Min or Max use the scenes - but not if device is an GE/BL-UMV
|
|
519
|
-
if (!dev.hwInfo.includes('-UMV') && (roleDef.max !== undefined && value === roleDef.min) || (roleDef.max !== undefined && value === roleDef.max)) {
|
|
520
|
-
value = (value > roleDef.min);
|
|
521
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
522
|
-
dssClass: 'device',
|
|
523
|
-
dssFunction: 'callScene',
|
|
524
|
-
params: {
|
|
525
|
-
dsuid: dev.dSUID,
|
|
526
|
-
sceneNumber: value ? 14 : 13,
|
|
527
|
-
category: 'manual'
|
|
528
|
-
}
|
|
529
|
-
}, 'high', (err, res) => {
|
|
530
|
-
if (err || (res && !res.ok)) {
|
|
531
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
532
|
-
} else {
|
|
533
|
-
this.adapter.setState(outputStateId, value ? roleDef.max : roleDef.min, true);
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
const normalizedValue = Math.round(value * nativeMax / roleDef.max);
|
|
539
|
-
this.dssQueue.queueSetOutputValue(dev, channelIndex, nativeMax, normalizedValue, 'high', (err, _value) => {
|
|
540
|
-
if (err) {
|
|
541
|
-
this.adapter.log.warn('Error when setting output value for ' + dev.dSUID + ': ' + err);
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
this.adapter.setState(outputStateId, value, true);
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
// send value directly
|
|
551
|
-
this.dssQueue.queueSetOutputValue(dev, channelIndex, 1, value, 'high', (err, _value) => {
|
|
552
|
-
if (err) {
|
|
553
|
-
this.adapter.log.warn('Error when setting output value for ' + dev.dSUID + ': ' + err);
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
this.adapter.setState(outputStateId, value, true);
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
else {
|
|
563
|
-
this.adapter.log.warn('Invalid output channel definition for device ' + dev.dSUID + ': ' + JSON.stringify(output));
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
this.adapter.log.info(dev.outputChannels.length + ' Output values for device ' + dev.dSUID + ' are unsupported');
|
|
568
|
-
}
|
|
569
|
-
if (dev.buttonActiveGroup === 8) {
|
|
570
|
-
this.createJokerDevice(dev, devId, callback);
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
callback && setImmediate(() => callback());
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
if (dev.buttonActiveGroup === 8) {
|
|
578
|
-
this.createJokerDevice(dev, devId, callback);
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
callback && setImmediate(() => callback());
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
createJokerDevice(dev, devId, callback) {
|
|
588
|
-
this.addStateObject(devId + '.buttonClickType', dev.dSUID + '.0.buttonClickType', {
|
|
589
|
-
name: dev.name + ' Button Click Type',
|
|
590
|
-
type: 'number',
|
|
591
|
-
role: 'indicator',
|
|
592
|
-
state: {
|
|
593
|
-
0: 'Single Tip',
|
|
594
|
-
1: 'Double Tip',
|
|
595
|
-
2: 'Triple Tip',
|
|
596
|
-
3: 'Quadruple Tip',
|
|
597
|
-
4: 'Hold Start',
|
|
598
|
-
5: 'Hold Repeat',
|
|
599
|
-
6: 'Hold End',
|
|
600
|
-
7: 'Single Click',
|
|
601
|
-
8: 'Double Click',
|
|
602
|
-
9: 'Triple Click',
|
|
603
|
-
10: 'Single Tip (Off)',
|
|
604
|
-
11: 'Single Tip (On/Down)',
|
|
605
|
-
12: 'Single Tip (On/Up)',
|
|
606
|
-
14: 'Single Tip (Stop)'
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
this.initialObjectValues[devId + '.buttonClickType'] = null;
|
|
610
|
-
|
|
611
|
-
this.addStateObject(devId + '.buttonHoldCount', dev.dSUID + '.0.buttonHoldCount', {
|
|
612
|
-
name: dev.name + ' Button Hold Count',
|
|
613
|
-
type: 'number',
|
|
614
|
-
role: 'indicator',
|
|
615
|
-
unit: 'ms',
|
|
616
|
-
read: true,
|
|
617
|
-
write: false
|
|
618
|
-
});
|
|
619
|
-
this.initialObjectValues[devId + '.buttonHoldCount'] = 0;
|
|
620
|
-
|
|
621
|
-
if (dev.buttonInputCount > 1) {
|
|
622
|
-
for (let cnt = 1; cnt < dev.buttonInputCount;cnt ++) {
|
|
623
|
-
this.addStateObject(devId + '.button-' + cnt, dev.dSUID + '.' + cnt + '.button', {
|
|
624
|
-
name: dev.name + ' Button State',
|
|
625
|
-
type: 'boolean',
|
|
626
|
-
role: 'indicator',
|
|
627
|
-
read: true,
|
|
628
|
-
write: false
|
|
629
|
-
});
|
|
630
|
-
this.initialObjectValues[devId + '.button-' + cnt] = false;
|
|
631
|
-
|
|
632
|
-
this.addStateObject(devId + '.buttonClickType-' + cnt, dev.dSUID + '.' + cnt + '.buttonClickType', {
|
|
633
|
-
name: dev.name + ' Button Click Type',
|
|
634
|
-
type: 'number',
|
|
635
|
-
role: 'indicator',
|
|
636
|
-
state: {
|
|
637
|
-
0: 'Single Tip',
|
|
638
|
-
1: 'Double Tip',
|
|
639
|
-
2: 'Triple Tip',
|
|
640
|
-
3: 'Quadruple Tip',
|
|
641
|
-
4: 'Hold Start',
|
|
642
|
-
5: 'Hold Repeat',
|
|
643
|
-
6: 'Hold End',
|
|
644
|
-
7: 'Single Click',
|
|
645
|
-
8: 'Double Click',
|
|
646
|
-
9: 'Triple Click',
|
|
647
|
-
10: 'Single Tip (Off)',
|
|
648
|
-
11: 'Single Tip (On/Down)',
|
|
649
|
-
12: 'Single Tip (On/Up)',
|
|
650
|
-
14: 'Single Tip (Stop)'
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
this.initialObjectValues[devId + '.buttonClickType-' + cnt] = null;
|
|
654
|
-
|
|
655
|
-
this.addStateObject(devId + '.buttonHoldCount-' + cnt, dev.dSUID + '.' + cnt + '.buttonHoldCount', {
|
|
656
|
-
name: dev.name + ' Button Hold Count',
|
|
657
|
-
type: 'number',
|
|
658
|
-
role: 'indicator',
|
|
659
|
-
unit: 'ms',
|
|
660
|
-
read: true,
|
|
661
|
-
write: false
|
|
662
|
-
});
|
|
663
|
-
this.initialObjectValues[devId + '.buttonHoldCount-' + cnt] = 0;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
callback && setImmediate(() => callback());
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
createLightDevice(dev, devId, callback) {
|
|
670
|
-
const setLightValue = (outputType, value) => {
|
|
671
|
-
if (outputType !== 'brightness') {
|
|
672
|
-
this.adapter.log.warn('Not supported ' + outputType + ' for ' + dev.dSUID);
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
const percentValue = Math.round(value * 100 / 255);
|
|
676
|
-
if (dev.outputMode === 16 && dev.outputSwitchThreshold !== undefined) {
|
|
677
|
-
this.adapter.setState(devId + '.state', (value >= dev.outputSwitchThreshold), true);
|
|
678
|
-
this.initialObjectValues[devId + '.state'] = (value >= dev.outputSwitchThreshold);
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
this.adapter.setState(devId + '.state', !!percentValue, true);
|
|
682
|
-
this.initialObjectValues[devId + '.state'] = !!percentValue;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
if (this.stateMap[dev.dSUID + '.brightness']) {
|
|
686
|
-
this.adapter.setState(this.stateMap[dev.dSUID + '.brightness'], percentValue, true);
|
|
687
|
-
this.initialObjectValues[this.stateMap[dev.dSUID + '.brightness']] = percentValue
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
if (dev.outputMode === 16 && dev.outputSwitchThreshold === undefined) {
|
|
692
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
693
|
-
dssClass: 'device',
|
|
694
|
-
dssFunction: 'getSwitchThreshold',
|
|
695
|
-
params: {
|
|
696
|
-
dsuid: dev.dSUID,
|
|
697
|
-
category: 'manual'
|
|
698
|
-
}
|
|
699
|
-
}, 'high', (err, res) => {
|
|
700
|
-
if (err || (res && !res.ok) || !res.result || res.result.threshold === undefined || typeof res.result.threshold !== 'number') {
|
|
701
|
-
this.adapter.log.warn('Can not get SwitchThreshold for ' + dev.dSUID + ', assume 50%');
|
|
702
|
-
dev.outputSwitchThreshold = 128;
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
dev.outputSwitchThreshold = res.result.threshold;
|
|
706
|
-
}
|
|
707
|
-
this.createLightDevice(dev, devId, callback);
|
|
708
|
-
});
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
this.addStateObject( devId + '.state', {
|
|
713
|
-
name: dev.name + ' State',
|
|
714
|
-
type: 'boolean',
|
|
715
|
-
role: 'switch.light'
|
|
716
|
-
}, value => {
|
|
717
|
-
value = !!value;
|
|
718
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
719
|
-
dssClass: 'device',
|
|
720
|
-
dssFunction: 'callScene',
|
|
721
|
-
params: {
|
|
722
|
-
dsuid: dev.dSUID,
|
|
723
|
-
sceneNumber: value ? 14 : 13,
|
|
724
|
-
category: 'manual'
|
|
725
|
-
}
|
|
726
|
-
}, 'high', (err, res) => {
|
|
727
|
-
if (err || (res && !res.ok)) {
|
|
728
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
setLightValue('brightness', value ? 255 : 0);
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
if (this.dssObjects[devId + '.brightness']) {
|
|
736
|
-
this.dssObjects[devId + '.brightness'].onChange = value => {
|
|
737
|
-
if (value === 0 || value === 100) {
|
|
738
|
-
value = !!value;
|
|
739
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
740
|
-
dssClass: 'device',
|
|
741
|
-
dssFunction: 'callScene',
|
|
742
|
-
params: {
|
|
743
|
-
dsuid: dev.dSUID,
|
|
744
|
-
sceneNumber: value ? 14 : 13,
|
|
745
|
-
category: 'manual'
|
|
746
|
-
}
|
|
747
|
-
}, 'high', (err, res) => {
|
|
748
|
-
if (err || (res && !res.ok)) {
|
|
749
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
750
|
-
} else {
|
|
751
|
-
setLightValue('brightness', value ? 255 : 0);
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
value = Math.round(value * dssConstants.outputChannelUnitRoleMap['brightness'].native.nativeMax / 100);
|
|
757
|
-
this.dssQueue.queueSetOutputValue(dev, dssConstants.outputChannelUnitRoleMap['brightness'].native.channelIndex, dssConstants.outputChannelUnitRoleMap['brightness'].native.nativeMax, value, 'high', (err, value) => {
|
|
758
|
-
if (err) {
|
|
759
|
-
this.adapter.log.warn('Error when setting output value for ' + dev.dSUID + ': ' + err);
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
setLightValue('brightness', value);
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
if (dev.outputChannelList && this.adapter.config.initializeOutputValues) {
|
|
770
|
-
Object.keys(dev.outputChannelList).forEach(outputType => {
|
|
771
|
-
this.dssQueue.queueUpdateOutputValue(dev, dssConstants.outputChannelUnitRoleMap[outputType].native.channelIndex, dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax, 'medium', (err, value) => {
|
|
772
|
-
if (!err) {
|
|
773
|
-
setLightValue(outputType, value);
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
})
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
this.dss.on(dev.dSUID, data => {
|
|
780
|
-
this.adapter.log.debug('DEVICE event ' + JSON.stringify(data));
|
|
781
|
-
if (data.name !== 'callScene' && data.name !== 'undoScene') return;
|
|
782
|
-
let brightness;
|
|
783
|
-
if (this.adapter.config.usePresetValues) {
|
|
784
|
-
brightness = dssConstants.lightSceneValueMap[data.properties.sceneID];
|
|
785
|
-
if (brightness !== null && brightness !== undefined) {
|
|
786
|
-
setLightValue('brightness', brightness);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
this.dssQueue.queueUpdateOutputValue(dev, 0, ((brightness !== null && brightness !== undefined) || data.source.isGroup) ? 'low' : 'medium', (err, value) => {
|
|
790
|
-
if (!err) {
|
|
791
|
-
setLightValue('brightness', value);
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
callback && setImmediate(() => callback());
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
createShaderDevice(dev, devId, callback) {
|
|
800
|
-
let positionName = null;
|
|
801
|
-
let angleName = null;
|
|
802
|
-
|
|
803
|
-
if (dev.outputChannelList && this.adapter.config.initializeOutputValues) {
|
|
804
|
-
Object.keys(dev.outputChannelList).forEach(outputType => {
|
|
805
|
-
let relevant = false;
|
|
806
|
-
if (!positionName && outputType.includes('Position')) {
|
|
807
|
-
positionName = outputType;
|
|
808
|
-
relevant = true;
|
|
809
|
-
}
|
|
810
|
-
else if (!angleName && outputType.includes('Angle')) {
|
|
811
|
-
angleName = outputType;
|
|
812
|
-
relevant = true;
|
|
813
|
-
}
|
|
814
|
-
if (!relevant) return;
|
|
815
|
-
this.dssObjects[dev.outputChannelList[outputType]].onChange = value => {
|
|
816
|
-
const originalValue = value;
|
|
817
|
-
if (outputType === positionName && (value === 0 || value === 100)) {
|
|
818
|
-
value = !!value;
|
|
819
|
-
this.dssQueue.pushQueryQueue(dev.meterDSUID, {
|
|
820
|
-
dssClass: 'device',
|
|
821
|
-
dssFunction: 'callScene',
|
|
822
|
-
params: {
|
|
823
|
-
dsuid: dev.dSUID,
|
|
824
|
-
sceneNumber: value ? 14 : 13,
|
|
825
|
-
category: 'manual'
|
|
826
|
-
}
|
|
827
|
-
}, 'high', (err, res) => {
|
|
828
|
-
if (err || (res && !res.ok)) {
|
|
829
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for ' + dev.dSUID + ': ' + (err || JSON.stringify(res)));
|
|
830
|
-
} else {
|
|
831
|
-
this.adapter.setState(dev.outputChannelList[outputType], originalValue, true);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
else {
|
|
836
|
-
value = Math.round(value * dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax / 100);
|
|
837
|
-
this.dssQueue.queueSetOutputValue(dev, dssConstants.outputChannelUnitRoleMap[outputType].native.channelIndex, dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax, value, 'high', (err, _value) => {
|
|
838
|
-
if (err) {
|
|
839
|
-
this.adapter.log.warn('Error when setting output value for ' + dev.dSUID + ': ' + err);
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
this.adapter.setState(dev.outputChannelList[outputType], originalValue, true);
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
this.dssQueue.queueUpdateOutputValue(dev, dssConstants.outputChannelUnitRoleMap[outputType].native.channelIndex, dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax, 'medium', (err, value) => {
|
|
848
|
-
if (!err) {
|
|
849
|
-
if (dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax) {
|
|
850
|
-
value = Math.round(value * 100 / dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax);
|
|
851
|
-
}
|
|
852
|
-
this.adapter.setState(dev.outputChannelList[outputType], value, true);
|
|
853
|
-
this.initialObjectValues[dev.outputChannelList[outputType]] = value;
|
|
854
|
-
}
|
|
855
|
-
});
|
|
856
|
-
})
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
const valueUpdateTimeouts = {};
|
|
860
|
-
this.dss.on(dev.dSUID, data => {
|
|
861
|
-
this.adapter.log.debug('DEVICE event ' + JSON.stringify(data));
|
|
862
|
-
if (data.name !== 'callScene' && data.name !== 'undoScene') return;
|
|
863
|
-
if (this.adapter.config.usePresetValues) {
|
|
864
|
-
let shadePos = dssConstants.shadeSceneValueMap[data.properties.sceneID];
|
|
865
|
-
if (shadePos !== null && shadePos !== undefined) {
|
|
866
|
-
shadePos = Math.round(shadePos * 100 / 65535);
|
|
867
|
-
positionName && this.adapter.setState(dev.outputChannelList[positionName], shadePos, true);
|
|
868
|
-
if (shadePos === 0 || shadePos === 100 && angleName && dev.outputChannelList[angleName]) {
|
|
869
|
-
if (!this.dssObjects[dev.outputChannelList[angleName]]) {
|
|
870
|
-
this.adapter.log.warn('Can not set unknown state ' + dev.outputChannelList[angleName]);
|
|
871
|
-
}
|
|
872
|
-
else {
|
|
873
|
-
this.adapter.setState(dev.outputChannelList[angleName], shadePos, true);
|
|
874
|
-
this.initialObjectValues[dev.outputChannelList[angleName]] = shadePos;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
if (dev.outputChannelList) {
|
|
881
|
-
Object.keys(dev.outputChannelList).forEach(outputType => {
|
|
882
|
-
if (valueUpdateTimeouts[outputType]) {
|
|
883
|
-
clearTimeout(valueUpdateTimeouts[outputType]);
|
|
884
|
-
valueUpdateTimeouts[outputType] = null;
|
|
885
|
-
}
|
|
886
|
-
valueUpdateTimeouts[outputType] = setTimeout(() => {
|
|
887
|
-
valueUpdateTimeouts[outputType] = null;
|
|
888
|
-
this.dssQueue.queueUpdateOutputValue(dev, dssConstants.outputChannelUnitRoleMap[outputType].native.channelIndex, dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax, 'medium', (err, value) => {
|
|
889
|
-
if (!err) {
|
|
890
|
-
if (dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax) {
|
|
891
|
-
value = Math.round(value * 100 / dssConstants.outputChannelUnitRoleMap[outputType].native.nativeMax);
|
|
892
|
-
}
|
|
893
|
-
this.adapter.setState(dev.outputChannelList[outputType], value, true);
|
|
894
|
-
this.initialObjectValues[dev.outputChannelList[outputType]] = value;
|
|
895
|
-
}
|
|
896
|
-
});
|
|
897
|
-
}, 2000);
|
|
898
|
-
})
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
callback && setImmediate(() => callback());
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
convertSceneName(name) {
|
|
906
|
-
if (!name) {
|
|
907
|
-
return name;
|
|
908
|
-
}
|
|
909
|
-
const brackets = name.indexOf(' (');
|
|
910
|
-
if (brackets !== -1) {
|
|
911
|
-
name = name.substr(0, brackets);
|
|
912
|
-
}
|
|
913
|
-
name = name.replace(/ /g, '');
|
|
914
|
-
return name;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
createUserActions() {
|
|
918
|
-
if (!this.userActions || !this.userActions.length) return;
|
|
919
|
-
|
|
920
|
-
this.addFolderObject('userActions', 'User Actions', 'channel');
|
|
921
|
-
|
|
922
|
-
this.userActions.forEach(action => {
|
|
923
|
-
this.addStateObject('userActions.' + action.id, {
|
|
924
|
-
name: 'User Action ' + action.name,
|
|
925
|
-
type: 'boolean',
|
|
926
|
-
role: 'button'
|
|
927
|
-
},value => {
|
|
928
|
-
if (!value) return;
|
|
929
|
-
this.dssQueue.pushQueryQueue('event-' + action.id, {
|
|
930
|
-
dssClass: 'event',
|
|
931
|
-
dssFunction: 'raise',
|
|
932
|
-
params: {
|
|
933
|
-
name: 'highlevelevent',
|
|
934
|
-
parameter: 'id=' + action.id
|
|
935
|
-
}
|
|
936
|
-
}, 'high', (err, res) => {
|
|
937
|
-
if (err || (res && !res.ok)) {
|
|
938
|
-
this.adapter.log.warn('Error while raise event for apartment: ' + (err || JSON.stringify(res)));
|
|
939
|
-
}
|
|
940
|
-
});
|
|
941
|
-
});
|
|
942
|
-
this.initialObjectValues['userActions.' + action.id] = false;
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
createApartment(apartment, reachableZoneGroups, callback) {
|
|
947
|
-
this.addFolderObject('apartment', 'Apartment');
|
|
948
|
-
|
|
949
|
-
let callbackCounter = 0;
|
|
950
|
-
// Create Floors and Zones and Groups inside
|
|
951
|
-
Object.keys(apartment.floors).forEach(floorId => {
|
|
952
|
-
const floor = apartment.floors[floorId];
|
|
953
|
-
this.addFolderObject('apartment.' + floorId, floor.name || 'Floor ' + floorId);
|
|
954
|
-
|
|
955
|
-
floor.zones.forEach(zoneId => {
|
|
956
|
-
callbackCounter++;
|
|
957
|
-
setImmediate(() => this.processZone('apartment.' + floorId, apartment.zones[zoneId], reachableZoneGroups[zoneId].groups, this.sensorValues.zones[zoneId], this.temperatureControlStatus.zones[zoneId], () => {
|
|
958
|
-
!--callbackCounter && callback && callback(null);
|
|
959
|
-
}));
|
|
960
|
-
});
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// Check if we have available Zones that were not assigned to any floor (should not happen)
|
|
964
|
-
Object.keys(apartment.zones).forEach(zoneId => {
|
|
965
|
-
if (this.processedZones[zoneId] || !apartment.zones[zoneId].isValid) return;
|
|
966
|
-
this.adapter.log.warn('EXTRANOUS ZONE found ' + zoneId);
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
this.addFolderObject('apartment.scenes', 'Apartment Scenes', 'channel');
|
|
970
|
-
|
|
971
|
-
const sceneList = {};
|
|
972
|
-
Object.keys(dssConstants.apartmentScenes).forEach(sceneId => {
|
|
973
|
-
// @ts-ignore
|
|
974
|
-
if (sceneId >= 67 && sceneId <= 70) return; // ignore Zone Scenes?
|
|
975
|
-
const sceneStateId = 'apartment.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[sceneId]);
|
|
976
|
-
sceneList[sceneId] = dssConstants.apartmentScenes[sceneId];
|
|
977
|
-
|
|
978
|
-
this.addStateObject(sceneStateId, '0.0.scenes.' + sceneId, {
|
|
979
|
-
name: 'Apartment ' + dssConstants.apartmentScenes[sceneId],
|
|
980
|
-
type: 'boolean',
|
|
981
|
-
role: 'switch'
|
|
982
|
-
},value => {
|
|
983
|
-
value = !!value;
|
|
984
|
-
this.dssQueue.pushQueryQueue('apartment', {
|
|
985
|
-
dssClass: 'apartment',
|
|
986
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
987
|
-
params: {
|
|
988
|
-
sceneNumber: sceneId
|
|
989
|
-
}
|
|
990
|
-
}, 'high', (err, res) => {
|
|
991
|
-
if (err || (res && !res.ok)) {
|
|
992
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for apartment: ' + (err || JSON.stringify(res)));
|
|
993
|
-
}
|
|
994
|
-
});
|
|
995
|
-
});
|
|
996
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
997
|
-
});
|
|
998
|
-
if (Object.keys(sceneList).length) {
|
|
999
|
-
this.addStateObject('apartment.scenes.sceneId', {
|
|
1000
|
-
name: 'Scene ID',
|
|
1001
|
-
type: 'number',
|
|
1002
|
-
role: 'state',
|
|
1003
|
-
states: sceneList
|
|
1004
|
-
},value => {
|
|
1005
|
-
if (!sceneList[value]) {
|
|
1006
|
-
this.adapter.log.warn('Invalid Scene ID ' + value + ' for apartment.scenes.sceneId');
|
|
1007
|
-
return;
|
|
1008
|
-
}
|
|
1009
|
-
this.dssQueue.pushQueryQueue('apartment', {
|
|
1010
|
-
dssClass: 'apartment',
|
|
1011
|
-
dssFunction: 'callScene',
|
|
1012
|
-
params: {
|
|
1013
|
-
sceneNumber: value
|
|
1014
|
-
}
|
|
1015
|
-
}, 'high', (err, res) => {
|
|
1016
|
-
if (err || (res && !res.ok)) {
|
|
1017
|
-
this.adapter.log.warn('Error while callScene for apartment: ' + (err || JSON.stringify(res)));
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
});
|
|
1021
|
-
|
|
1022
|
-
callbackCounter++;
|
|
1023
|
-
this.dssQueue.pushQueryQueue('apartment', {
|
|
1024
|
-
dssClass: 'zone',
|
|
1025
|
-
dssFunction: 'getLastCalledScene',
|
|
1026
|
-
params: {
|
|
1027
|
-
id: 0
|
|
1028
|
-
}
|
|
1029
|
-
}, 'high', (err, res) => {
|
|
1030
|
-
if (err || (res && !res.ok) || !res.result || res.result.scene === undefined) {
|
|
1031
|
-
this.adapter.log.warn('Error while getLastCalledScene for apartment: ' + (err || JSON.stringify(res)));
|
|
1032
|
-
}
|
|
1033
|
-
else {
|
|
1034
|
-
this.initialObjectValues['apartment.scenes.sceneId'] = res.result.scene;
|
|
1035
|
-
this.initialScenes['0.0'] = res.result.scene;
|
|
1036
|
-
const sceneStateId = 'apartment.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[res.result.scene]);
|
|
1037
|
-
if (this.dssObjects[sceneStateId]) {
|
|
1038
|
-
this.initialObjectValues[sceneStateId] = true;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
!--callbackCounter && callback && callback(null);
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
const aptStates = this.findStates('^([^.]*)$');
|
|
1046
|
-
if (aptStates && aptStates.length) {
|
|
1047
|
-
this.addFolderObject('apartment.states', 'Apartment States', 'channel');
|
|
1048
|
-
|
|
1049
|
-
aptStates.forEach(state => {
|
|
1050
|
-
if (!state.matchedName) return;
|
|
1051
|
-
const stateId = 'apartment.states.' + state.matchedName;
|
|
1052
|
-
const stateName = state.matchedName;
|
|
1053
|
-
let stateValue = state.state;
|
|
1054
|
-
|
|
1055
|
-
let roleMap = dssConstants.apartmentStateRoleMap[stateName];
|
|
1056
|
-
|
|
1057
|
-
if (!roleMap) {
|
|
1058
|
-
roleMap = {
|
|
1059
|
-
name: stateName,
|
|
1060
|
-
role: 'indicator',
|
|
1061
|
-
type: 'boolean',
|
|
1062
|
-
read: true,
|
|
1063
|
-
write: false,
|
|
1064
|
-
native: {
|
|
1065
|
-
valueTrue: 'active',
|
|
1066
|
-
valueFalse: 'inactive'
|
|
1067
|
-
}
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
if (roleMap.native) {
|
|
1071
|
-
if (roleMap.native.valueTrue !== undefined && stateValue == roleMap.native.valueTrue) {
|
|
1072
|
-
stateValue = true;
|
|
1073
|
-
} else if (roleMap.native.valueFalse !== undefined && stateValue == roleMap.native.valueFalse) {
|
|
1074
|
-
stateValue = false;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
this.addStateObject(stateId, state.name, roleMap, value => {
|
|
1078
|
-
value = !!value;
|
|
1079
|
-
if (!this.dssObjects[stateId] || !this.dssObjects[stateId].native) return;
|
|
1080
|
-
this.dssQueue.pushQueryQueue('apartment', {
|
|
1081
|
-
dssClass: 'state',
|
|
1082
|
-
dssFunction: 'set',
|
|
1083
|
-
params: {
|
|
1084
|
-
name: state.name,
|
|
1085
|
-
value: value ? this.dssObjects[stateId].native.valueTrue : this.dssObjects[stateId].native.valueFalse
|
|
1086
|
-
}
|
|
1087
|
-
}, 'high', (err, res) => {
|
|
1088
|
-
if (err || (res && !res.ok)) {
|
|
1089
|
-
this.adapter.log.warn('Error while set State for apartment: ' + (err || JSON.stringify(res)));
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
this.initialObjectValues[stateId] = stateValue;
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
if (this.propertyUserStates && this.propertyUserStates.length) {
|
|
1098
|
-
this.addFolderObject('apartment.userStates', 'Apartment User States', 'channel');
|
|
1099
|
-
|
|
1100
|
-
this.propertyUserStates.forEach(state => {
|
|
1101
|
-
const stateId = 'apartment.userStates.' + state.name.replace(/\./g, '-');
|
|
1102
|
-
let stateValue = state.state;
|
|
1103
|
-
const stateObj = {
|
|
1104
|
-
name: state.displayName,
|
|
1105
|
-
role: 'indicator',
|
|
1106
|
-
type: 'string'
|
|
1107
|
-
};
|
|
1108
|
-
this.addStateObject(stateId, state.name, stateObj, stateValue, value => {
|
|
1109
|
-
this.dssQueue.pushQueryQueue('apartment-user', {
|
|
1110
|
-
dssClass: 'state',
|
|
1111
|
-
dssFunction: 'set',
|
|
1112
|
-
params: {
|
|
1113
|
-
addon: 'system-addon-user-defined-states',
|
|
1114
|
-
name: state.name,
|
|
1115
|
-
value: value
|
|
1116
|
-
}
|
|
1117
|
-
}, 'high', (err, res) => {
|
|
1118
|
-
if (err || (res && !res.ok)) {
|
|
1119
|
-
this.adapter.log.warn('Error while set State for apartment-user: ' + (err || JSON.stringify(res)));
|
|
1120
|
-
}
|
|
1121
|
-
});
|
|
1122
|
-
});
|
|
1123
|
-
this.initialObjectValues[stateId] = stateValue;
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
this.addFolderObject('apartment.sensors', 'Apartment Sensors');
|
|
1128
|
-
|
|
1129
|
-
// Ignore weather for now!
|
|
1130
|
-
if (this.sensorValues.outdoor && Object.keys(this.sensorValues.outdoor).length) {
|
|
1131
|
-
this.addFolderObject('apartment.sensors.outdoor', 'Apartment Outdoor Sensors', 'channel');
|
|
1132
|
-
|
|
1133
|
-
Object.keys(this.sensorValues.outdoor).forEach(sensorName => {
|
|
1134
|
-
if (!dssConstants.sensorValuesRoleMapOutdoor[sensorName]) {
|
|
1135
|
-
this.adapter.log.warn('INVALID Sensor Type! ' + sensorName);
|
|
1136
|
-
return;
|
|
1137
|
-
}
|
|
1138
|
-
this.addStateObject('apartment.sensors.outdoor.' + sensorName, '0.sensors.' + dssConstants.sensorValuesRoleMapOutdoor[sensorName].native.sensorType, dssConstants.sensorValuesRoleMapOutdoor[sensorName]);
|
|
1139
|
-
this.initialObjectValues['apartment.sensors.outdoor.' + sensorName] = {
|
|
1140
|
-
val: this.sensorValues.outdoor[sensorName].value,
|
|
1141
|
-
ts: typeof this.sensorValues.outdoor[sensorName].time === 'number' ? this.sensorValues.outdoor[sensorName].time : new Date(this.sensorValues.outdoor[sensorName].time).getTime()
|
|
1142
|
-
};
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
this.addStateObject('apartment.sensors.VentilationStatusValue', '0.sensors.60', {
|
|
1146
|
-
name: 'Ventilation Status',
|
|
1147
|
-
type: 'boolean',
|
|
1148
|
-
role: 'indicator',
|
|
1149
|
-
read: true,
|
|
1150
|
-
write: false
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
// Create Apartment groups, as soon as at least one device is present
|
|
1154
|
-
this.addFolderObject('apartment.groups', 'Apartment Groups');
|
|
1155
|
-
|
|
1156
|
-
apartment.zone0.groups.forEach(group => {
|
|
1157
|
-
if (!group.devices || !group.devices.length) return;
|
|
1158
|
-
callbackCounter++;
|
|
1159
|
-
setImmediate(() => this.processGroup('apartment.groups.' + group.id, 0, group, () => {
|
|
1160
|
-
!--callbackCounter && callback && callback(null);
|
|
1161
|
-
}));
|
|
1162
|
-
|
|
1163
|
-
// setApartmentScene: '/apartment/callScene?sceneNumber=%s&force=true',
|
|
1164
|
-
// setZoneScene: '/zone/callScene?id=%s&sceneNumber=%s&force=true',
|
|
1165
|
-
// setGroupScene: '/zone/callScene?id=%s&groupID=%s&sceneNumber=%s&force=true',
|
|
1166
|
-
// undoScene
|
|
1167
|
-
});
|
|
1168
|
-
!callbackCounter && callback && setImmediate(() => callback(null));
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
processZone(baseId, zone, reachableGroups, sensorValues, temperatureControlStatus, callback) {
|
|
1172
|
-
if (!zone) {
|
|
1173
|
-
this.adapter.log.debug('INVALID ZONE ' + zone.id);
|
|
1174
|
-
return callback && setImmediate(callback, null);
|
|
1175
|
-
}
|
|
1176
|
-
if (!zone.isPresent) {
|
|
1177
|
-
this.adapter.log.debug('Ignore not present zone ' + zone.id);
|
|
1178
|
-
return callback && setImmediate(callback, null);
|
|
1179
|
-
}
|
|
1180
|
-
if (this.processedZones[zone.id]) {
|
|
1181
|
-
this.adapter.log.debug('Zone ' + zone.id + ' already processec');
|
|
1182
|
-
return callback && setImmediate(callback, null);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
const zoneBaseId = baseId + '.' + zone.id;
|
|
1186
|
-
this.addFolderObject(zoneBaseId, zone.name || 'Zone ' + zone.id);
|
|
1187
|
-
|
|
1188
|
-
const zoneStates = this.findStates('^zone\\.' + zone.id + '\\.([^.]*)$');
|
|
1189
|
-
if (zoneStates && zoneStates.length) {
|
|
1190
|
-
this.addFolderObject(zoneBaseId + '.states', 'Zone States', 'channel');
|
|
1191
|
-
|
|
1192
|
-
zoneStates.forEach(state => {
|
|
1193
|
-
if (!state.matchedName) return;
|
|
1194
|
-
const stateId = zoneBaseId + '.states.' + state.matchedName;
|
|
1195
|
-
const stateName = state.matchedName;
|
|
1196
|
-
let stateValue = state.state;
|
|
1197
|
-
if (!dssConstants.zoneStateRoleMap[stateName]) {
|
|
1198
|
-
this.adapter.log.info('INVALID Zone State ' + state.matchedName + ': ' + JSON.stringify(state));
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
if (dssConstants.zoneStateRoleMap[stateName].native) {
|
|
1203
|
-
if (dssConstants.zoneStateRoleMap[stateName].native.valueTrue !== undefined && stateValue === dssConstants.zoneStateRoleMap[stateName].native.valueTrue) {
|
|
1204
|
-
stateValue = true;
|
|
1205
|
-
}
|
|
1206
|
-
else if (dssConstants.zoneStateRoleMap[stateName].native.valueFalse !== undefined && stateValue === dssConstants.zoneStateRoleMap[stateName].native.valueFalse) {
|
|
1207
|
-
stateValue = false;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
this.addStateObject(stateId, state.name, dssConstants.zoneStateRoleMap[stateName], stateValue, value => {
|
|
1211
|
-
value = !!value;
|
|
1212
|
-
if (!this.dssObjects[stateId] || !this.dssObjects[stateId].native) return;
|
|
1213
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1214
|
-
dssClass: 'state',
|
|
1215
|
-
dssFunction: 'set',
|
|
1216
|
-
params: {
|
|
1217
|
-
name: state.name,
|
|
1218
|
-
value: value ? this.dssObjects[stateId].native.valueTrue : this.dssObjects[stateId].native.valueFalse
|
|
1219
|
-
}
|
|
1220
|
-
}, 'high', (err, res) => {
|
|
1221
|
-
if (err || (res && !res.ok)) {
|
|
1222
|
-
this.adapter.log.warn('Error while set State for zone: ' + (err || JSON.stringify(res)));
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
});
|
|
1226
|
-
this.initialObjectValues[stateId] = stateValue;
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
let groupCounter = 0;
|
|
1231
|
-
zone.groups.forEach(group => {
|
|
1232
|
-
if (!reachableGroups.includes(group.id)) return;
|
|
1233
|
-
groupCounter++;
|
|
1234
|
-
setImmediate(() => this.processGroup(zoneBaseId + '.' + group.id, zone.id, group, () => {
|
|
1235
|
-
!--groupCounter && callback && callback(null);
|
|
1236
|
-
}));
|
|
1237
|
-
});
|
|
1238
|
-
this.processedZones[zone.id] = true;
|
|
1239
|
-
|
|
1240
|
-
this.addFolderObject(zoneBaseId + '.scenes', (zone.name || 'Zone ' + zone.id) + ' Scenes', 'channel');
|
|
1241
|
-
|
|
1242
|
-
const sceneList = {};
|
|
1243
|
-
this.basicRoomScenes.forEach(sceneId => {
|
|
1244
|
-
const sceneStateId = zoneBaseId + '.scenes.' + this.convertSceneName(dssConstants.zoneSceneCommands[sceneId]);
|
|
1245
|
-
sceneList[sceneId] = dssConstants.zoneSceneCommands[sceneId];
|
|
1246
|
-
|
|
1247
|
-
this.addStateObject(sceneStateId, zone.id + '.0.scenes.' + sceneId, {
|
|
1248
|
-
name: 'Zone ' + zone.id + ' ' + dssConstants.zoneSceneCommands[sceneId],
|
|
1249
|
-
type: 'boolean',
|
|
1250
|
-
role: 'switch'
|
|
1251
|
-
}, value => {
|
|
1252
|
-
value = !!value;
|
|
1253
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1254
|
-
dssClass: 'zone',
|
|
1255
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1256
|
-
params: {
|
|
1257
|
-
id: zone.id,
|
|
1258
|
-
sceneNumber: sceneId
|
|
1259
|
-
}
|
|
1260
|
-
}, 'high', (err, res) => {
|
|
1261
|
-
if (err || (res && !res.ok)) {
|
|
1262
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for zone ' + zone.id + ': ' + (err || JSON.stringify(res)));
|
|
1263
|
-
}
|
|
1264
|
-
});
|
|
1265
|
-
});
|
|
1266
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1267
|
-
});
|
|
1268
|
-
for (let sceneId = 67; sceneId <= 70; sceneId++) {
|
|
1269
|
-
const sceneStateId = zoneBaseId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[sceneId]);
|
|
1270
|
-
sceneList[sceneId] = dssConstants.apartmentScenes[sceneId];
|
|
1271
|
-
|
|
1272
|
-
this.addStateObject(sceneStateId, zone.id + '.0.scenes.' + sceneId, {
|
|
1273
|
-
name: 'Zone ' + zone.id + ' ' + dssConstants.apartmentScenes[sceneId],
|
|
1274
|
-
type: 'boolean',
|
|
1275
|
-
role: 'switch'
|
|
1276
|
-
}, value => {
|
|
1277
|
-
value = !!value;
|
|
1278
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1279
|
-
dssClass: 'zone',
|
|
1280
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1281
|
-
params: {
|
|
1282
|
-
id: zone.id,
|
|
1283
|
-
sceneNumber: sceneId
|
|
1284
|
-
}
|
|
1285
|
-
}, 'high', (err, res) => {
|
|
1286
|
-
if (err || (res && !res.ok)) {
|
|
1287
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for zone ' + zone.id + ': ' + (err || JSON.stringify(res)));
|
|
1288
|
-
}
|
|
1289
|
-
});
|
|
1290
|
-
});
|
|
1291
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1292
|
-
}
|
|
1293
|
-
if (Object.keys(sceneList).length) {
|
|
1294
|
-
this.addStateObject(zoneBaseId + '.scenes.sceneId', {
|
|
1295
|
-
name: 'Scene ID',
|
|
1296
|
-
type: 'number',
|
|
1297
|
-
role: 'value',
|
|
1298
|
-
states: sceneList
|
|
1299
|
-
},value => {
|
|
1300
|
-
if (!sceneList[value]) {
|
|
1301
|
-
this.adapter.log.warn('Invalid Scene ID ' + value + ' for Zone ' + zone.id + '.scenes.sceneId');
|
|
1302
|
-
return;
|
|
1303
|
-
}
|
|
1304
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1305
|
-
dssClass: 'zone',
|
|
1306
|
-
dssFunction: 'callScene',
|
|
1307
|
-
params: {
|
|
1308
|
-
id: zone.id,
|
|
1309
|
-
sceneNumber: value
|
|
1310
|
-
}
|
|
1311
|
-
}, 'high', (err, res) => {
|
|
1312
|
-
if (err || (res && !res.ok)) {
|
|
1313
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for Zone ' + zone.id + ': ' + (err || JSON.stringify(res)));
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
});
|
|
1317
|
-
|
|
1318
|
-
groupCounter++;
|
|
1319
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1320
|
-
dssClass: 'zone',
|
|
1321
|
-
dssFunction: 'getLastCalledScene',
|
|
1322
|
-
params: {
|
|
1323
|
-
id: zone.id
|
|
1324
|
-
}
|
|
1325
|
-
}, 'high', (err, res) => {
|
|
1326
|
-
if (err || (res && !res.ok) || !res.result || res.result.scene === undefined) {
|
|
1327
|
-
this.adapter.log.warn('Error while getLastCalledScene for zone ' + zone.id + ': ' + (err || JSON.stringify(res)));
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
this.initialObjectValues[zoneBaseId + '.scenes.sceneId'] = res.result.scene;
|
|
1331
|
-
this.initialScenes[zone.id + '.0'] = res.result.scene;
|
|
1332
|
-
const sceneStateId = zoneBaseId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[res.result.scene]);
|
|
1333
|
-
if (this.dssObjects[sceneStateId]) {
|
|
1334
|
-
this.initialObjectValues[sceneStateId] = true;
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
!--groupCounter && callback && callback(null);
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
this.addFolderObject(zoneBaseId + '.sensors', (zone.name || 'Zone ' + zone.id) + ' Sensors', 'channel');
|
|
1342
|
-
|
|
1343
|
-
//sensorValues.values = sensorValues.values || [];
|
|
1344
|
-
if (temperatureControlStatus) {
|
|
1345
|
-
sensorValues.values.push(temperatureControlStatus);
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
sensorValues = sensorValues || {};
|
|
1349
|
-
sensorValues.values = sensorValues.values || [];
|
|
1350
|
-
Object.keys(dssConstants.sensorValuesRoleMapZone).forEach(sensorValueName => {
|
|
1351
|
-
const sensor = sensorValues.values.find(val => val[sensorValueName] !== undefined) || {};
|
|
1352
|
-
|
|
1353
|
-
this.addStateObject( zoneBaseId + '.sensors.' + sensorValueName, zone.id + '.sensors.' + dssConstants.sensorValuesRoleMapZone[sensorValueName].native.sensorType, dssConstants.sensorValuesRoleMapZone[sensorValueName], value => {
|
|
1354
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1355
|
-
dssClass: 'zone',
|
|
1356
|
-
dssFunction: 'pushSensorValue',
|
|
1357
|
-
params: {
|
|
1358
|
-
id: zone.id,
|
|
1359
|
-
groupID: 0,
|
|
1360
|
-
sensorType: dssConstants.sensorValuesRoleMapZone[sensorValueName].native.sensorType,
|
|
1361
|
-
sensorValue: value
|
|
1362
|
-
}
|
|
1363
|
-
}, 'high', (err, res) => {
|
|
1364
|
-
if (err || (res && !res.ok)) {
|
|
1365
|
-
this.adapter.log.warn('Error while pushSensorValue for zone: ' + (err || JSON.stringify(res)));
|
|
1366
|
-
}
|
|
1367
|
-
});
|
|
1368
|
-
});
|
|
1369
|
-
if (sensor) {
|
|
1370
|
-
this.initialObjectValues[zoneBaseId + '.sensors.' + sensorValueName] = sensor[sensorValueName];
|
|
1371
|
-
}
|
|
1372
|
-
});
|
|
1373
|
-
|
|
1374
|
-
!groupCounter && callback && setImmediate(() => callback(null));
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
processGroup(groupBaseId, zoneId, group, callback) {
|
|
1378
|
-
if (!group.isPresent || !group.isValid) {
|
|
1379
|
-
return callback && setImmediate(callback, null);
|
|
1380
|
-
}
|
|
1381
|
-
this.dss.requestAsync('zone', 'getReachableScenes' , {id: zoneId, groupID: group.id}).then((reachableScenes) => {
|
|
1382
|
-
this.adapter.log.debug('getReachableScenes ' + zoneId + '-' + group.id + ': ' + JSON.stringify(reachableScenes));
|
|
1383
|
-
|
|
1384
|
-
this.addFolderObject(groupBaseId, group.name || 'Group ' + group.id);
|
|
1385
|
-
this.addFolderObject(groupBaseId + '.scenes', (group.name || 'Group ' + group.id) + ' Scenes', 'channel');
|
|
1386
|
-
|
|
1387
|
-
const sceneList = {};
|
|
1388
|
-
const scenesToProcess = reachableScenes.result.reachableScenes || [];
|
|
1389
|
-
this.basicRoomScenes.forEach(sceneId => scenesToProcess.push(sceneId)); // enhance
|
|
1390
|
-
if (scenesToProcess.length) {
|
|
1391
|
-
const userNames = this.convertObject(reachableScenes.result.userSceneNames, 'sceneNr');
|
|
1392
|
-
if (scenesToProcess.includes(0)) {
|
|
1393
|
-
scenesToProcess.push(40); // Add Auto-Off if we support off
|
|
1394
|
-
}
|
|
1395
|
-
scenesToProcess.forEach(sceneId => {
|
|
1396
|
-
let sceneStateId;
|
|
1397
|
-
let sceneName;
|
|
1398
|
-
if (zoneId === 0) {
|
|
1399
|
-
if (!dssConstants.apartmentScenes[sceneId] && !dssConstants.zoneSceneCommands[sceneId]) {
|
|
1400
|
-
this.adapter.log.warn('IGNORE INVALID SCENEID ' + sceneId);
|
|
1401
|
-
return;
|
|
1402
|
-
}
|
|
1403
|
-
sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[sceneId] || dssConstants.zoneSceneCommands[sceneId]);
|
|
1404
|
-
sceneName = dssConstants.apartmentScenes[sceneId] || dssConstants.zoneSceneCommands[sceneId];
|
|
1405
|
-
} else {
|
|
1406
|
-
if (!dssConstants.zoneSceneCommands[sceneId]) {
|
|
1407
|
-
this.adapter.log.warn('IGNORE INVALID SCENEID ' + sceneId);
|
|
1408
|
-
return;
|
|
1409
|
-
}
|
|
1410
|
-
sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.zoneSceneCommands[sceneId]);
|
|
1411
|
-
sceneName = (userNames[sceneId] && userNames[sceneId].sceneName) ? userNames[sceneId].sceneName : dssConstants.zoneSceneCommands[sceneId];
|
|
1412
|
-
}
|
|
1413
|
-
sceneList[sceneId] = sceneName;
|
|
1414
|
-
|
|
1415
|
-
this.addStateObject(sceneStateId, zoneId + '.' + group.id + '.scenes.' + sceneId, {
|
|
1416
|
-
name: 'Group ' + group.id + ' ' + sceneName,
|
|
1417
|
-
type: 'boolean',
|
|
1418
|
-
role: 'switch'
|
|
1419
|
-
},value => {
|
|
1420
|
-
value = !!value;
|
|
1421
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1422
|
-
dssClass: 'zone',
|
|
1423
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1424
|
-
params: {
|
|
1425
|
-
sceneNumber: sceneId,
|
|
1426
|
-
groupID: group.id,
|
|
1427
|
-
id: zoneId
|
|
1428
|
-
}
|
|
1429
|
-
}, 'high', (err, res) => {
|
|
1430
|
-
if (err || (res && !res.ok)) {
|
|
1431
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for group: ' + (err || JSON.stringify(res)));
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
});
|
|
1435
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1436
|
-
});
|
|
1437
|
-
for (let sceneId = 67; sceneId <= 70; sceneId++) {
|
|
1438
|
-
const sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[sceneId]);
|
|
1439
|
-
sceneList[sceneId] = dssConstants.apartmentScenes[sceneId];
|
|
1440
|
-
|
|
1441
|
-
this.addStateObject(sceneStateId, zoneId + '.' + group.id + '.scenes.' + sceneId, {
|
|
1442
|
-
name: 'Group ' + group.id + ' ' + dssConstants.apartmentScenes[sceneId],
|
|
1443
|
-
type: 'boolean',
|
|
1444
|
-
role: 'switch'
|
|
1445
|
-
}, value => {
|
|
1446
|
-
value = !!value;
|
|
1447
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1448
|
-
dssClass: 'zone',
|
|
1449
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1450
|
-
params: {
|
|
1451
|
-
id: zoneId,
|
|
1452
|
-
groupID: group.id,
|
|
1453
|
-
sceneNumber: sceneId
|
|
1454
|
-
}
|
|
1455
|
-
}, 'high', (err, res) => {
|
|
1456
|
-
if (err || (res && !res.ok)) {
|
|
1457
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for group: ' + (err || JSON.stringify(res)));
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
});
|
|
1461
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
if (group.id === 48 && zoneId !== 0) {
|
|
1465
|
-
Object.keys(dssConstants.temperatureControlScenes).forEach(sceneId => {
|
|
1466
|
-
const sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.temperatureControlScenes[sceneId]);
|
|
1467
|
-
const sceneName = dssConstants.temperatureControlScenes[sceneId];
|
|
1468
|
-
sceneList[sceneId] = sceneName;
|
|
1469
|
-
|
|
1470
|
-
this.addStateObject(sceneStateId, zoneId + '.' + group.id + '.scenes.' + sceneId, {
|
|
1471
|
-
name: 'Group ' + group.id + ' ' + sceneName,
|
|
1472
|
-
type: 'boolean',
|
|
1473
|
-
role: 'switch'
|
|
1474
|
-
}, value => {
|
|
1475
|
-
value = !!value;
|
|
1476
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1477
|
-
dssClass: 'zone',
|
|
1478
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1479
|
-
params: {
|
|
1480
|
-
sceneNumber: sceneId,
|
|
1481
|
-
groupID: group.id,
|
|
1482
|
-
id: zoneId
|
|
1483
|
-
}
|
|
1484
|
-
}, 'high', (err, res) => {
|
|
1485
|
-
if (err || (res && !res.ok)) {
|
|
1486
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for group: ' + (err || JSON.stringify(res)));
|
|
1487
|
-
}
|
|
1488
|
-
});
|
|
1489
|
-
});
|
|
1490
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1491
|
-
});
|
|
1492
|
-
}
|
|
1493
|
-
if ((group.id === 10 || group.id === 64) && zoneId !== 0) {
|
|
1494
|
-
Object.keys(dssConstants.ventilationControlScenes).forEach(sceneId => {
|
|
1495
|
-
const sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.ventilationControlScenes[sceneId]);
|
|
1496
|
-
const sceneName = dssConstants.ventilationControlScenes[sceneId];
|
|
1497
|
-
sceneList[sceneId] = sceneName;
|
|
1498
|
-
|
|
1499
|
-
this.addStateObject(sceneStateId, zoneId + '.' + group.id + '.scenes.' + sceneId, {
|
|
1500
|
-
name: 'Group ' + group.id + ' ' + sceneName,
|
|
1501
|
-
type: 'boolean',
|
|
1502
|
-
role: 'switch'
|
|
1503
|
-
}, value => {
|
|
1504
|
-
value = !!value;
|
|
1505
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1506
|
-
dssClass: 'zone',
|
|
1507
|
-
dssFunction: value ? 'callScene' : 'undoScene',
|
|
1508
|
-
params: {
|
|
1509
|
-
sceneNumber: sceneId,
|
|
1510
|
-
groupID: group.id,
|
|
1511
|
-
id: zoneId
|
|
1512
|
-
}
|
|
1513
|
-
}, 'high', (err, res) => {
|
|
1514
|
-
if (err || (res && !res.ok)) {
|
|
1515
|
-
this.adapter.log.warn('Error while ' + (value ? 'callScene' : 'undoScene') + ' for group: ' + (err || JSON.stringify(res)));
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
});
|
|
1519
|
-
this.initialObjectValues[sceneStateId] = false;
|
|
1520
|
-
});
|
|
1521
|
-
}
|
|
1522
|
-
if (Object.keys(sceneList).length) {
|
|
1523
|
-
this.addStateObject(groupBaseId + '.scenes.sceneId', {
|
|
1524
|
-
name: 'Group Scene ID',
|
|
1525
|
-
type: 'number',
|
|
1526
|
-
role: 'value',
|
|
1527
|
-
states: sceneList
|
|
1528
|
-
},value => {
|
|
1529
|
-
if (!sceneList[value]) {
|
|
1530
|
-
this.adapter.log.warn('Invalid Scene ID ' + value + ' for ' + groupBaseId + '.scenes.sceneId');
|
|
1531
|
-
return;
|
|
1532
|
-
}
|
|
1533
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1534
|
-
dssClass: 'zone',
|
|
1535
|
-
dssFunction: 'callScene',
|
|
1536
|
-
params: {
|
|
1537
|
-
sceneNumber: value,
|
|
1538
|
-
groupID: group.id,
|
|
1539
|
-
id: zoneId
|
|
1540
|
-
}
|
|
1541
|
-
}, 'high', (err, res) => {
|
|
1542
|
-
if (err || (res && !res.ok)) {
|
|
1543
|
-
this.adapter.log.warn('Error while callScene for ' + groupBaseId + '.scenes.sceneId: ' + (err || JSON.stringify(res)));
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
});
|
|
1547
|
-
|
|
1548
|
-
this.dssQueue.pushQueryQueue('zone', {
|
|
1549
|
-
dssClass: 'zone',
|
|
1550
|
-
dssFunction: 'getLastCalledScene',
|
|
1551
|
-
params: {
|
|
1552
|
-
id: zoneId,
|
|
1553
|
-
groupID: group.id
|
|
1554
|
-
}
|
|
1555
|
-
}, 'high', (err, res) => {
|
|
1556
|
-
if (err || (res && !res.ok) || !res.result || res.result.scene === undefined) {
|
|
1557
|
-
this.adapter.log.warn('Error while getLastCalledScene for group ' + zoneId + '.' + group.id + ': ' + (err || JSON.stringify(res)));
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
this.initialObjectValues[groupBaseId + '.scenes.sceneId'] = res.result.scene;
|
|
1561
|
-
this.initialScenes[zoneId + '.' + group.id] = res.result.scene;
|
|
1562
|
-
const sceneStateId = groupBaseId + '.scenes.' + this.convertSceneName(dssConstants.apartmentScenes[res.result.scene] || dssConstants.zoneSceneCommands[res.result.scene]);
|
|
1563
|
-
if (this.dssObjects[sceneStateId]) {
|
|
1564
|
-
this.initialObjectValues[sceneStateId] = true;
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
callback && callback(null);
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
const groupStates = this.findStates('^zone\\.' + zoneId + '\\.group\\.' + group.id + '\\.([^.]*)$');
|
|
1572
|
-
if (groupStates && groupStates.length) {
|
|
1573
|
-
this.addFolderObject(groupBaseId + '.states', (group.name || 'Group ' + group.id) + ' Scenes', 'channel');
|
|
1574
|
-
|
|
1575
|
-
groupStates.forEach(state => {
|
|
1576
|
-
if (!state.matchedName) return;
|
|
1577
|
-
const stateId = groupBaseId + '.states.' + state.matchedName;
|
|
1578
|
-
this.addStateObject(stateId, state.name, {
|
|
1579
|
-
name: state.matchedName,
|
|
1580
|
-
role: 'indicator',
|
|
1581
|
-
type: 'boolean',
|
|
1582
|
-
read: true,
|
|
1583
|
-
write: false,
|
|
1584
|
-
native: {}
|
|
1585
|
-
}, value => {
|
|
1586
|
-
value = !!value;
|
|
1587
|
-
if (!this.dssObjects[stateId] || !this.dssObjects[stateId].native) return;
|
|
1588
|
-
this.dssQueue.pushQueryQueue('group', {
|
|
1589
|
-
dssClass: 'state',
|
|
1590
|
-
dssFunction: 'set',
|
|
1591
|
-
params: {
|
|
1592
|
-
name: state.name,
|
|
1593
|
-
value: value ? this.dssObjects[stateId].native.valueTrue : this.dssObjects[stateId].native.valueFalse
|
|
1594
|
-
}
|
|
1595
|
-
}, 'high', (err, res) => {
|
|
1596
|
-
if (err || (res && !res.ok)) {
|
|
1597
|
-
this.adapter.log.warn('Error while set State for group: ' + (err || JSON.stringify(res)));
|
|
1598
|
-
}
|
|
1599
|
-
});
|
|
1600
|
-
});
|
|
1601
|
-
this.initialObjectValues[stateId] = state.state;
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
!Object.keys(sceneList).length && callback && callback(null);
|
|
1606
|
-
}, (err) => {
|
|
1607
|
-
this.adapter.log.warn('Err getReachableScenes:' + JSON.stringify(err));
|
|
1608
|
-
callback && callback(err);
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
addFolderObject(id, name, type) {
|
|
1613
|
-
const obj ={
|
|
1614
|
-
type: type || 'folder',
|
|
1615
|
-
common: {
|
|
1616
|
-
name
|
|
1617
|
-
}
|
|
1618
|
-
};
|
|
1619
|
-
this.dssObjects[id] = obj;
|
|
1620
|
-
|
|
1621
|
-
const idLength = id.replace(/[^.]/g, '').length;
|
|
1622
|
-
const spacesStr = ' ';
|
|
1623
|
-
this.adapter.log.debug(spacesStr.substr(0, idLength * 2) + 'CREATE ' + obj.type + ' ' + id + ' WITH ' + JSON.stringify(obj));
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
addStateObject(id, dssId, objData, value, onChange) {
|
|
1627
|
-
if (typeof dssId === 'object') {
|
|
1628
|
-
onChange = value;
|
|
1629
|
-
value = objData;
|
|
1630
|
-
objData = dssId;
|
|
1631
|
-
dssId = null;
|
|
1632
|
-
}
|
|
1633
|
-
if (typeof value === 'function') {
|
|
1634
|
-
onChange = value;
|
|
1635
|
-
value = undefined;
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
objData = JSON.parse(JSON.stringify(objData));
|
|
1639
|
-
let native = {};
|
|
1640
|
-
if (objData.native) {
|
|
1641
|
-
native = objData.native;
|
|
1642
|
-
delete objData.native;
|
|
1643
|
-
}
|
|
1644
|
-
const obj = {
|
|
1645
|
-
type: 'state',
|
|
1646
|
-
common: objData,
|
|
1647
|
-
native,
|
|
1648
|
-
value,
|
|
1649
|
-
onChange
|
|
1650
|
-
};
|
|
1651
|
-
this.dssObjects[id] = obj;
|
|
1652
|
-
if (dssId) {
|
|
1653
|
-
this.stateMap[dssId] = id;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
const idLength = id.replace(/[^.]/g, '').length;
|
|
1657
|
-
const spacesStr = ' ';
|
|
1658
|
-
this.adapter.log.debug(spacesStr.substr(0, idLength * 2) + 'CREATE state ' + id + ' value = ' + value + ' WITH ' + JSON.stringify(obj));
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
module.exports = DSSStructure;
|