homebridge-tasmota-control 1.4.0-beta.26 → 1.4.0-beta.28
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 +14 -69
- package/package.json +1 -1
- package/src/deviceinfo.js +77 -0
- package/src/fans.js +2 -2
- package/src/lights.js +2 -2
- package/src/mielhvac.js +2 -2
- package/src/switches.js +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { mkdirSync, existsSync, writeFileSync } from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import deviceinfo from './src/deviceinfo.js';
|
|
4
4
|
import mielhvac from './src/mielhvac.js';
|
|
5
5
|
import switches from './src/switches.js';
|
|
6
6
|
import lights from './src/lights.js';
|
|
@@ -43,15 +43,13 @@ class tasmotaPlatform {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//log config
|
|
46
|
-
|
|
47
|
-
this.loadNameFromDevice = deviceConfig.loadNameFromDevice || false;
|
|
46
|
+
const loadNameFromDevice = deviceConfig.loadNameFromDevice || false;
|
|
48
47
|
const auth = deviceConfig.auth || false;
|
|
49
48
|
const url = `http://${host}/cm?cmnd=`;
|
|
50
49
|
const user = deviceConfig.user || '';
|
|
51
50
|
const passwd = deviceConfig.passwd || '';
|
|
52
51
|
const refreshInterval = deviceConfig.refreshInterval * 1000 || 5000;
|
|
53
52
|
const enableDebugMode = deviceConfig.enableDebugMode || false;
|
|
54
|
-
this.enableDebugMode = enableDebugMode;
|
|
55
53
|
const disableLogDeviceInfo = deviceConfig.disableLogDeviceInfo || false;
|
|
56
54
|
const disableLogInfo = deviceConfig.disableLogInfo || false;
|
|
57
55
|
const disableLogSuccess = deviceConfig.disableLogSuccess || false;
|
|
@@ -87,21 +85,20 @@ class tasmotaPlatform {
|
|
|
87
85
|
return;
|
|
88
86
|
}
|
|
89
87
|
|
|
90
|
-
//axios instance
|
|
91
|
-
this.axiosInstance = axios.create({
|
|
92
|
-
method: 'GET',
|
|
93
|
-
baseURL: url,
|
|
94
|
-
timeout: refreshInterval > 10000 ? 10000 : refreshInterval,
|
|
95
|
-
withCredentials: auth,
|
|
96
|
-
auth: {
|
|
97
|
-
username: user,
|
|
98
|
-
password: passwd
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
88
|
try {
|
|
103
89
|
//get device info
|
|
104
|
-
const
|
|
90
|
+
const deviceInfo = new deviceinfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode, refreshInterval);
|
|
91
|
+
info.on('debug', (debug) => {
|
|
92
|
+
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
93
|
+
})
|
|
94
|
+
.on('warn', (warn) => {
|
|
95
|
+
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
96
|
+
})
|
|
97
|
+
.on('error', (error) => {
|
|
98
|
+
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}.`);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const info = await info.getInfo();
|
|
105
102
|
if (!info.serialNumber) {
|
|
106
103
|
this.emit('warn', `Serial number not found`);
|
|
107
104
|
return;
|
|
@@ -173,58 +170,6 @@ class tasmotaPlatform {
|
|
|
173
170
|
configureAccessory(accessory) {
|
|
174
171
|
this.accessories.push(accessory);
|
|
175
172
|
}
|
|
176
|
-
|
|
177
|
-
async getDeviceInfo() {
|
|
178
|
-
const debug = this.enableDebugMode ? this.emit('debug', `Requesting info`) : false;
|
|
179
|
-
try {
|
|
180
|
-
const deviceInfoData = await this.axiosInstance(ApiCommands.Status);
|
|
181
|
-
const deviceInfo = deviceInfoData.data ?? {};
|
|
182
|
-
const debug = this.enableDebugMode ? this.emit('debug', `Info: ${JSON.stringify(deviceInfo, null, 2)}`) : false;
|
|
183
|
-
await new Promise(resolve => setTimeout(resolve, 250));
|
|
184
|
-
|
|
185
|
-
//status
|
|
186
|
-
const friendlyNames = [];
|
|
187
|
-
const status = deviceInfo.Status ?? {};
|
|
188
|
-
const deviceName = this.loadNameFromDevice ? status.DeviceName ?? 'Unknown' : this.name;
|
|
189
|
-
const friendlyName = status.FriendlyName ?? [];
|
|
190
|
-
const relaysName = Array.isArray(friendlyName) ? friendlyName : [friendlyName];
|
|
191
|
-
for (const relayName of relaysName) {
|
|
192
|
-
const name = relayName ?? 'Unknown'
|
|
193
|
-
friendlyNames.push(name);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//status FWR
|
|
197
|
-
const statusFwr = deviceInfo.StatusFWR ?? {};
|
|
198
|
-
const firmwareRevision = statusFwr.Version ?? 'Unknown';
|
|
199
|
-
const modelName = statusFwr.Hardware ?? 'Unknown';
|
|
200
|
-
|
|
201
|
-
//status NET
|
|
202
|
-
const statusNet = deviceInfo.StatusNET ?? {};
|
|
203
|
-
const addressMac = statusNet.Mac ?? false;
|
|
204
|
-
|
|
205
|
-
//status SNS
|
|
206
|
-
const statusSns = deviceInfo.StatusSNS ?? {};
|
|
207
|
-
const statusSnsKeys = Object.keys(statusSns);
|
|
208
|
-
|
|
209
|
-
//status STS
|
|
210
|
-
const statusSts = deviceInfo.StatusSTS ?? {};
|
|
211
|
-
const statusStsKeys = Object.keys(statusSts);
|
|
212
|
-
const deviceType = statusSnsKeys.includes('MiElHVAC') ? 0 : statusStsKeys.some(key => LightKeys.includes(key)) ? 2 : statusStsKeys.includes('FanSpeed') ? 3 : 1;
|
|
213
|
-
const obj = {
|
|
214
|
-
deviceType: deviceType,
|
|
215
|
-
deviceName: deviceName,
|
|
216
|
-
friendlyNames: friendlyNames,
|
|
217
|
-
modelName: modelName,
|
|
218
|
-
serialNumber: addressMac,
|
|
219
|
-
firmwareRevision: firmwareRevision,
|
|
220
|
-
relaysCount: friendlyNames.length
|
|
221
|
-
}
|
|
222
|
-
return obj;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
throw new Error(`Check info error: ${error}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
173
|
}
|
|
229
174
|
|
|
230
175
|
export default (api) => {
|
package/package.json
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import { ApiCommands, LightKeys } from './constants.js';
|
|
4
|
+
|
|
5
|
+
class DeviceInfo extends EventEmitter {
|
|
6
|
+
constructor(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode, refreshInterval) {
|
|
7
|
+
super();
|
|
8
|
+
this.name = deviceName
|
|
9
|
+
this.loadNameFromDevice = loadNameFromDevice;
|
|
10
|
+
this.enableDebugMode = enableDebugMode;
|
|
11
|
+
|
|
12
|
+
//axios instance
|
|
13
|
+
this.axiosInstance = axios.create({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
baseURL: url,
|
|
16
|
+
timeout: refreshInterval > 10000 ? 10000 : refreshInterval,
|
|
17
|
+
withCredentials: auth,
|
|
18
|
+
auth: {
|
|
19
|
+
username: user,
|
|
20
|
+
password: passwd
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getInfo() {
|
|
27
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Requesting info`) : false;
|
|
28
|
+
try {
|
|
29
|
+
const deviceInfoData = await this.axiosInstance(ApiCommands.Status);
|
|
30
|
+
const deviceInfo = deviceInfoData.data ?? {};
|
|
31
|
+
const debug = this.enableDebugMode ? this.emit('debug', `Info: ${JSON.stringify(deviceInfo, null, 2)}`) : false;
|
|
32
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
33
|
+
|
|
34
|
+
//status
|
|
35
|
+
const friendlyNames = [];
|
|
36
|
+
const status = deviceInfo.Status ?? {};
|
|
37
|
+
const deviceName = this.loadNameFromDevice ? status.DeviceName ?? 'Unknown' : this.name;
|
|
38
|
+
const friendlyName = status.FriendlyName ?? [];
|
|
39
|
+
const relaysName = Array.isArray(friendlyName) ? friendlyName : [friendlyName];
|
|
40
|
+
for (const relayName of relaysName) {
|
|
41
|
+
const name = relayName ?? 'Unknown'
|
|
42
|
+
friendlyNames.push(name);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//status FWR
|
|
46
|
+
const statusFwr = deviceInfo.StatusFWR ?? {};
|
|
47
|
+
const firmwareRevision = statusFwr.Version ?? 'Unknown';
|
|
48
|
+
const modelName = statusFwr.Hardware ?? 'Unknown';
|
|
49
|
+
|
|
50
|
+
//status NET
|
|
51
|
+
const statusNet = deviceInfo.StatusNET ?? {};
|
|
52
|
+
const addressMac = statusNet.Mac ?? false;
|
|
53
|
+
|
|
54
|
+
//status SNS
|
|
55
|
+
const statusSns = deviceInfo.StatusSNS ?? {};
|
|
56
|
+
const statusSnsKeys = Object.keys(statusSns);
|
|
57
|
+
|
|
58
|
+
//status STS
|
|
59
|
+
const statusSts = deviceInfo.StatusSTS ?? {};
|
|
60
|
+
const statusStsKeys = Object.keys(statusSts);
|
|
61
|
+
const deviceType = statusSnsKeys.includes('MiElHVAC') ? 0 : statusStsKeys.some(key => LightKeys.includes(key)) ? 2 : statusStsKeys.includes('FanSpeed') ? 3 : 1;
|
|
62
|
+
const obj = {
|
|
63
|
+
deviceType: deviceType,
|
|
64
|
+
deviceName: deviceName,
|
|
65
|
+
friendlyNames: friendlyNames,
|
|
66
|
+
modelName: modelName,
|
|
67
|
+
serialNumber: addressMac,
|
|
68
|
+
firmwareRevision: firmwareRevision,
|
|
69
|
+
relaysCount: friendlyNames.length
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error(`Check info error: ${error}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export default DeviceInfo;
|
package/src/fans.js
CHANGED
|
@@ -5,7 +5,7 @@ import ImpulseGenerator from './impulsegenerator.js';
|
|
|
5
5
|
import { ApiCommands, SensorKeys } from './constants.js';
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class Fans extends EventEmitter {
|
|
9
9
|
constructor(api, config, info, refreshInterval) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
@@ -710,4 +710,4 @@ class TasmotaDevice extends EventEmitter {
|
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
|
-
export default
|
|
713
|
+
export default Fans;
|
package/src/lights.js
CHANGED
|
@@ -5,7 +5,7 @@ import ImpulseGenerator from './impulsegenerator.js';
|
|
|
5
5
|
import { ApiCommands, SensorKeys } from './constants.js';
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class Lights extends EventEmitter {
|
|
9
9
|
constructor(api, config, info, refreshInterval) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
@@ -731,4 +731,4 @@ class TasmotaDevice extends EventEmitter {
|
|
|
731
731
|
}
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
|
-
export default
|
|
734
|
+
export default Lights;
|
package/src/mielhvac.js
CHANGED
|
@@ -5,7 +5,7 @@ import ImpulseGenerator from './impulsegenerator.js';
|
|
|
5
5
|
import { ApiCommands, MiElHVAC, TemperatureDisplayUnits } from './constants.js';
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class MiElHvac extends EventEmitter {
|
|
9
9
|
constructor(api, config, info, refreshInterval, defaultHeatingSetTemperatureFile, defaultCoolingSetTemperatureFile) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
@@ -1395,4 +1395,4 @@ class TasmotaDevice extends EventEmitter {
|
|
|
1395
1395
|
}
|
|
1396
1396
|
}
|
|
1397
1397
|
}
|
|
1398
|
-
export default
|
|
1398
|
+
export default MiElHvac;
|
package/src/switches.js
CHANGED
|
@@ -5,7 +5,7 @@ import ImpulseGenerator from './impulsegenerator.js';
|
|
|
5
5
|
import { ApiCommands, SensorKeys } from './constants.js';
|
|
6
6
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class Switches extends EventEmitter {
|
|
9
9
|
constructor(api, config, info, refreshInterval) {
|
|
10
10
|
super();
|
|
11
11
|
|
|
@@ -620,4 +620,4 @@ class TasmotaDevice extends EventEmitter {
|
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
export default
|
|
623
|
+
export default Switches;
|