homebridge-tasmota-control 0.3.35 → 0.3.37-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/README.md +1 -1
  2. package/index.js +14 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1 @@
1
- # tasmota-outlet
1
+ # tasmota-control
package/index.js CHANGED
@@ -85,6 +85,7 @@ class tasmotaDevice {
85
85
  this.checkDeviceInfo = true;
86
86
  this.checkDeviceState = false;
87
87
  this.startPrepareAccessory = true;
88
+
88
89
  this.prefDir = path.join(api.user.storagePath(), 'tasmota');
89
90
  this.url = `http://${this.host}/cm?user=${this.user}&password=${this.passwd}&cmnd=`
90
91
 
@@ -103,19 +104,18 @@ class tasmotaDevice {
103
104
  setInterval(function () {
104
105
  if (this.checkDeviceInfo) {
105
106
  this.getDeviceInfo();
106
- }
107
- if (this.checkDeviceState) {
107
+ } else {
108
108
  this.updateDeviceState();
109
109
  }
110
110
  }.bind(this), this.refreshInterval * 1000);
111
-
112
- //start prepare accessory
113
111
  }
114
112
 
115
113
  async getDeviceInfo() {
116
114
  this.log.debug('Device: %s %s, requesting Device Info.', this.host, this.name);
117
115
  try {
118
116
  const response = await this.axiosInstance(STATUS);
117
+ const debug = this.enableDebugMode ? this.log('Device: %s %s, debug response: %s', this.host, this.name, response.data) : false;
118
+
119
119
  const deviceName = response.data.Status.DeviceName;
120
120
  const modelName = response.data.StatusFWR.Hardware;
121
121
  const addressMac = response.data.StatusNET.Mac;
@@ -133,7 +133,6 @@ class tasmotaDevice {
133
133
  this.firmwareRevision = firmwareRevision;
134
134
 
135
135
  this.checkDeviceInfo = false;
136
- this.updateDeviceState();
137
136
  } catch (error) {
138
137
  this.log.error('Device: %s %s, Device Info eror: %s, state: Offline, trying to reconnect', this.host, this.name, error);
139
138
  this.checkDeviceInfo = true;
@@ -143,15 +142,18 @@ class tasmotaDevice {
143
142
  async updateDeviceState() {
144
143
  this.log.debug('Device: %s %s, requesting Device state.', this.host, this.name);
145
144
  try {
145
+ const response = await this.axiosInstance(POWER + 0);
146
+ const debug = this.enableDebugMode ? this.log('Device: %s %s, debug response: %s', this.host, this.name, response.data) : false;
147
+
148
+ this.powerState = new Array();
146
149
  for (let i = 0; i < this.channelsCount; i++) {
147
- const channel = this.channelsCount == 1 ? 'POWER' : 'POWER' + i;
148
- const response = await this.axiosInstance(channel);
149
- const debug = this.enableDebugMode ? this.log('Device: %s %s, debug response: %s', this.host, this.name, response.data) : false;
150
- const powerState = (response.data[channel] != undefined) ? (response.data[channel] == 'ON') : false;
150
+ const powerState = (response.data[POWER + i] != undefined) ? (response.data[POWER + i] == 'ON') : false;
151
151
  if (this.tasmotaServices) {
152
152
  this.tasmotaServices[i]
153
153
  .updateCharacteristic(Characteristic.OutletInUse, powerState);
154
154
  }
155
+
156
+ this.powerState.push(powerState)
155
157
  }
156
158
  this.checkDeviceState = true;
157
159
 
@@ -188,7 +190,6 @@ class tasmotaDevice {
188
190
  .setCharacteristic(Characteristic.Model, modelName)
189
191
  .setCharacteristic(Characteristic.SerialNumber, serialNumber)
190
192
  .setCharacteristic(Characteristic.FirmwareRevision, firmwareRevision);
191
-
192
193
  accessory.addService(informationService);
193
194
 
194
195
  //Prepare service
@@ -198,24 +199,20 @@ class tasmotaDevice {
198
199
  const tasmotaService = new Service.Outlet(accessoryName, `tasmotaService${[i]}`);
199
200
  tasmotaService.getCharacteristic(Characteristic.On)
200
201
  .onGet(async () => {
201
- const channel = this.channelsCount == 1 ? 'POWER' : 'POWER' + i;
202
- const response = await this.axiosInstance(channel);
203
- const state = (response.data[channel] != undefined) ? (response.data[channel] == 'ON') : false;
202
+ const state = this.powerState[i];
204
203
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s, get state: %s', accessoryName, state ? 'ON' : 'OFF');
205
204
  return state;
206
205
  })
207
206
  .onSet(async (state) => {
208
207
  const powerOn = this.channelsCount == 1 ? POWER + ON : POWER + (i + 1) + ON;
209
208
  const powerOff = this.channelsCount == 1 ? POWER + OFF : POWER + (i + 1) + OFF;
210
- state = state ? powerOn : powerOff;
209
+ state = state ? POWER + ON : POWER + OFF;
211
210
  this.axiosInstance(state);
212
211
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s, set state: %s', accessoryName, state ? 'ON' : 'OFF');
213
212
  });
214
213
  tasmotaService.getCharacteristic(Characteristic.OutletInUse)
215
214
  .onGet(async () => {
216
- const channel = this.channelsCount == 1 ? 'POWER' : 'POWER' + i;
217
- const response = await this.axiosInstance(channel);
218
- const state = (response.data[channel] != undefined) ? (response.data[channel] == 'ON') : false;
215
+ const state = this.powerState[i];
219
216
  const logInfo = this.disableLogInfo ? false : this.log('Device: %s, in use: %s', accessoryName, state ? 'YES' : 'NO');
220
217
  return state;
221
218
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "0.3.35",
4
+ "version": "0.3.37-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",