homebridge-tasmota-control 0.4.16 → 0.4.17
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 +13 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -88,6 +88,8 @@ class tasmotaDevice {
|
|
|
88
88
|
this.firmwareRevision = 'Firmware Revision';
|
|
89
89
|
|
|
90
90
|
//setup variables
|
|
91
|
+
this.powerStates = [];
|
|
92
|
+
this.names = [];
|
|
91
93
|
this.channelsCount = 0;
|
|
92
94
|
this.startPrepareAccessory = true;
|
|
93
95
|
|
|
@@ -162,29 +164,27 @@ class tasmotaDevice {
|
|
|
162
164
|
const deviceState = await this.axiosInstance(API_COMMANDS.PowerStatus);
|
|
163
165
|
const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, debug state: ${JSON.stringify(deviceState.data, null, 2)}`) : false;
|
|
164
166
|
|
|
165
|
-
this.powerState = [];
|
|
166
|
-
this.names = [];
|
|
167
167
|
for (let i = 0; i < channelsCount; i++) {
|
|
168
168
|
const power = channelsCount === 1 ? 'POWER' : 'POWER' + (i + 1);
|
|
169
169
|
const power1 = channelsCount === 1 ? 'POWER1' : 'POWER' + (i + 1);
|
|
170
|
-
const powerState =
|
|
170
|
+
const powerState = deviceState.data[power] !== undefined ? (deviceState.data[power] === 'ON') : (deviceState.data[power1] === 'ON');
|
|
171
171
|
const name = friendlyName[i];
|
|
172
172
|
|
|
173
|
-
if (this.tasmotaServices && (powerState !== this.
|
|
173
|
+
if (this.tasmotaServices && (powerState !== this.powerStates[i])) {
|
|
174
174
|
this.tasmotaServices[i]
|
|
175
175
|
.updateCharacteristic(Characteristic.On, powerState);
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
this.
|
|
179
|
-
this.names.push(name);
|
|
178
|
+
this.powerStates.length < channelsCount ? this.powerStates.push(powerState) : this.powerStates[i] = powerState;
|
|
179
|
+
this.names.length < channelsCount ? this.names.push(name) : this.namesnames[i] = name;
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
this.updateDeviceState();
|
|
183
|
-
|
|
184
182
|
//start prepare accessory
|
|
185
183
|
if (this.startPrepareAccessory && this.serialNumber) {
|
|
186
184
|
this.prepareAccessory();
|
|
187
185
|
};
|
|
186
|
+
|
|
187
|
+
this.updateDeviceState();
|
|
188
188
|
} catch (error) {
|
|
189
189
|
this.log.error(`Device: ${this.host} ${this.name}, check state error: ${error}, trying again.`);
|
|
190
190
|
this.updateDeviceState();
|
|
@@ -218,18 +218,18 @@ class tasmotaDevice {
|
|
|
218
218
|
const channelsName = this.names;
|
|
219
219
|
const channelsCount = this.channelsCount;;
|
|
220
220
|
for (let i = 0; i < channelsCount; i++) {
|
|
221
|
-
const serviceName =
|
|
222
|
-
const logName =
|
|
221
|
+
const serviceName = channelsCount > 1 ? `${accessoryName} ${channelsName[i]}` : accessoryName;
|
|
222
|
+
const logName = channelsCount > 1 ? `${accessoryName}, channel: ${channelsName[i]}` : `${accessoryName}`
|
|
223
223
|
const tasmotaService = new Service.Outlet(serviceName, `tasmotaService${[i]}`);
|
|
224
224
|
tasmotaService.getCharacteristic(Characteristic.On)
|
|
225
225
|
.onGet(async () => {
|
|
226
|
-
const state = this.
|
|
226
|
+
const state = this.powerStates[i];
|
|
227
227
|
const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host} ${logName}, state: ${state ? 'ON' : 'OFF'}`);
|
|
228
228
|
return state;
|
|
229
229
|
})
|
|
230
230
|
.onSet(async (state) => {
|
|
231
|
-
const powerOn =
|
|
232
|
-
const powerOff =
|
|
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;
|
|
233
233
|
state = state ? powerOn : powerOff;
|
|
234
234
|
try {
|
|
235
235
|
await this.axiosInstance(state);
|
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
|
+
"version": "0.4.17",
|
|
5
5
|
"description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Tasmota flashed devices.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|