homebridge-tasmota-control 0.4.15 → 0.4.16

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.
Files changed (2) hide show
  1. package/index.js +23 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -39,18 +39,17 @@ class tasmotaPlatform {
39
39
 
40
40
  this.log = log;
41
41
  this.api = api;
42
- this.devices = config.devices;
43
42
  this.accessories = [];
43
+ const devices = config.devices;
44
44
 
45
45
  this.api.on('didFinishLaunching', () => {
46
46
  this.log.debug('didFinishLaunching');
47
- for (let i = 0; i < this.devices.length; i++) {
48
- const device = this.devices[i];
47
+ for (const device of devices) {
49
48
  if (!device.name || !device.host) {
50
49
  this.log.warn('Device name or host missing!');
51
- } else {
52
- new tasmotaDevice(this.log, device, this.api);
53
- };
50
+ return;
51
+ }
52
+ new tasmotaDevice(this.log, device, this.api);
54
53
  };
55
54
  });
56
55
  };
@@ -76,7 +75,7 @@ class tasmotaDevice {
76
75
  this.host = config.host;
77
76
  this.user = config.user;
78
77
  this.passwd = config.passwd;
79
- this.auth = config.auth;
78
+ this.auth = config.auth || false;
80
79
  this.refreshInterval = config.refreshInterval || 5;
81
80
  this.enableDebugMode = config.enableDebugMode || false;
82
81
  this.disableLogInfo = config.disableLogInfo || false;
@@ -109,16 +108,14 @@ class tasmotaDevice {
109
108
  this.getDeviceInfo();
110
109
  };
111
110
 
112
- reconnect() {
113
- setTimeout(() => {
114
- this.getDeviceInfo();
115
- }, 15000);
111
+ async reconnect() {
112
+ await new Promise(resolve => setTimeout(resolve, 15000));
113
+ this.getDeviceInfo();
116
114
  };
117
115
 
118
- updateDeviceState() {
119
- setTimeout(() => {
120
- this.checkDeviceState();
121
- }, this.refreshInterval * 1000);
116
+ async updateDeviceState() {
117
+ await new Promise(resolve => setTimeout(resolve, this.refreshInterval * 1000));
118
+ this.checkDeviceState();
122
119
  };
123
120
 
124
121
  async getDeviceInfo() {
@@ -168,18 +165,18 @@ class tasmotaDevice {
168
165
  this.powerState = [];
169
166
  this.names = [];
170
167
  for (let i = 0; i < channelsCount; i++) {
171
- const power = channelsCount == 1 ? 'POWER' : 'POWER' + (i + 1);
172
- const power1 = channelsCount == 1 ? 'POWER1' : 'POWER' + (i + 1);
173
- const powerState = (deviceState.data[power] != undefined) ? (deviceState.data[power] == 'ON') : (deviceState.data[power1] == 'ON');
168
+ const power = channelsCount === 1 ? 'POWER' : 'POWER' + (i + 1);
169
+ const power1 = channelsCount === 1 ? 'POWER1' : 'POWER' + (i + 1);
170
+ const powerState = (deviceState.data[power] != undefined) ? (deviceState.data[power] === 'ON') : (deviceState.data[power1] === 'ON');
174
171
  const name = friendlyName[i];
175
172
 
176
- this.powerState.push(powerState);
177
- this.names.push(name);
178
-
179
- if (this.tasmotaServices) {
173
+ if (this.tasmotaServices && (powerState !== this.powerState[i])) {
180
174
  this.tasmotaServices[i]
181
175
  .updateCharacteristic(Characteristic.On, powerState);
182
176
  };
177
+
178
+ this.powerState.push(powerState);
179
+ this.names.push(name);
183
180
  };
184
181
 
185
182
  this.updateDeviceState();
@@ -231,8 +228,8 @@ class tasmotaDevice {
231
228
  return state;
232
229
  })
233
230
  .onSet(async (state) => {
234
- const powerOn = (channelsCount == 1) ? API_COMMANDS.Power + API_COMMANDS.On : API_COMMANDS.Power + (i + 1) + API_COMMANDS.On;
235
- const powerOff = (channelsCount == 1) ? API_COMMANDS.Power + API_COMMANDS.Off : API_COMMANDS.Power + (i + 1) + API_COMMANDS.Off;
231
+ const powerOn = (channelsCount === 1) ? API_COMMANDS.Power + API_COMMANDS.On : API_COMMANDS.Power + (i + 1) + API_COMMANDS.On;
232
+ const powerOff = (channelsCount === 1) ? API_COMMANDS.Power + API_COMMANDS.Off : API_COMMANDS.Power + (i + 1) + API_COMMANDS.Off;
236
233
  state = state ? powerOn : powerOff;
237
234
  try {
238
235
  await this.axiosInstance(state);
@@ -245,8 +242,8 @@ class tasmotaDevice {
245
242
  accessory.addService(this.tasmotaServices[i]);
246
243
  };
247
244
 
248
- this.startPrepareAccessory = false;
249
- this.log.debug(`Device: ${this.host} ${accessoryName}, publish as external accessory.`);
250
245
  this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
246
+ this.log.debug(`Device: ${this.host} ${accessoryName}, publish as external accessory.`);
247
+ this.startPrepareAccessory = false;
251
248
  };
252
249
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "0.4.15",
4
+ "version": "0.4.16",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",