forked from Black-Thunder/ioBroker.melcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
626 lines (554 loc) · 24.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
"use strict";
/*
* Created with @iobroker/create-adapter v1.24.1
*/
// The adapter-core module gives you access to the core ioBroker functions
const utils = require("@iobroker/adapter-core");
// Needed modules
const cloudPlatform = require("./lib/melcloudPlatform");
const commonDefines = require("./lib/commonDefines");
let gthis = null; // global to 'this' of Melcloud main instance
let CloudPlatform = null;
const stateValueCache = {}; // used to store all adapter state values to check for unchanged values
class Melcloud extends utils.Adapter {
/**
* @param {Partial<ioBroker.AdapterOptions>} [options={}]
*/
constructor(options) {
// @ts-ignore
super({
...options,
name: "melcloud",
});
this.on("ready", this.onReady.bind(this));
this.on("stateChange", this.onStateChange.bind(this));
this.on("unload", this.onUnload.bind(this));
gthis = this;
this.deviceObjects = []; // array of all device objects
this.currentKnownDeviceIDs = []; // array of all current known device IDs
}
async checkSettings() {
this.log.debug("Checking adapter settings...");
if (this.config.melCloudEmail == null || this.config.melCloudEmail == "") {
throw new Error("MELCloud username empty! Check settings.");
}
if (this.config.melCloudPassword == null || this.config.melCloudPassword == "") {
throw new Error("MELCloud password empty! Check settings.");
}
// Minimum pollingInterval = 5 to prevent rate limiting
if (this.config.pollingInterval < 5) {
this.config.pollingInterval = 5;
this.log.warn("Polling interval can't be set lower than 5 minutes to avoid being throttled by the MELCloud servers. Now set to 5 minutes.");
}
if (this.config.ignoreSslErrors) {
this.log.info("SSL errors are ignored when communicating with the cloud. This is potentially insecure!");
}
}
async setAdapterConnectionState(isConnected) {
await this.setStateChangedAsync(`${commonDefines.AdapterDatapointIDs.Info}.${commonDefines.AdapterStateIDs.Connection}`, isConnected, true);
await this.setForeignState(`system.adapter.${this.namespace}.connected`, isConnected, true);
}
async saveKnownDeviceIDs() {
this.log.debug("Getting current known devices...");
const prefix = `${this.namespace}.${commonDefines.AdapterDatapointIDs.Devices}.`;
const objects = await this.getAdapterObjectsAsync();
for (const id of Object.keys(objects)) {
if (!id.startsWith(prefix)) {
continue;
}
const deviceIdTemp = id.replace(prefix, "");
const deviceId = parseInt(deviceIdTemp.substring(0, deviceIdTemp.lastIndexOf(".")), 10);
// Add each device only one time
if (!isNaN(deviceId) && !this.currentKnownDeviceIDs.includes(deviceId)) {
this.currentKnownDeviceIDs.push(deviceId);
this.log.debug(`Found known device: ${deviceId}`);
}
}
if (this.currentKnownDeviceIDs.length == 0) {
this.log.debug("No known devices found.");
}
}
async deleteMelDevice(id) {
const prefix = `${this.namespace}.${commonDefines.AdapterDatapointIDs.Devices}.${id}`;
const objects = await this.getAdapterObjectsAsync();
for (const id of Object.keys(objects)) {
if (id.startsWith(prefix)) {
const objID = id.replace(`${this.namespace}.`, "");
this.log.debug(`Deleting state '${objID}'`);
await this.delObjectAsync(objID);
}
}
}
async initObjects() {
this.log.debug("Initializing objects...");
await this.setObjectNotExistsAsync(commonDefines.AdapterDatapointIDs.Devices, {
type: "folder",
common: {
name: "Devices",
},
native: {},
});
//#region INFO
await this.setObjectNotExistsAsync(commonDefines.AdapterDatapointIDs.Info, {
type: "channel",
common: {
name: "Adapter information"
},
native: {}
});
await this.setObjectNotExistsAsync(`${commonDefines.AdapterDatapointIDs.Info}.${commonDefines.AdapterStateIDs.Connection}`, {
type: "state",
common: {
name: "Connection to cloud",
type: "boolean",
role: "indicator.connected",
read: true,
write: false,
def: false,
desc: "Indicates if connection to MELCloud was successful or not"
},
native: {}
});
this.setAdapterConnectionState(false);
//#endregion
//#region REPORTS (cumulated for all supported devices)
let reportsPrefix = `${commonDefines.AdapterDatapointIDs.Reports}`;
await this.setObjectNotExistsAsync(reportsPrefix, {
type: "channel",
common: {
name: "Cumulated report for all supported devices"
},
native: {}
});
reportsPrefix += ".";
await this.setObjectNotExistsAsync(reportsPrefix + commonDefines.CommonDeviceStateIDs.PowerConsumptionReportStartDate, {
type: "state",
common: {
name: "Report start date (format: YYYY-MM-DD)",
type: "string",
role: "date",
read: true,
write: true,
desc: "Report data will be collected starting at this date"
},
native: {}
});
await this.setObjectNotExistsAsync(reportsPrefix + commonDefines.CommonDeviceStateIDs.PowerConsumptionReportEndDate, {
type: "state",
common: {
name: "Report end date (format: YYYY-MM-DD)",
type: "string",
role: "date",
read: true,
write: true,
desc: "Report data will be collected until this date"
},
native: {}
});
await this.setObjectNotExistsAsync(reportsPrefix + commonDefines.CommonDeviceStateIDs.GetCumulatedPowerConsumptionReport, {
type: "state",
common: {
name: "Get current power consumption report for all supported devices",
type: "boolean",
role: "button",
read: false,
write: true,
def: false,
desc: "Get current power consumption report for all supported devices"
},
native: {}
});
let lastReportDataPrefix = `${commonDefines.AdapterDatapointIDs.Reports}.${commonDefines.AdapterDatapointIDs.LastReportData}`;
await this.setObjectNotExistsAsync(lastReportDataPrefix, {
type: "channel",
common: {
name: "Last report data for all supported devices"
},
native: {}
});
lastReportDataPrefix += ".";
const reportModes = [commonDefines.AtaDeviceOperationModes.HEAT.id, commonDefines.AtaDeviceOperationModes.COOL.id, commonDefines.AtaDeviceOperationModes.AUTO.id, commonDefines.AtaDeviceOperationModes.VENT.id, commonDefines.AtaDeviceOperationModes.DRY.id, "HotWater"];
reportModes.forEach(mode => {
this.setObjectNotExistsAsync(lastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + mode, {
type: "state",
common: {
name: `Total power consumption for mode '${mode}'`,
type: "number",
role: "value.power.consumption",
min: 0,
read: true,
write: false,
unit: "kWh",
def: 0,
desc: `Total power consumption for mode '${mode}'`
},
native: {}
});
if (mode == commonDefines.AtaDeviceOperationModes.AUTO.id || mode == commonDefines.AtaDeviceOperationModes.DRY.id || mode == commonDefines.AtaDeviceOperationModes.VENT.id) return;
this.setObjectNotExistsAsync(lastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerProductionPrefix + mode, {
type: "state",
common: {
name: `Total power production for mode '${mode}'`,
type: "number",
role: "value.power.consumption",
min: 0,
read: true,
write: false,
unit: "kWh",
def: 0,
desc: `Total power production for mode '${mode}'`
},
native: {}
});
});
await this.setObjectNotExistsAsync(lastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix, {
type: "state",
common: {
name: "Total power consumption for all modes",
type: "number",
role: "value.power.consumption",
min: 0,
read: true,
write: false,
unit: "kWh",
def: 0,
desc: "Total power consumption for all modes"
},
native: {}
});
await this.setObjectNotExistsAsync(lastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerProductionPrefix, {
type: "state",
common: {
name: "Total power production for all modes",
type: "number",
role: "value.power.consumption",
min: 0,
read: true,
write: false,
unit: "kWh",
def: 0,
desc: "Total power production for all modes"
},
native: {}
});
await this.setObjectNotExistsAsync(lastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalReportedMinutes, {
type: "state",
common: {
name: "Total power consumption minutes",
type: "number",
role: "value",
min: 0,
read: true,
write: false,
unit: "min",
def: 0,
desc: "Total operation time"
},
native: {}
});
//#endregion
}
/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
this.initObjects()
.then(() => this.checkSettings()
.then(() => this.saveKnownDeviceIDs()
.then(() => {
this.connectToCloud();
this.subscribeStates("devices.*.control.*"); // subscribe to states changes under "devices.X.control."
this.subscribeStates("devices.*.reports.getPowerConsumptionReport"); // subscribe to state "devices.X.reports.getPowerConsumptionReport"
this.subscribeStates("reports.getCumulatedPowerConsumptionReport"); // subscribe to state "reports.getCumulatedPowerConsumptionReport"
})
)
)
.catch(err => this.log.error(err));
}
async connectToCloud() {
gthis.log.info(`Connecting initially to MELCloud and retrieving device data. Polling is ${this.config.enablePolling ? `enabled (interval: ${this.config.pollingInterval} minutes)` : "disabled"}.`);
// Connect to cloud and retrieve/update registered devices initially
CloudPlatform = new cloudPlatform.MelCloudPlatform(gthis);
if (this.config.enablePolling) {
CloudPlatform.GetContextKey(CloudPlatform.CreateAndSaveDevices, CloudPlatform.startPolling);
}
else {
CloudPlatform.GetContextKey(CloudPlatform.CreateAndSaveDevices);
}
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
*/
onUnload(callback) {
try {
this.setAdapterConnectionState(false);
this.deviceObjects.length = 0;
if (CloudPlatform != null) {
CloudPlatform.stopPolling();
CloudPlatform.stopContextKeyInvalidation();
}
this.log.debug("onUnload(): Cleaned everything up...");
callback();
// eslint-disable-next-line no-unused-vars
} catch (e) {
callback();
}
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
onStateChange(id, state) {
// The state was changed
if (state) {
// always trigger on "getPowerConsumptionReport" and "getCumulatedPowerConsumptionReport" ignoring if the value has changed or not
if (!id.includes(commonDefines.CommonDeviceStateIDs.GetPowerConsumptionReport) && !id.includes(commonDefines.CommonDeviceStateIDs.GetCumulatedPowerConsumptionReport)
&& stateValueCache[id] != undefined && stateValueCache[id] != null && stateValueCache[id] == state.val) {
this.log.silly(`state ${id} unchanged: ${state.val} (ack = ${state.ack})`);
return;
}
stateValueCache[id] = state.val;
this.log.silly(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
// ack is true when state was updated by MELCloud --> in this case, we don't need to send it again
if (state.ack) {
this.log.silly("Updated data was retrieved from MELCloud. No need to process changed data.");
return;
}
if (this.deviceObjects.length == 0) {
this.log.error("No objects for MELCloud devices constructed yet. Try again in a few seconds...");
return;
}
// "reports.getCumulatedPowerConsumptionReport"
if (id.includes(commonDefines.CommonDeviceStateIDs.GetCumulatedPowerConsumptionReport)) {
this.log.debug(`Processing command '${commonDefines.CommonDeviceStateIDs.GetCumulatedPowerConsumptionReport}' with value '${state.val}' for all devices...`);
this.GetCumulatedReport();
}
// "devices.XXX.control.*" and "devices.XXX.reports.getPowerConsumptionReport"
else {
let deviceId = id.replace(`${this.namespace}.${commonDefines.AdapterDatapointIDs.Devices}.`, "");
deviceId = deviceId.substring(0, deviceId.indexOf("."));
// Get the device object that should be changed
this.log.debug(`Trying to get device object with id ${deviceId}...`);
const device = this.deviceObjects.find(obj => {
return obj.id === parseInt(deviceId);
});
if (device == null) {
let knownIds = "";
this.deviceObjects.forEach(obj => knownIds += `${obj.id}, `);
this.log.error(`Failed to get device object. Known object IDs: ${knownIds}`);
this.log.error("This should not happen - report this to the developer!");
return;
}
const controlOption = id.substring(id.lastIndexOf(".") + 1, id.length);
this.log.debug(`Processing command '${controlOption}' with value '${state.val}' for device object with id ${device.id} (${device.name})...`);
const type = device.deviceType;
switch (type) {
case commonDefines.DeviceTypes.AirToAir: this.processAtaDeviceCommand(controlOption, state, device); break;
case commonDefines.DeviceTypes.AirToWater: this.processAtwDeviceCommand(controlOption, state, device); break;
default: this.log.error(`Unsupported device type: '${type}' - Please report this to the developer!`); break;
}
}
}
// The state was deleted
else {
this.log.silly(`state ${id} deleted`);
if (stateValueCache[id]) {
delete stateValueCache[id];
}
}
}
async GetCumulatedReport() {
const promises = [];
for (const obj of this.deviceObjects) {
promises.push(obj.getPowerConsumptionReport(true));
}
Promise.all(promises).then(() => {
this.UpdateCumulatedReportData(this.deviceObjects);
});
}
async UpdateCumulatedReportData(deviceObjs) {
const cumulatedLastReportDataPrefix = `${commonDefines.AdapterDatapointIDs.Reports}.${commonDefines.AdapterDatapointIDs.LastReportData}.`;
let totalConsumption = 0, totalConsumptionCool = 0, totalConsumptionHeat = 0, totalConsumptionDry = 0, totalConsumptionVent = 0, totalConsumptionAuto = 0, totalConsumptionMinutes = 0;
const aggregatedDeviceGroups = [];
for (const obj of deviceObjs) {
// Check if device is already part of aggregation group to exclude duplicated values
if (obj.linkedDevicesIncludedInArregateEnergyReport && obj.linkedDevicesIncludedInArregateEnergyReport != "") {
if (aggregatedDeviceGroups.length == 0) aggregatedDeviceGroups.push({ groupName: obj.linkedDevicesIncludedInArregateEnergyReport, alreadyProcessed: false });
let isKnownGroup = false;
for (let i = 0; i < aggregatedDeviceGroups.length; i++) {
const aggregatedGroup = aggregatedDeviceGroups[i];
if (aggregatedGroup.groupName.includes(obj.name) && !aggregatedGroup.alreadyProcessed) {
this.log.debug(`Device '${obj.name}' is part of the aggregated group '${aggregatedGroup.groupName}'. Excluding the other devices from this group for cumulated reports.`);
totalConsumptionCool += obj.totalPowerConsumptionCooling;
totalConsumptionHeat += obj.totalPowerConsumptionHeating;
totalConsumptionAuto += obj.totalPowerConsumptionAuto;
totalConsumptionDry += obj.totalPowerConsumptionDry;
totalConsumptionVent += obj.totalPowerConsumptionVent;
totalConsumptionMinutes = obj.totalPowerConsumptionMinutes; // same for all devices
totalConsumption += totalConsumptionCool + totalConsumptionHeat + totalConsumptionAuto + totalConsumptionDry + totalConsumptionVent;
aggregatedGroup.alreadyProcessed = true;
isKnownGroup = true;
break;
}
}
if (!isKnownGroup) aggregatedDeviceGroups.push({ groupName: obj.linkedDevicesIncludedInArregateEnergyReport, alreadyProcessed: false });
}
// Device is not part of any aggregation group, just take thhe values as they are
else {
totalConsumptionCool += obj.totalPowerConsumptionCooling;
totalConsumptionHeat += obj.totalPowerConsumptionHeating;
totalConsumptionAuto += obj.totalPowerConsumptionAuto;
totalConsumptionDry += obj.totalPowerConsumptionDry;
totalConsumptionVent += obj.totalPowerConsumptionVent;
totalConsumptionMinutes += obj.totalPowerConsumptionMinutes;
totalConsumption += totalConsumptionCool + totalConsumptionHeat + totalConsumptionAuto + totalConsumptionDry + totalConsumptionVent;
}
}
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + commonDefines.AtaDeviceOperationModes.COOL.id, commonDefines.roundValue(totalConsumptionCool, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + commonDefines.AtaDeviceOperationModes.HEAT.id, commonDefines.roundValue(totalConsumptionHeat, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + commonDefines.AtaDeviceOperationModes.AUTO.id, commonDefines.roundValue(totalConsumptionAuto, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + commonDefines.AtaDeviceOperationModes.DRY.id, commonDefines.roundValue(totalConsumptionDry, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix + commonDefines.AtaDeviceOperationModes.VENT.id, commonDefines.roundValue(totalConsumptionVent, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalPowerConsumptionPrefix, commonDefines.roundValue(totalConsumption, 3), true);
await this.setStateChangedAsync(cumulatedLastReportDataPrefix + commonDefines.CommonDeviceStateIDs.TotalReportedMinutes, totalConsumptionMinutes, true);
this.log.debug(`Updated cumulated report data for all devices`);
}
mapAtaDeviceOperationMode(value) {
switch (value) {
case (commonDefines.AtaDeviceOperationModes.HEAT.value):
return commonDefines.AtaDeviceOperationModes.HEAT;
case (commonDefines.AtaDeviceOperationModes.DRY.value):
return commonDefines.AtaDeviceOperationModes.DRY;
case (commonDefines.AtaDeviceOperationModes.COOL.value):
return commonDefines.AtaDeviceOperationModes.COOL;
case (commonDefines.AtaDeviceOperationModes.VENT.value):
return commonDefines.AtaDeviceOperationModes.VENT;
case (commonDefines.AtaDeviceOperationModes.AUTO.value):
return commonDefines.AtaDeviceOperationModes.AUTO;
default:
this.log.error(`Unsupported ATA operation mode: '${value}' - Please report this to the developer!`);
return commonDefines.AtaDeviceOperationModes.UNDEF;
}
}
mapAtwDeviceZoneOperationMode(value) {
switch (value) {
case (commonDefines.AtwDeviceZoneOperationModes.HEATTHERMOSTAT.value):
return commonDefines.AtwDeviceZoneOperationModes.HEATTHERMOSTAT;
case (commonDefines.AtwDeviceZoneOperationModes.HEATFLOW.value):
return commonDefines.AtwDeviceZoneOperationModes.HEATFLOW;
case (commonDefines.AtwDeviceZoneOperationModes.CURVE.value):
return commonDefines.AtwDeviceZoneOperationModes.CURVE;
case (commonDefines.AtwDeviceZoneOperationModes.COOLTHERMOSTAT.value):
return commonDefines.AtwDeviceZoneOperationModes.COOLTHERMOSTAT;
case (commonDefines.AtwDeviceZoneOperationModes.COOLFLOW.value):
return commonDefines.AtwDeviceZoneOperationModes.COOLFLOW;
default:
this.log.error(`Unsupported ATW zone operation mode: '${value}' - Please report this to the developer!`);
return commonDefines.AtwDeviceZoneOperationModes.UNDEF;
}
}
processAtaDeviceCommand(controlOption, state, device) {
switch (controlOption) {
case (commonDefines.AtaDeviceStateIDs.Power):
if (state.val) {
// switch on using current operation mode
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.PowerState, commonDefines.DevicePowerStates.ON);
}
else {
// switch off
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.PowerState, commonDefines.DevicePowerStates.OFF);
}
break;
case (commonDefines.AtaDeviceStateIDs.Mode):
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.TargetHeatingCoolingState, this.mapAtaDeviceOperationMode(state.val));
break;
case (commonDefines.AtaDeviceStateIDs.TargetTemp):
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.TargetTemperature, state.val);
break;
case (commonDefines.AtaDeviceStateIDs.FanSpeedManual):
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.FanSpeed, state.val);
break;
case (commonDefines.AtaDeviceStateIDs.VaneVerticalDirection):
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.VaneVerticalDirection, state.val);
break;
case (commonDefines.AtaDeviceStateIDs.VaneHorizontalDirection):
device.getDeviceInfo(device.setDevice, commonDefines.AtaDeviceOptions.VaneHorizontalDirection, state.val);
break;
case (commonDefines.AtaDeviceStateIDs.TimerToogle):
device.toggleTimerState(state.val);
break;
case (commonDefines.CommonDeviceStateIDs.GetPowerConsumptionReport):
device.getPowerConsumptionReport();
break;
default:
this.log.error(`Unsupported ATA control option: ${controlOption} - Please report this to the developer!`);
break;
}
}
processAtwDeviceCommand(controlOption, state, device) {
switch (controlOption) {
case (commonDefines.AtwDeviceStateIDs.Power):
if (state.val) {
// switch on using current operation mode
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.PowerState, commonDefines.DevicePowerStates.ON);
}
else {
// switch off
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.PowerState, commonDefines.DevicePowerStates.OFF);
}
break;
case (commonDefines.AtwDeviceStateIDs.ForcedHotWaterMode):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.ForcedHotWaterMode, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.OperationModeZone1):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.OperationModeZone1, this.mapAtwDeviceZoneOperationMode(state.val));
break;
case (commonDefines.AtwDeviceStateIDs.OperationModeZone2):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.OperationModeZone2, this.mapAtwDeviceZoneOperationMode(state.val));
break;
case (commonDefines.AtwDeviceStateIDs.SetTankWaterTemperature):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetTankWaterTemperature, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetTemperatureZone1):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetTemperatureZone1, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetTemperatureZone2):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetTemperatureZone2, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetHeatFlowTemperatureZone1):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetHeatFlowTemperatureZone1, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetHeatFlowTemperatureZone2):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetHeatFlowTemperatureZone2, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetCoolFlowTemperatureZone1):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetCoolFlowTemperatureZone1, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.SetCoolFlowTemperatureZone2):
device.getDeviceInfo(device.setDevice, commonDefines.AtwDeviceOptions.SetCoolFlowTemperatureZone2, state.val);
break;
case (commonDefines.AtwDeviceStateIDs.TimerToogle):
device.toggleTimerState(state.val);
break;
case (commonDefines.CommonDeviceStateIDs.GetPowerConsumptionReport):
device.getPowerConsumptionReport();
break;
default:
this.log.error(`Unsupported ATW control option: ${controlOption} - Please report this to the developer!`);
break;
}
}
}
// @ts-ignore parent is a valid property on module
if (module.parent) {
// Export the constructor in compact mode
/**
* @param {Partial<ioBroker.AdapterOptions>} [options={}]
*/
module.exports = (options) => new Melcloud(options);
} else {
// otherwise start the instance directly
new Melcloud();
}