homebridge-tasmota-control 1.4.0-beta.25 → 1.4.0-beta.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from 'path';
2
2
  import { mkdirSync, existsSync, writeFileSync } from 'fs';
3
- import axios from 'axios';
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,8 +43,7 @@ class tasmotaPlatform {
43
43
  }
44
44
 
45
45
  //log config
46
- this.name = deviceName;
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 || '';
@@ -86,21 +85,20 @@ class tasmotaPlatform {
86
85
  return;
87
86
  }
88
87
 
89
- //axios instance
90
- this.axiosInstance = axios.create({
91
- method: 'GET',
92
- baseURL: url,
93
- timeout: refreshInterval > 10000 ? 10000 : refreshInterval,
94
- withCredentials: auth,
95
- auth: {
96
- username: user,
97
- password: passwd
98
- }
99
- });
100
-
101
88
  try {
102
89
  //get device info
103
- const info = await this.getDeviceInfo();
90
+ const deviceInfo = new deviceinfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode);
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();
104
102
  if (!info.serialNumber) {
105
103
  this.emit('warn', `Serial number not found`);
106
104
  return;
@@ -172,58 +170,6 @@ class tasmotaPlatform {
172
170
  configureAccessory(accessory) {
173
171
  this.accessories.push(accessory);
174
172
  }
175
-
176
- async getDeviceInfo() {
177
- const debug = this.enableDebugMode ? this.emit('debug', `Requesting info`) : false;
178
- try {
179
- const deviceInfoData = await this.axiosInstance(ApiCommands.Status);
180
- const deviceInfo = deviceInfoData.data ?? {};
181
- const debug = this.enableDebugMode ? this.emit('debug', `Info: ${JSON.stringify(deviceInfo, null, 2)}`) : false;
182
- await new Promise(resolve => setTimeout(resolve, 250));
183
-
184
- //status
185
- const friendlyNames = [];
186
- const status = deviceInfo.Status ?? {};
187
- const deviceName = this.loadNameFromDevice ? status.DeviceName ?? 'Unknown' : this.name;
188
- const friendlyName = status.FriendlyName ?? [];
189
- const relaysName = Array.isArray(friendlyName) ? friendlyName : [friendlyName];
190
- for (const relayName of relaysName) {
191
- const name = relayName ?? 'Unknown'
192
- friendlyNames.push(name);
193
- }
194
-
195
- //status FWR
196
- const statusFwr = deviceInfo.StatusFWR ?? {};
197
- const firmwareRevision = statusFwr.Version ?? 'Unknown';
198
- const modelName = statusFwr.Hardware ?? 'Unknown';
199
-
200
- //status NET
201
- const statusNet = deviceInfo.StatusNET ?? {};
202
- const addressMac = statusNet.Mac ?? false;
203
-
204
- //status SNS
205
- const statusSns = deviceInfo.StatusSNS ?? {};
206
- const statusSnsKeys = Object.keys(statusSns);
207
-
208
- //status STS
209
- const statusSts = deviceInfo.StatusSTS ?? {};
210
- const statusStsKeys = Object.keys(statusSts);
211
- const deviceType = statusSnsKeys.includes('MiElHVAC') ? 0 : statusStsKeys.some(key => LightKeys.includes(key)) ? 2 : statusStsKeys.includes('FanSpeed') ? 3 : 1;
212
- const obj = {
213
- deviceType: deviceType,
214
- deviceName: deviceName,
215
- friendlyNames: friendlyNames,
216
- modelName: modelName,
217
- serialNumber: addressMac,
218
- firmwareRevision: firmwareRevision,
219
- relaysCount: friendlyNames.length
220
- }
221
- return obj;
222
- } catch (error) {
223
- throw new Error(`Check info error: ${error}`);
224
- }
225
- }
226
-
227
173
  }
228
174
 
229
175
  export default (api) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "1.4.0-beta.25",
4
+ "version": "1.4.0-beta.27",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -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) {
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 TasmotaDevice extends EventEmitter {
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 TasmotaDevice;
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 TasmotaDevice extends EventEmitter {
8
+ class Lights extends EventEmitter {
9
9
  constructor(api, config, info, refreshInterval) {
10
10
  super();
11
11
 
@@ -366,7 +366,7 @@ class TasmotaDevice extends EventEmitter {
366
366
  this.emit('devInfo', `Serialnr: ${this.info.serialNumber}`)
367
367
  this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
368
368
  this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
369
- this.emit('devInfo', `Sensors: ${this.info.sensorsCount}`);
369
+ this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
370
370
  this.emit('devInfo', `----------------------------------`);
371
371
  }
372
372
 
@@ -731,4 +731,4 @@ class TasmotaDevice extends EventEmitter {
731
731
  }
732
732
  }
733
733
  }
734
- export default TasmotaDevice;
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 TasmotaDevice extends EventEmitter {
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 TasmotaDevice;
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 TasmotaDevice extends EventEmitter {
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 TasmotaDevice;
623
+ export default Switches;