homebridge-melcloud-control 2.5.0-beta.1 → 2.5.0-beta.11
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/homebridge-ui/public/index.html +29 -52
- package/homebridge-ui/server.js +38 -30
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/melcloud.js +10 -3
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
<input id="language" type="text" class="form-control"><br>
|
|
21
21
|
</div>
|
|
22
22
|
<div class="text-center">
|
|
23
|
-
<button id="logIn" type="button" class="btn btn-primary">
|
|
24
|
-
<button id="getDevices" type="button" class="btn btn-primary">Get Devices</button>
|
|
23
|
+
<button id="logIn" type="button" class="btn btn-primary">Connect to MELCloud</button>
|
|
25
24
|
<button id="configButton" type="button" class="btn btn-primary"><i class="fas fa-gear"></i></button>
|
|
26
25
|
</div>
|
|
27
26
|
</form>
|
|
@@ -101,7 +100,7 @@
|
|
|
101
100
|
|
|
102
101
|
try {
|
|
103
102
|
await homebridge.updatePluginConfig(pluginConfig)
|
|
104
|
-
document.getElementById('info').innerHTML = '';
|
|
103
|
+
document.getElementById('info').innerHTML = 'Connecting...';
|
|
105
104
|
|
|
106
105
|
const accountName = pluginConfig[0].accounts[this.deviceIndex].name;
|
|
107
106
|
const user = pluginConfig[0].accounts[this.deviceIndex].user;
|
|
@@ -111,7 +110,6 @@
|
|
|
111
110
|
const refreshInterval = pluginConfig[0].accounts[this.deviceIndex].refreshInterval;
|
|
112
111
|
|
|
113
112
|
const payload = {
|
|
114
|
-
mode: 'connect',
|
|
115
113
|
accountName: accountName,
|
|
116
114
|
user: user,
|
|
117
115
|
passwd: passwd,
|
|
@@ -122,75 +120,54 @@
|
|
|
122
120
|
const response = await homebridge.request('/connect', payload);
|
|
123
121
|
const info = response.info;
|
|
124
122
|
const status = response.status;
|
|
125
|
-
const
|
|
126
|
-
const error = response.error;
|
|
123
|
+
const devices = response.data ?? [];
|
|
127
124
|
|
|
128
125
|
switch (status) {
|
|
129
126
|
case 0:
|
|
130
|
-
document.getElementById('info').innerHTML = info;
|
|
131
|
-
document.getElementById('getDevices').removeAttribute('disabled');
|
|
132
|
-
break;
|
|
133
|
-
case 2:
|
|
134
|
-
document.getElementById('getDevices').setAttribute('disabled');
|
|
135
|
-
document.getElementById('info').innerHTML = `MELCloud error: ${JSON.stringify(error, null, 2)}`;
|
|
136
|
-
document.getElementById('info').style.color = 'red';
|
|
137
|
-
break;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
homebridge.hideSpinner();
|
|
141
|
-
} catch (e) {
|
|
142
|
-
homebridge.toast.error(`Data error: ${e.message}`);
|
|
143
|
-
} finally {
|
|
144
|
-
homebridge.hideSpinner();
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
//get devices
|
|
149
|
-
document.getElementById('getDevices').addEventListener('click', async () => {
|
|
150
|
-
homebridge.showSpinner();
|
|
151
|
-
try {
|
|
152
|
-
const devicesId = [];
|
|
153
|
-
|
|
154
|
-
const payload = {
|
|
155
|
-
mode: 'getdevices'
|
|
156
|
-
};
|
|
157
|
-
const response = await homebridge.request('/getDevices', payload);
|
|
158
|
-
|
|
159
|
-
const info = response.info;
|
|
160
|
-
const status = response.status;
|
|
161
|
-
const devices = response.data;
|
|
162
|
-
const error = response.error;
|
|
163
|
-
|
|
164
|
-
switch (status) {
|
|
165
|
-
case 1:
|
|
166
127
|
//get device info fom devices
|
|
167
128
|
for (const deviceInfo of devices) {
|
|
168
129
|
const deviceId = deviceInfo.DeviceID;
|
|
169
130
|
const deviceName = deviceInfo.DeviceName;
|
|
170
|
-
|
|
171
|
-
//prepare device if not in devices array
|
|
172
|
-
if (!devicesId.includes(deviceId)) {
|
|
173
|
-
devicesId.push(deviceId);
|
|
174
|
-
}
|
|
175
131
|
};
|
|
176
132
|
|
|
177
|
-
document.getElementById('info').innerHTML = `${info} Found: ${
|
|
133
|
+
document.getElementById('info').innerHTML = `${info} Found: ${devices.length} devices. Now You can start to configure it.`;
|
|
134
|
+
document.getElementById('info').style.color = 'green';
|
|
178
135
|
await homebridge.updatePluginConfig(pluginConfig);
|
|
179
136
|
await homebridge.savePluginConfig(pluginConfig);
|
|
180
137
|
break;
|
|
138
|
+
case 1:
|
|
139
|
+
document.getElementById('info').innerHTML = info;
|
|
140
|
+
document.getElementById('info').style.color = 'green';
|
|
141
|
+
break;
|
|
181
142
|
case 2:
|
|
182
|
-
document.getElementById('info').innerHTML =
|
|
143
|
+
document.getElementById('info').innerHTML = info;
|
|
144
|
+
document.getElementById('info').style.color = 'white';
|
|
145
|
+
break;
|
|
146
|
+
case 3:
|
|
147
|
+
document.getElementById('info').innerHTML = info;
|
|
148
|
+
document.getElementById('info').style.color = 'gray';
|
|
149
|
+
break;
|
|
150
|
+
case 4:
|
|
151
|
+
document.getElementById('info').innerHTML = info;
|
|
152
|
+
document.getElementById('info').style.color = 'yellow';
|
|
153
|
+
break;
|
|
154
|
+
case 5:
|
|
155
|
+
document.getElementById('info').innerHTML = info;
|
|
183
156
|
document.getElementById('info').style.color = 'red';
|
|
184
157
|
break;
|
|
158
|
+
default:
|
|
159
|
+
document.getElementById('info').innerHTML = `Received unknown status: ${status}, please try again.`;
|
|
160
|
+
document.getElementById('info').style.color = 'yellow';
|
|
161
|
+
break;
|
|
185
162
|
};
|
|
186
163
|
|
|
187
164
|
homebridge.hideSpinner();
|
|
188
165
|
} catch (e) {
|
|
189
|
-
|
|
166
|
+
document.getElementById('info').innerHTML = 'Please try again.';
|
|
167
|
+
homebridge.toast.error(`Data error: ${e.message}`);
|
|
190
168
|
} finally {
|
|
191
169
|
homebridge.hideSpinner();
|
|
192
|
-
}
|
|
170
|
+
};
|
|
193
171
|
});
|
|
194
|
-
|
|
195
172
|
})();
|
|
196
173
|
</script>
|
package/homebridge-ui/server.js
CHANGED
|
@@ -7,9 +7,6 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
9
9
|
|
|
10
|
-
//get devices
|
|
11
|
-
this.onRequest('/getdevices', this.start.bind(this));
|
|
12
|
-
|
|
13
10
|
//connect
|
|
14
11
|
this.onRequest('/connect', this.start.bind(this));
|
|
15
12
|
|
|
@@ -18,8 +15,6 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
18
15
|
};
|
|
19
16
|
|
|
20
17
|
async start(payload) {
|
|
21
|
-
|
|
22
|
-
const mode = payload.mode;
|
|
23
18
|
const accountName = payload.accountName;
|
|
24
19
|
const user = payload.user;
|
|
25
20
|
const passwd = payload.passwd;
|
|
@@ -28,40 +23,53 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
28
23
|
const refreshInterval = payload.refreshInterval;
|
|
29
24
|
const accountInfoFile = `${this.homebridgeStoragePath}/melcloud/${accountName}_Account`;
|
|
30
25
|
const deviceInfoFile = `${this.homebridgeStoragePath}/melcloud/${accountName}_Device_`;
|
|
31
|
-
const
|
|
32
|
-
|
|
26
|
+
const buildingsFile = `${this.homebridgeStoragePath}/melcloud/${accountName}_Buildings`;
|
|
33
27
|
let data = {};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, enableDebugMode, refreshInterval, true);
|
|
31
|
+
melCloud.on('devicesList', (devices) => {
|
|
32
|
+
return data = {
|
|
33
|
+
info: 'Check devices list complete.',
|
|
34
|
+
status: 0,
|
|
35
|
+
data: devices
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.on('success', (message) => {
|
|
38
39
|
return data = {
|
|
39
|
-
info:
|
|
40
|
-
status: 1
|
|
41
|
-
data: response
|
|
40
|
+
info: message,
|
|
41
|
+
status: 1
|
|
42
42
|
};
|
|
43
|
-
}
|
|
43
|
+
})
|
|
44
|
+
.on('message', (message) => {
|
|
44
45
|
return data = {
|
|
45
|
-
info:
|
|
46
|
-
status: 2
|
|
47
|
-
data: error
|
|
46
|
+
info: message,
|
|
47
|
+
status: 2
|
|
48
48
|
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const response = await melCloud.chackDevicesList();
|
|
49
|
+
})
|
|
50
|
+
.on('debug', (debug) => {
|
|
53
51
|
return data = {
|
|
54
|
-
info:
|
|
55
|
-
status:
|
|
56
|
-
data: response
|
|
52
|
+
info: debug,
|
|
53
|
+
status: 3
|
|
57
54
|
};
|
|
58
|
-
}
|
|
55
|
+
})
|
|
56
|
+
.on('warn', (warn) => {
|
|
59
57
|
return data = {
|
|
60
|
-
info:
|
|
61
|
-
status:
|
|
62
|
-
data: error
|
|
58
|
+
info: warn,
|
|
59
|
+
status: 4
|
|
63
60
|
};
|
|
64
|
-
}
|
|
61
|
+
})
|
|
62
|
+
.on('error', async (error) => {
|
|
63
|
+
return data = {
|
|
64
|
+
info: error,
|
|
65
|
+
status: 5
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return data = {
|
|
70
|
+
info: error,
|
|
71
|
+
status: 5
|
|
72
|
+
};
|
|
65
73
|
};
|
|
66
74
|
};
|
|
67
75
|
};
|
package/index.js
CHANGED
|
@@ -78,7 +78,7 @@ class MelCloudPlatform {
|
|
|
78
78
|
const deviceRefreshInterval = account.deviceRefreshInterval * 1000 || 5000;
|
|
79
79
|
|
|
80
80
|
//melcloud account
|
|
81
|
-
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, buildingsFile, deviceInfoFile, enableDebugMode, refreshInterval);
|
|
81
|
+
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, buildingsFile, deviceInfoFile, enableDebugMode, refreshInterval, false);
|
|
82
82
|
melCloud.on('checkDevicesListComplete', (accountInfo, contextKey, deviceInfo) => {
|
|
83
83
|
const deviceId = deviceInfo.DeviceID.toString();
|
|
84
84
|
const deviceType = deviceInfo.Type;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "2.5.0-beta.
|
|
4
|
+
"version": "2.5.0-beta.11",
|
|
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/melcloud.js
CHANGED
|
@@ -8,13 +8,14 @@ const ImpulseGenerator = require('./impulsegenerator.js');
|
|
|
8
8
|
const CONSTANTS = require('./constants.json');
|
|
9
9
|
|
|
10
10
|
class MelCloud extends EventEmitter {
|
|
11
|
-
constructor(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, enableDebugMode, refreshInterval) {
|
|
11
|
+
constructor(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, enableDebugMode, refreshInterval, connectForConfig) {
|
|
12
12
|
super();
|
|
13
13
|
this.enableDebugMode = enableDebugMode;
|
|
14
14
|
this.accountInfoFile = accountInfoFile;
|
|
15
15
|
this.buildingsFile = buildingsFile;
|
|
16
16
|
this.deviceInfoFile = deviceInfoFile;
|
|
17
17
|
this.refreshInterval = refreshInterval;
|
|
18
|
+
this.connectForConfig = connectForConfig;
|
|
18
19
|
this.devicesId = [];
|
|
19
20
|
|
|
20
21
|
this.options = {
|
|
@@ -128,7 +129,7 @@ class MelCloud extends EventEmitter {
|
|
|
128
129
|
|
|
129
130
|
//start impulse generator
|
|
130
131
|
const timers = [{ name: 'checkDevicesList', sampling: this.refreshInterval }];
|
|
131
|
-
this.impulseGenerator.start(timers)
|
|
132
|
+
const startImpulseGenerator = this.connectForConfig ? false : this.impulseGenerator.start(timers);
|
|
132
133
|
|
|
133
134
|
return true;
|
|
134
135
|
} catch (error) {
|
|
@@ -175,6 +176,12 @@ class MelCloud extends EventEmitter {
|
|
|
175
176
|
}
|
|
176
177
|
const debug3 = this.enableDebugMode ? this.emit('debug', `Found: ${devicesCount} devices.`) : false;
|
|
177
178
|
|
|
179
|
+
//emit devices list for config
|
|
180
|
+
this.emit('devicesList', devices);
|
|
181
|
+
if (this.connectForConfig) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
178
185
|
//get device info fom devices
|
|
179
186
|
for (const deviceInfo of devices) {
|
|
180
187
|
const deviceId = deviceInfo.DeviceID
|
|
@@ -192,7 +199,7 @@ class MelCloud extends EventEmitter {
|
|
|
192
199
|
}
|
|
193
200
|
};
|
|
194
201
|
|
|
195
|
-
return
|
|
202
|
+
return true;
|
|
196
203
|
} catch (error) {
|
|
197
204
|
this.impulseGenerator.stop();
|
|
198
205
|
throw new Error(`Scanning for devices error: ${error.message ?? error}.`);
|