homebridge-tasmota-control 0.4.4 → 0.4.45-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.
Files changed (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/index.js +22 -18
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.4.5] - (08.08.2022)
8
+ ## Changes
9
+ - fix report wrong device state [#4](https://github.com/grzegorz914/homebridge-tasmota-control/issues/4)
10
+
7
11
  ## [0.4.4] - (23.07.2022)
8
12
  ## Changes
9
13
  - refactor information service
package/index.js CHANGED
@@ -88,8 +88,6 @@ class tasmotaDevice {
88
88
 
89
89
  //setup variables
90
90
  this.channelsCount = 0;
91
- this.checkDeviceInfo = true;
92
- this.checkDeviceState = false;
93
91
  this.startPrepareAccessory = true;
94
92
 
95
93
  this.prefDir = path.join(api.user.storagePath(), 'tasmota');
@@ -106,14 +104,19 @@ class tasmotaDevice {
106
104
  fs.mkdirSync(this.prefDir);
107
105
  }
108
106
 
109
- //Check device state
110
- setInterval(function () {
111
- if (this.checkDeviceInfo) {
112
- this.getDeviceInfo();
113
- } else {
114
- this.updateDeviceState();
115
- }
116
- }.bind(this), this.refreshInterval * 1000);
107
+ this.getDeviceInfo();
108
+ }
109
+
110
+ reconnect() {
111
+ setTimeout(() => {
112
+ this.getDeviceInfo();
113
+ }, 10000);
114
+ }
115
+
116
+ checkDeviceState() {
117
+ setTimeout(() => {
118
+ this.updateDeviceState();
119
+ }, this.refreshInterval * 1000);
117
120
  }
118
121
 
119
122
  async getDeviceInfo() {
@@ -141,9 +144,10 @@ class tasmotaDevice {
141
144
  this.firmwareRevision = firmwareRevision;
142
145
  this.channelsCount = channelsCount;
143
146
 
144
- this.checkDeviceInfo = (channelsCount == 0);
147
+ this.updateDeviceState();
145
148
  } catch (error) {
146
- this.log.error('Device: %s %s, Device Info eror: %s, state: Offline, trying to reconnect', this.host, this.name, error);
149
+ this.log.error('Device: %s %s, Device Info eror: %s, state: Offline, trying to reconnect in 10s.', this.host, this.name, error);
150
+ this.reconnect();
147
151
  }
148
152
  }
149
153
 
@@ -155,7 +159,7 @@ class tasmotaDevice {
155
159
 
156
160
  this.powerState = new Array();
157
161
  for (let i = 0; i < this.channelsCount; i++) {
158
- const channel = this.channelsCount == 1 ? 'POWER' : 'POWER' + (i + 1);
162
+ const channel = this.channelsCount == 1 ? 'POWER' || 'POWER1' : 'POWER' + (i + 1);
159
163
  const powerState = (response.data[channel] == 'ON');
160
164
  if (this.tasmotaServices) {
161
165
  this.tasmotaServices[i]
@@ -163,16 +167,16 @@ class tasmotaDevice {
163
167
  }
164
168
  this.powerState.push(powerState);
165
169
  }
166
- this.checkDeviceState = true;
170
+
171
+ this.checkDeviceState();
167
172
 
168
173
  //start prepare accessory
169
- if (this.startPrepareAccessory) {
174
+ if (this.startPrepareAccessory && this.serialNumber) {
170
175
  this.prepareAccessory();
171
176
  }
172
177
  } catch (error) {
173
- this.log.error('Device: %s %s, update Device state error: %s, state: Offline', this.host, this.name, error);
174
- this.checkDeviceState = false;
175
- this.checkDeviceInfo = true;
178
+ this.log.error('Device: %s %s, update Device state error: %s, trying again.', this.host, this.name, error);
179
+ this.checkDeviceState();
176
180
  }
177
181
  }
178
182
 
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.4",
4
+ "version": "0.4.45-beta.2",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",