homebridge-melcloud-control 4.3.16-beta.3 → 4.3.16-beta.5
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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/deviceata.js +138 -79
- package/src/deviceatw.js +56 -60
- package/src/deviceerv.js +56 -61
- package/src/mqtt.js +5 -25
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
22
|
|
|
23
23
|
- Do not use Homebridge UI > v5.5.0 because of break config.json
|
|
24
24
|
|
|
25
|
+
# [4.3.16] - (09.12.2025)
|
|
26
|
+
|
|
27
|
+
## Changes
|
|
28
|
+
|
|
29
|
+
- stability and performance improvements
|
|
30
|
+
- moved MQTT to v5
|
|
31
|
+
- bump dependencies
|
|
32
|
+
- cleanup
|
|
33
|
+
|
|
25
34
|
# [4.3.11] - (07.12.2025)
|
|
26
35
|
|
|
27
36
|
## Changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.3.16-beta.
|
|
4
|
+
"version": "4.3.16-beta.5",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
package/src/deviceata.js
CHANGED
|
@@ -113,34 +113,31 @@ class DeviceAta extends EventEmitter {
|
|
|
113
113
|
const restFulEnabled = this.restFul.enable || false;
|
|
114
114
|
if (restFulEnabled) {
|
|
115
115
|
try {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
this.restFul1 = new RestFul({
|
|
117
|
+
port: this.restFul.port,
|
|
118
|
+
logWarn: this.logWarn,
|
|
119
|
+
logDebug: this.logDebug
|
|
120
|
+
})
|
|
121
|
+
.on('connected', (message) => {
|
|
122
|
+
this.restFulConnected = true;
|
|
123
|
+
this.emit('success', message);
|
|
122
124
|
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
-
.on('error', (error) => {
|
|
141
|
-
this.emit('error', error);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
125
|
+
.on('set', async (key, value) => {
|
|
126
|
+
try {
|
|
127
|
+
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
this.emit('warn', error);
|
|
130
|
+
};
|
|
131
|
+
})
|
|
132
|
+
.on('debug', (debug) => {
|
|
133
|
+
this.emit('debug', debug);
|
|
134
|
+
})
|
|
135
|
+
.on('warn', (warn) => {
|
|
136
|
+
this.emit('warn', warn);
|
|
137
|
+
})
|
|
138
|
+
.on('error', (error) => {
|
|
139
|
+
this.emit('error', error);
|
|
140
|
+
});
|
|
144
141
|
} catch (error) {
|
|
145
142
|
if (this.logWarn) this.emit('warn', `RESTFul integration start error: ${error}`);
|
|
146
143
|
};
|
|
@@ -150,41 +147,39 @@ class DeviceAta extends EventEmitter {
|
|
|
150
147
|
const mqttEnabled = this.mqtt.enable || false;
|
|
151
148
|
if (mqttEnabled) {
|
|
152
149
|
try {
|
|
153
|
-
|
|
154
|
-
this.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
150
|
+
this.mqtt1 = new Mqtt({
|
|
151
|
+
host: this.mqtt.host,
|
|
152
|
+
port: this.mqtt.port || 1883,
|
|
153
|
+
clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
|
|
154
|
+
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeString}/${this.deviceName}` : `melcloud/${this.deviceTypeString}/${this.deviceName}`,
|
|
155
|
+
user: this.mqtt.auth?.user,
|
|
156
|
+
passwd: this.mqtt.auth?.passwd,
|
|
157
|
+
logWarn: this.logWarn,
|
|
158
|
+
logDebug: this.logDebug
|
|
159
|
+
})
|
|
160
|
+
.on('connected', (message) => {
|
|
161
|
+
this.mqttConnected = true;
|
|
162
|
+
this.emit('success', message);
|
|
163
163
|
})
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.
|
|
182
|
-
|
|
183
|
-
})
|
|
184
|
-
.on('error', (error) => {
|
|
185
|
-
this.emit('error', error);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
164
|
+
.on('subscribed', (message) => {
|
|
165
|
+
this.emit('success', message);
|
|
166
|
+
})
|
|
167
|
+
.on('set', async (key, value) => {
|
|
168
|
+
try {
|
|
169
|
+
await this.setOverExternalIntegration('MQTT', this.deviceData, key, value);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
this.emit('warn', error);
|
|
172
|
+
};
|
|
173
|
+
})
|
|
174
|
+
.on('debug', (debug) => {
|
|
175
|
+
this.emit('debug', debug);
|
|
176
|
+
})
|
|
177
|
+
.on('warn', (warn) => {
|
|
178
|
+
this.emit('warn', warn);
|
|
179
|
+
})
|
|
180
|
+
.on('error', (error) => {
|
|
181
|
+
this.emit('error', error);
|
|
182
|
+
});
|
|
188
183
|
} catch (error) {
|
|
189
184
|
if (this.logWarn) this.emit('warn', `MQTT integration start error: ${error}`);
|
|
190
185
|
};
|
|
@@ -705,12 +700,12 @@ class DeviceAta extends EventEmitter {
|
|
|
705
700
|
if (this.frostProtectionSupport && this.accessory.frostProtectionEnabled !== null) {
|
|
706
701
|
//control
|
|
707
702
|
if (this.logDebug) this.emit('debug', `Prepare frost protection control service`);
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
703
|
+
const frostProtectionControlService = new Service.HeaterCooler(`${serviceName} Frost Protection`, `frostProtectionControlService${deviceId}`);
|
|
704
|
+
frostProtectionControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
705
|
+
frostProtectionControlService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Frost Protection`);
|
|
706
|
+
frostProtectionControlService.getCharacteristic(Characteristic.Active)
|
|
712
707
|
.onGet(async () => {
|
|
713
|
-
const state = this.accessory.
|
|
708
|
+
const state = this.accessory.frostProtection.Enabled;
|
|
714
709
|
return state;
|
|
715
710
|
})
|
|
716
711
|
.onSet(async (state) => {
|
|
@@ -722,7 +717,75 @@ class DeviceAta extends EventEmitter {
|
|
|
722
717
|
if (this.logWarn) this.emit('warn', `Set frost protection error: ${error}`);
|
|
723
718
|
};
|
|
724
719
|
});
|
|
725
|
-
|
|
720
|
+
frostProtectionControlService.getCharacteristic(Characteristic.CurrentHeaterCoolerState)
|
|
721
|
+
.onGet(async () => {
|
|
722
|
+
const value = this.accessory.frostProtection.Active ? 2 : 1;
|
|
723
|
+
return value;
|
|
724
|
+
})
|
|
725
|
+
frostProtectionControlService.getCharacteristic(Characteristic.TargetHeaterCoolerState)
|
|
726
|
+
.setProps({
|
|
727
|
+
minValue: 0,
|
|
728
|
+
maxValue: 0,
|
|
729
|
+
validValues: [0]
|
|
730
|
+
})
|
|
731
|
+
.onGet(async () => {
|
|
732
|
+
const value = 0
|
|
733
|
+
return value;
|
|
734
|
+
})
|
|
735
|
+
.onSet(async (value) => {
|
|
736
|
+
try {
|
|
737
|
+
deviceData.Device.FrostProtection.Enabled = true;
|
|
738
|
+
if (this.logInfo) this.emit('info', `Frost protection: Enabled`);
|
|
739
|
+
await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
|
|
740
|
+
} catch (error) {
|
|
741
|
+
if (this.logWarn) this.emit('warn', `Set operation mode error: ${error}`);
|
|
742
|
+
};
|
|
743
|
+
});
|
|
744
|
+
frostProtectionControlService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
745
|
+
.onGet(async () => {
|
|
746
|
+
const value = this.accessory.roomTemperature;
|
|
747
|
+
return value;
|
|
748
|
+
});
|
|
749
|
+
frostProtectionControlService.getCharacteristic(Characteristic.CoolingThresholdTemperature)
|
|
750
|
+
.setProps({
|
|
751
|
+
minValue: 4,
|
|
752
|
+
maxValue: 14,
|
|
753
|
+
minStep: 1
|
|
754
|
+
})
|
|
755
|
+
.onGet(async () => {
|
|
756
|
+
const value = this.accessory.frostProtection.Min;
|
|
757
|
+
return value;
|
|
758
|
+
})
|
|
759
|
+
.onSet(async (value) => {
|
|
760
|
+
try {
|
|
761
|
+
deviceData.FrostProtection.Min = value;
|
|
762
|
+
if (this.logInfo) this.emit('info', `Set frost protection min. temperature: ${value}${this.accessory.temperatureUnit}`);
|
|
763
|
+
await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (this.logWarn) this.emit('warn', `Set frost protection min. temperature error: ${error}`);
|
|
766
|
+
};
|
|
767
|
+
});
|
|
768
|
+
frostProtectionControlService.getCharacteristic(Characteristic.HeatingThresholdTemperature)
|
|
769
|
+
.setProps({
|
|
770
|
+
minValue: 6,
|
|
771
|
+
maxValue: 16,
|
|
772
|
+
minStep: 1
|
|
773
|
+
})
|
|
774
|
+
.onGet(async () => {
|
|
775
|
+
const value = this.accessory.frostProtection.Max;
|
|
776
|
+
return value;
|
|
777
|
+
})
|
|
778
|
+
.onSet(async (value) => {
|
|
779
|
+
try {
|
|
780
|
+
deviceData.FrostProtection.Max = value;
|
|
781
|
+
if (this.logInfo) this.emit('info', `Set frost protection max. temperature: ${value}${this.accessory.temperatureUnit}`);
|
|
782
|
+
await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
|
|
783
|
+
} catch (error) {
|
|
784
|
+
if (this.logWarn) this.emit('warn', `Set frost protection max. temperature error: ${error}`);
|
|
785
|
+
};
|
|
786
|
+
});
|
|
787
|
+
this.frostProtectionControlService = frostProtectionControlService;
|
|
788
|
+
accessory.addService(frostProtectionControlService);
|
|
726
789
|
|
|
727
790
|
if (this.logDebug) this.emit('debug', `Prepare frost protection control sensor service`);
|
|
728
791
|
this.frostProtectionControlSensorService = new Service.ContactSensor(`${serviceName} Frost Protection Control`, `frostProtectionControlSensorService${deviceId}`);
|
|
@@ -1374,10 +1437,12 @@ class DeviceAta extends EventEmitter {
|
|
|
1374
1437
|
const holidayModeActive = deviceData.HolidayMode?.Active ?? false;
|
|
1375
1438
|
|
|
1376
1439
|
//protection
|
|
1377
|
-
const
|
|
1378
|
-
const
|
|
1379
|
-
const
|
|
1380
|
-
const
|
|
1440
|
+
const frostProtection = deviceData.FrostProtection;
|
|
1441
|
+
const frostProtectionEnabled = frostProtection?.Enabled;
|
|
1442
|
+
const frostProtectionActive = frostProtection?.Active ?? false;
|
|
1443
|
+
const overheatProtection = deviceData.OverheatProtection;
|
|
1444
|
+
const overheatProtectionEnabled = overheatProtection?.Enabled;
|
|
1445
|
+
const overheatProtectionActive = overheatProtection?.Active ?? false;
|
|
1381
1446
|
|
|
1382
1447
|
//device control
|
|
1383
1448
|
const hideVaneControls = deviceData.HideVaneControls ?? false;
|
|
@@ -1470,8 +1535,10 @@ class DeviceAta extends EventEmitter {
|
|
|
1470
1535
|
temperatureUnit: TemperatureDisplayUnits[this.accountInfo.useFahrenheit ? 1 : 0],
|
|
1471
1536
|
isConnected: isConnected,
|
|
1472
1537
|
isInError: isInError,
|
|
1538
|
+
frostProtection: frostProtection,
|
|
1473
1539
|
frostProtectionEnabled: frostProtectionEnabled,
|
|
1474
1540
|
frostProtectionActive: frostProtectionActive,
|
|
1541
|
+
overheatProtection: overheatProtection,
|
|
1475
1542
|
overheatProtectionEnabled: overheatProtectionEnabled,
|
|
1476
1543
|
overheatProtectionActive: overheatProtectionActive,
|
|
1477
1544
|
holidayModeEnabled: holidayModeEnabled,
|
|
@@ -1572,42 +1639,34 @@ class DeviceAta extends EventEmitter {
|
|
|
1572
1639
|
obj.currentOperationMode = roomTemperature > setTemperature ? 0 : 1;
|
|
1573
1640
|
obj.targetOperationMode = 1;
|
|
1574
1641
|
break;
|
|
1575
|
-
|
|
1576
1642
|
case 2: // DRY
|
|
1577
1643
|
obj.currentOperationMode = 0;
|
|
1578
1644
|
obj.targetOperationMode = resolveTargetOperation1(2, obj);
|
|
1579
1645
|
break;
|
|
1580
|
-
|
|
1581
1646
|
case 3: // COOL
|
|
1582
1647
|
obj.currentOperationMode = roomTemperature < setTemperature ? 0 : 2;
|
|
1583
1648
|
obj.targetOperationMode = 2;
|
|
1584
1649
|
break;
|
|
1585
|
-
|
|
1586
1650
|
case 7: // FAN
|
|
1587
1651
|
obj.currentOperationMode = 0;
|
|
1588
1652
|
obj.targetOperationMode = resolveTargetOperation1(3, obj);
|
|
1589
1653
|
break;
|
|
1590
|
-
|
|
1591
1654
|
case 8: // AUTO
|
|
1592
1655
|
obj.currentOperationMode = roomTemperature < setTemperature ? 1 : roomTemperature > setTemperature ? 2 : 0;
|
|
1593
1656
|
obj.targetOperationMode = 3;
|
|
1594
1657
|
break;
|
|
1595
|
-
|
|
1596
1658
|
case 9: // ISEE HEAT
|
|
1597
1659
|
obj.currentOperationMode = roomTemperature > setTemperature ? 0 : 1;
|
|
1598
1660
|
obj.targetOperationMode = 1;
|
|
1599
1661
|
break;
|
|
1600
|
-
|
|
1601
1662
|
case 10: // ISEE DRY
|
|
1602
1663
|
obj.currentOperationMode = 0;
|
|
1603
1664
|
obj.targetOperationMode = resolveTargetOperation1(2, obj);
|
|
1604
1665
|
break;
|
|
1605
|
-
|
|
1606
1666
|
case 11: // ISEE COOL
|
|
1607
1667
|
obj.currentOperationMode = roomTemperature < setTemperature ? 0 : 2;
|
|
1608
1668
|
obj.targetOperationMode = 2;
|
|
1609
1669
|
break;
|
|
1610
|
-
|
|
1611
1670
|
default:
|
|
1612
1671
|
if (this.logWarn) this.emit('warn', `Unknown operating mode: ${operationMode}`);
|
|
1613
1672
|
break;
|
package/src/deviceatw.js
CHANGED
|
@@ -118,33 +118,31 @@ class DeviceAtw extends EventEmitter {
|
|
|
118
118
|
if (restFulEnabled) {
|
|
119
119
|
try {
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
this.restFul1 = new RestFul({
|
|
122
|
+
port: this.restFul.port,
|
|
123
|
+
logWarn: this.logWarn,
|
|
124
|
+
logDebug: this.logDebug
|
|
125
|
+
})
|
|
126
|
+
.on('connected', (message) => {
|
|
127
|
+
this.restFulConnected = true;
|
|
128
|
+
this.emit('success', message);
|
|
126
129
|
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
|
|
143
|
-
})
|
|
144
|
-
.on('error', (error) => {
|
|
145
|
-
this.emit('error', error);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
130
|
+
.on('set', async (key, value) => {
|
|
131
|
+
try {
|
|
132
|
+
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
this.emit('warn', error);
|
|
135
|
+
};
|
|
136
|
+
})
|
|
137
|
+
.on('debug', (debug) => {
|
|
138
|
+
this.emit('debug', debug);
|
|
139
|
+
})
|
|
140
|
+
.on('warn', (warn) => {
|
|
141
|
+
this.emit('warn', warn);
|
|
142
|
+
})
|
|
143
|
+
.on('error', (error) => {
|
|
144
|
+
this.emit('error', error);
|
|
145
|
+
});
|
|
148
146
|
} catch (error) {
|
|
149
147
|
if (this.logWarn) this.emit('warn', `RESTFul integration start error: ${error}`);
|
|
150
148
|
};
|
|
@@ -154,41 +152,39 @@ class DeviceAtw extends EventEmitter {
|
|
|
154
152
|
const mqttEnabled = this.mqtt.enable || false;
|
|
155
153
|
if (mqttEnabled) {
|
|
156
154
|
try {
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
this.mqtt1 = new Mqtt({
|
|
156
|
+
host: this.mqtt.host,
|
|
157
|
+
port: this.mqtt.port || 1883,
|
|
158
|
+
clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
|
|
159
|
+
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeString}/${this.deviceName}` : `melcloud/${this.deviceTypeString}/${this.deviceName}`,
|
|
160
|
+
user: this.mqtt.auth?.user,
|
|
161
|
+
passwd: this.mqtt.auth?.passwd,
|
|
162
|
+
logWarn: this.logWarn,
|
|
163
|
+
logDebug: this.logDebug
|
|
164
|
+
})
|
|
165
|
+
.on('connected', (message) => {
|
|
166
|
+
this.mqttConnected = true;
|
|
167
|
+
this.emit('success', message);
|
|
167
168
|
})
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
.
|
|
186
|
-
|
|
187
|
-
})
|
|
188
|
-
.on('error', (error) => {
|
|
189
|
-
this.emit('error', error);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
169
|
+
.on('subscribed', (message) => {
|
|
170
|
+
this.emit('success', message);
|
|
171
|
+
})
|
|
172
|
+
.on('set', async (key, value) => {
|
|
173
|
+
try {
|
|
174
|
+
await this.setOverExternalIntegration('MQTT', this.deviceData, key, value);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
this.emit('warn', error);
|
|
177
|
+
};
|
|
178
|
+
})
|
|
179
|
+
.on('debug', (debug) => {
|
|
180
|
+
this.emit('debug', debug);
|
|
181
|
+
})
|
|
182
|
+
.on('warn', (warn) => {
|
|
183
|
+
this.emit('warn', warn);
|
|
184
|
+
})
|
|
185
|
+
.on('error', (error) => {
|
|
186
|
+
this.emit('error', error);
|
|
187
|
+
});
|
|
192
188
|
} catch (error) {
|
|
193
189
|
if (this.logWarn) this.emit('warn', `MQTT integration start error: ${error}`);
|
|
194
190
|
};
|
package/src/deviceerv.js
CHANGED
|
@@ -109,34 +109,31 @@ class DeviceErv extends EventEmitter {
|
|
|
109
109
|
const restFulEnabled = this.restFul.enable || false;
|
|
110
110
|
if (restFulEnabled) {
|
|
111
111
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
this.restFul1 = new RestFul({
|
|
113
|
+
port: this.restFul.port,
|
|
114
|
+
logWarn: this.logWarn,
|
|
115
|
+
logDebug: this.logDebug
|
|
116
|
+
})
|
|
117
|
+
.on('connected', (message) => {
|
|
118
|
+
this.restFulConnected = true;
|
|
119
|
+
this.emit('success', message);
|
|
118
120
|
})
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.
|
|
134
|
-
|
|
135
|
-
})
|
|
136
|
-
.on('error', (error) => {
|
|
137
|
-
this.emit('error', error);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
121
|
+
.on('set', async (key, value) => {
|
|
122
|
+
try {
|
|
123
|
+
await this.setOverExternalIntegration('RESTFul', this.deviceData, key, value);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
this.emit('warn', error);
|
|
126
|
+
};
|
|
127
|
+
})
|
|
128
|
+
.on('debug', (debug) => {
|
|
129
|
+
this.emit('debug', debug);
|
|
130
|
+
})
|
|
131
|
+
.on('warn', (warn) => {
|
|
132
|
+
this.emit('warn', warn);
|
|
133
|
+
})
|
|
134
|
+
.on('error', (error) => {
|
|
135
|
+
this.emit('error', error);
|
|
136
|
+
});
|
|
140
137
|
} catch (error) {
|
|
141
138
|
if (this.logWarn) this.emit('warn', `RESTFul integration start error: ${error}`);
|
|
142
139
|
};
|
|
@@ -146,41 +143,39 @@ class DeviceErv extends EventEmitter {
|
|
|
146
143
|
const mqttEnabled = this.mqtt.enable || false;
|
|
147
144
|
if (mqttEnabled) {
|
|
148
145
|
try {
|
|
149
|
-
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
this.mqtt1 = new Mqtt({
|
|
147
|
+
host: this.mqtt.host,
|
|
148
|
+
port: this.mqtt.port || 1883,
|
|
149
|
+
clientId: this.mqtt.clientId ? `melcloud_${this.mqtt.clientId}_${Math.random().toString(16).slice(3)}` : `melcloud_${Math.random().toString(16).slice(3)}`,
|
|
150
|
+
prefix: this.mqtt.prefix ? `melcloud/${this.mqtt.prefix}/${this.deviceTypeString}/${this.deviceName}` : `melcloud/${this.deviceTypeString}/${this.deviceName}`,
|
|
151
|
+
user: this.mqtt.auth?.user,
|
|
152
|
+
passwd: this.mqtt.auth?.passwd,
|
|
153
|
+
logWarn: this.logWarn,
|
|
154
|
+
logDebug: this.logDebug
|
|
155
|
+
})
|
|
156
|
+
.on('connected', (message) => {
|
|
157
|
+
this.mqttConnected = true;
|
|
158
|
+
this.emit('success', message);
|
|
159
159
|
})
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
.
|
|
178
|
-
|
|
179
|
-
})
|
|
180
|
-
.on('error', (error) => {
|
|
181
|
-
this.emit('error', error);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
160
|
+
.on('subscribed', (message) => {
|
|
161
|
+
this.emit('success', message);
|
|
162
|
+
})
|
|
163
|
+
.on('set', async (key, value) => {
|
|
164
|
+
try {
|
|
165
|
+
await this.setOverExternalIntegration('MQTT', this.deviceData, key, value);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
this.emit('warn', error);
|
|
168
|
+
};
|
|
169
|
+
})
|
|
170
|
+
.on('debug', (debug) => {
|
|
171
|
+
this.emit('debug', debug);
|
|
172
|
+
})
|
|
173
|
+
.on('warn', (warn) => {
|
|
174
|
+
this.emit('warn', warn);
|
|
175
|
+
})
|
|
176
|
+
.on('error', (error) => {
|
|
177
|
+
this.emit('error', error);
|
|
178
|
+
});
|
|
184
179
|
} catch (error) {
|
|
185
180
|
if (this.logWarn) this.emit('warn', `MQTT integration start error: ${error}`);
|
|
186
181
|
};
|
package/src/mqtt.js
CHANGED
|
@@ -39,13 +39,7 @@ class Mqtt extends EventEmitter {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
// MQTT v5 subscription results contain reason codes
|
|
42
|
-
if (config.logDebug) {
|
|
43
|
-
this.emit(
|
|
44
|
-
'debug',
|
|
45
|
-
`Subscribed to ${subscribeTopic}, reason codes: ${JSON.stringify(result)}`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
42
|
+
if (config.logDebug) this.emit('debug', `Subscribed to ${subscribeTopic}, reason codes: ${JSON.stringify(result)}`);
|
|
49
43
|
this.emit('subscribed', `MQTT Subscribe topic: ${subscribeTopic}`);
|
|
50
44
|
|
|
51
45
|
} catch (error) {
|
|
@@ -57,22 +51,14 @@ class Mqtt extends EventEmitter {
|
|
|
57
51
|
this.mqttClient.on('message', (topic, payload, packet) => {
|
|
58
52
|
try {
|
|
59
53
|
const obj = JSON.parse(payload.toString());
|
|
60
|
-
|
|
61
|
-
if (config.logDebug) {
|
|
62
|
-
this.emit(
|
|
63
|
-
'debug',
|
|
64
|
-
`MQTT Received:\nTopic: ${topic}\nPayload: ${JSON.stringify(obj, null, 2)}\nProperties: ${JSON.stringify(packet.properties, null, 2)}`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
54
|
+
if (config.logDebug) this.emit('debug', `MQTT Received:\nTopic: ${topic}\nPayload: ${JSON.stringify(obj, null, 2)}\nProperties: ${JSON.stringify(packet.properties, null, 2)}`);
|
|
67
55
|
|
|
68
56
|
const key = Object.keys(obj)[0];
|
|
69
57
|
const value = Object.values(obj)[0];
|
|
70
58
|
this.emit('set', key, value);
|
|
71
59
|
|
|
72
60
|
} catch (error) {
|
|
73
|
-
if (config.logWarn) {
|
|
74
|
-
this.emit('warn', `MQTT Parse error: ${error}`);
|
|
75
|
-
}
|
|
61
|
+
if (config.logWarn) this.emit('warn', `MQTT Parse error: ${error}`);
|
|
76
62
|
}
|
|
77
63
|
});
|
|
78
64
|
|
|
@@ -93,13 +79,7 @@ class Mqtt extends EventEmitter {
|
|
|
93
79
|
}
|
|
94
80
|
});
|
|
95
81
|
|
|
96
|
-
if (config.logDebug) {
|
|
97
|
-
this.emit(
|
|
98
|
-
'debug',
|
|
99
|
-
`MQTT Publish:\nTopic: ${fullTopic}\nPayload: ${publishMessage}`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
82
|
+
if (config.logDebug) this.emit('debug', `MQTT Publish:\nTopic: ${fullTopic}\nPayload: ${publishMessage}`);
|
|
103
83
|
} catch (error) {
|
|
104
84
|
if (config.logWarn) this.emit('warn', `MQTT Publish error: ${error}`);
|
|
105
85
|
}
|
|
@@ -107,7 +87,7 @@ class Mqtt extends EventEmitter {
|
|
|
107
87
|
|
|
108
88
|
// === ERRORS / STATE ===
|
|
109
89
|
this.mqttClient.on('error', (err) => {
|
|
110
|
-
this.emit('warn', `MQTT Error: ${err.message}`);
|
|
90
|
+
if (config.logWarn) this.emit('warn', `MQTT Error: ${err.message}`);
|
|
111
91
|
});
|
|
112
92
|
|
|
113
93
|
this.mqttClient.on('reconnect', () => {
|