homebridge-melcloud-control 3.9.9 → 3.9.10-beta.2
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/index.js +104 -112
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -36,14 +36,8 @@ class MelCloudPlatform {
|
|
|
36
36
|
const language = account.language;
|
|
37
37
|
|
|
38
38
|
//check mandatory properties
|
|
39
|
-
if (!accountName || !user || !passwd || !language) {
|
|
40
|
-
log.warn(`
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
//check duplicate account name
|
|
45
|
-
if (accountsName.includes(accountName)) {
|
|
46
|
-
log.warn(`Account name: ${accountName}, must be unique.`);
|
|
39
|
+
if (!accountName || accountsName.includes(accountName) || !user || !passwd || !language) {
|
|
40
|
+
log.warn(`Account name: ${accountName ? accountsName.includes(accountName) ? 'Duplicated' : 'OK' : accountName}, user: ${user ? 'OK' : user}, password: ${passwd ? 'OK' : passwd}, language: ${language ? 'OK' : language} in config missing.`);
|
|
47
41
|
continue;
|
|
48
42
|
}
|
|
49
43
|
accountsName.push(accountName);
|
|
@@ -82,105 +76,106 @@ class MelCloudPlatform {
|
|
|
82
76
|
const devicesFile = `${prefDir}/${accountName}_Devices`;
|
|
83
77
|
|
|
84
78
|
//set account refresh interval
|
|
85
|
-
const refreshInterval = (account.refreshInterval ?? 120) * 1000
|
|
79
|
+
const refreshInterval = (account.refreshInterval ?? 120) * 1000
|
|
86
80
|
|
|
87
81
|
try {
|
|
88
|
-
//
|
|
89
|
-
const
|
|
90
|
-
.on('
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
82
|
+
//create impulse generator
|
|
83
|
+
const impulseGenerator = new ImpulseGenerator()
|
|
84
|
+
.on('start', async () => {
|
|
85
|
+
try {
|
|
86
|
+
//melcloud account
|
|
87
|
+
const melCloud = new MelCloud(user, passwd, language, accountFile, buildingsFile, devicesFile, enableDebugMode, false)
|
|
88
|
+
.on('success', (msg) => logLevel.success && log.success(`${accountName}, ${msg}`))
|
|
89
|
+
.on('info', (msg) => logLevel.info && log.info(`${accountName}, ${msg}`))
|
|
90
|
+
.on('debug', (msg) => logLevel.debug && log.info(`${accountName}, debug: ${msg}`))
|
|
91
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`${accountName}, ${msg}`))
|
|
92
|
+
.on('error', (msg) => logLevel.error && log.error(`${accountName}, ${msg}`));
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
//connect
|
|
96
|
+
let response;
|
|
97
|
+
try {
|
|
98
|
+
response = await melCloud.connect();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (logLevel.error) log.error(`${accountName}, Connect error: ${error.message ?? error}`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
109
103
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const accountInfo = response.accountInfo ?? false;
|
|
105
|
+
const contextKey = response.contextKey ?? false;
|
|
106
|
+
const useFahrenheit = response.useFahrenheit ?? false;
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
devicesInMelcloud = await melCloud.checkDevicesList(contextKey);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (!devicesInMelcloud || !Array.isArray(devicesInMelcloud)) continue;
|
|
123
|
-
|
|
124
|
-
//start account impulse generator
|
|
125
|
-
await melCloud.impulseGenerator.start([{ name: 'checkDevicesList', sampling: refreshInterval }]);
|
|
126
|
-
|
|
127
|
-
//configured devices
|
|
128
|
-
const ataDevices = account.ataDevices ?? [];
|
|
129
|
-
const atwDevices = account.atwDevices ?? [];
|
|
130
|
-
const ervDevices = account.ervDevices ?? [];
|
|
131
|
-
const devices = [...ataDevices, ...atwDevices, ...ervDevices];
|
|
132
|
-
if (logLevel.debug) log.info(`Found configured devices ATA: ${ataDevices.length}, ATW: ${atwDevices.length}, ERV: ${ervDevices.length}.`);
|
|
133
|
-
for (const device of devices) {
|
|
134
|
-
//chack device from config exist on melcloud
|
|
135
|
-
const deviceId = device.id;
|
|
136
|
-
const displayMode = device.displayMode > 0;
|
|
137
|
-
const deviceExistInMelCloud = devicesInMelcloud.some(dev => dev.DeviceID === deviceId);
|
|
138
|
-
if (!deviceExistInMelCloud || !displayMode) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const deviceName = device.name;
|
|
143
|
-
const deviceType = device.type;
|
|
144
|
-
const deviceTypeText = device.typeString;
|
|
145
|
-
const deviceRefreshInterval = (device.refreshInterval ?? 5) * 1000;
|
|
146
|
-
try {
|
|
147
|
-
let configuredDevice;
|
|
148
|
-
switch (deviceType) {
|
|
149
|
-
case 0: //ATA
|
|
150
|
-
configuredDevice = new DeviceAta(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
151
|
-
break;
|
|
152
|
-
case 1: //ATW
|
|
153
|
-
configuredDevice = new DeviceAtw(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
154
|
-
break;
|
|
155
|
-
case 2:
|
|
156
|
-
break;
|
|
157
|
-
case 3: //ERV
|
|
158
|
-
configuredDevice = new DeviceErv(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
159
|
-
break;
|
|
160
|
-
default:
|
|
161
|
-
if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
108
|
+
if (contextKey === false) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
164
111
|
|
|
165
|
-
|
|
112
|
+
//check devices list
|
|
113
|
+
let devicesInMelcloud;
|
|
166
114
|
try {
|
|
167
|
-
|
|
168
|
-
await melCloud.send(accountInfo);
|
|
115
|
+
devicesInMelcloud = await melCloud.checkDevicesList(contextKey);
|
|
169
116
|
} catch (error) {
|
|
170
|
-
if (logLevel.error) log.error(`${accountName},
|
|
117
|
+
if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
|
|
118
|
+
return;
|
|
171
119
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
120
|
+
if (!devicesInMelcloud || !Array.isArray(devicesInMelcloud)) return;
|
|
121
|
+
|
|
122
|
+
//start account impulse generator
|
|
123
|
+
await melCloud.impulseGenerator.start([{ name: 'checkDevicesList', sampling: refreshInterval }]);
|
|
124
|
+
|
|
125
|
+
//configured devices
|
|
126
|
+
const ataDevices = account.ataDevices ?? [];
|
|
127
|
+
const atwDevices = account.atwDevices ?? [];
|
|
128
|
+
const ervDevices = account.ervDevices ?? [];
|
|
129
|
+
const devices = [...ataDevices, ...atwDevices, ...ervDevices];
|
|
130
|
+
if (logLevel.debug) log.info(`Found configured devices ATA: ${ataDevices.length}, ATW: ${atwDevices.length}, ERV: ${ervDevices.length}.`);
|
|
131
|
+
|
|
132
|
+
for (const device of devices) {
|
|
133
|
+
//chack device from config exist on melcloud
|
|
134
|
+
const deviceId = device.id;
|
|
135
|
+
const displayMode = device.displayMode > 0;
|
|
136
|
+
const deviceExistInMelCloud = devicesInMelcloud.some(dev => dev.DeviceID === deviceId);
|
|
137
|
+
if (!deviceExistInMelCloud || !displayMode) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const deviceName = device.name;
|
|
142
|
+
const deviceType = device.type;
|
|
143
|
+
const deviceTypeText = device.typeString;
|
|
144
|
+
const deviceRefreshInterval = (device.refreshInterval ?? 5) * 1000;
|
|
145
|
+
|
|
146
|
+
let configuredDevice;
|
|
147
|
+
switch (deviceType) {
|
|
148
|
+
case 0: //ATA
|
|
149
|
+
configuredDevice = new DeviceAta(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
150
|
+
break;
|
|
151
|
+
case 1: //ATW
|
|
152
|
+
configuredDevice = new DeviceAtw(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
153
|
+
break;
|
|
154
|
+
case 2:
|
|
155
|
+
break;
|
|
156
|
+
case 3: //ERV
|
|
157
|
+
configuredDevice = new DeviceErv(api, account, device, contextKey, accountName, deviceId, deviceName, deviceTypeText, devicesFile, deviceRefreshInterval, useFahrenheit, restFul, mqtt);
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
if (logLevel.warn) log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, unknown device: ${deviceType}.`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
configuredDevice.on('melCloud', async (key, value) => {
|
|
165
|
+
try {
|
|
166
|
+
accountInfo[key] = value;
|
|
167
|
+
await melCloud.send(accountInfo);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (logLevel.error) log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error}.`);
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
.on('devInfo', (info) => logLevel.devInfo && log.info(info))
|
|
173
|
+
.on('success', (msg) => logLevel.success && log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
|
|
174
|
+
.on('info', (msg) => logLevel.info && log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
|
|
175
|
+
.on('debug', (msg) => logLevel.debug && log.info(`${accountName}, ${deviceTypeText}, ${deviceName}, debug: ${msg}`))
|
|
176
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`))
|
|
177
|
+
.on('error', (msg) => logLevel.error && log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${msg}`));
|
|
178
|
+
|
|
184
179
|
const accessory = await configuredDevice.start();
|
|
185
180
|
if (accessory) {
|
|
186
181
|
api.publishExternalAccessories(PluginName, [accessory]);
|
|
@@ -189,21 +184,18 @@ class MelCloudPlatform {
|
|
|
189
184
|
await impulseGenerator.stop();
|
|
190
185
|
await configuredDevice.startImpulseGenerator();
|
|
191
186
|
}
|
|
192
|
-
} catch (error) {
|
|
193
|
-
if (logLevel.error) log.error(`${accountName}, ${deviceTypeText}, ${deviceName}, ${error.message ?? error}, trying again.`);
|
|
194
187
|
}
|
|
195
|
-
}
|
|
196
|
-
if (logLevel.
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (logLevel.error) log.error(`${accountName}, Start impulse generator error, ${error.message ?? error}, trying again.`);
|
|
190
|
+
}
|
|
191
|
+
}).on('state', (state) => {
|
|
192
|
+
if (logLevel.debug) log.info(`${accountName}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
//start impulse generator
|
|
196
|
+
await impulseGenerator.start([{ name: 'start', sampling: 60000 }]);
|
|
205
197
|
} catch (error) {
|
|
206
|
-
if (logLevel.error) log.error(`${accountName},
|
|
198
|
+
if (logLevel.error) log.error(`${accountName}, Did finish launching error: ${error.message ?? error}.`);
|
|
207
199
|
}
|
|
208
200
|
}
|
|
209
201
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "3.9.
|
|
4
|
+
"version": "3.9.10-beta.2",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"LICENSE"
|
|
32
32
|
],
|
|
33
33
|
"engines": {
|
|
34
|
-
"homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.
|
|
34
|
+
"homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.30 || ^2.0.0-alpha.40",
|
|
35
35
|
"node": "^20 || ^22 || ^24"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@homebridge/plugin-ui-utils": "^2.1.0",
|
|
39
39
|
"async-mqtt": "^2.6.3",
|
|
40
|
-
"axios": "^1.12.
|
|
40
|
+
"axios": "^1.12.2",
|
|
41
41
|
"express": "^5.1.0"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|