homebridge-tasmota-control 0.10.13 → 0.10.15

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
@@ -2,13 +2,13 @@
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const TasmotaDevice = require('./src/tasmotadevice.js');
5
- const CONSTANS = require('./src/constans.json');
5
+ const CONSTANTS = require('./src/constants.json');
6
6
 
7
7
  class tasmotaPlatform {
8
8
  constructor(log, config, api) {
9
9
  // only load if configured
10
10
  if (!config || !Array.isArray(config.devices)) {
11
- log(`No configuration found for ${CONSTANS.PluginName}.`);
11
+ log(`No configuration found for ${CONSTANTS.PluginName}.`);
12
12
  return;
13
13
  };
14
14
  this.accessories = [];
@@ -38,7 +38,7 @@ class tasmotaPlatform {
38
38
  //tasmota device
39
39
  const tasmotaDevice = new TasmotaDevice(api, device);
40
40
  tasmotaDevice.on('publishAccessory', (accessory) => {
41
- api.publishExternalAccessories(CONSTANS.PluginName, [accessory]);
41
+ api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]);
42
42
  const debug = device.enableDebugMode ? log(`Device: ${device.host} ${device.name}, published as external accessory.`) : false;
43
43
  })
44
44
  .on('devInfo', (devInfo) => {
@@ -63,5 +63,5 @@ class tasmotaPlatform {
63
63
  };
64
64
 
65
65
  module.exports = (api) => {
66
- api.registerPlatform(CONSTANS.PluginName, CONSTANS.PlatformName, tasmotaPlatform, true);
66
+ api.registerPlatform(CONSTANTS.PluginName, CONSTANTS.PlatformName, tasmotaPlatform, true);
67
67
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "0.10.13",
4
+ "version": "0.10.15",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -28,7 +28,7 @@
28
28
  "homebridge": ">=1.6.0"
29
29
  },
30
30
  "dependencies": {
31
- "axios": "^1.6.7"
31
+ "axios": "^1.6.8"
32
32
  },
33
33
  "keywords": [
34
34
  "homebridge",
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
  const axios = require('axios');
3
3
  const EventEmitter = require('events');
4
- const CONSTANS = require('./constans.json');
5
- let Accessory, Characteristic, Service, Categories, UUID;
4
+ const CONSTANTS = require('./constants.json');
5
+ let Accessory, Characteristic, Service, Categories, AccessoryUUID;
6
6
 
7
7
  class TasmotaDevice extends EventEmitter {
8
8
  constructor(api, config) {
@@ -12,7 +12,7 @@ class TasmotaDevice extends EventEmitter {
12
12
  Characteristic = api.hap.Characteristic;
13
13
  Service = api.hap.Service;
14
14
  Categories = api.hap.Categories;
15
- UUID = api.hap.uuid;
15
+ AccessoryUUID = api.hap.uuid;
16
16
 
17
17
  //device configuration
18
18
  this.name = config.name;
@@ -102,8 +102,8 @@ class TasmotaDevice extends EventEmitter {
102
102
  const debug = this.enableDebugMode ? this.emit('debug', `Requesting info.`) : false;
103
103
 
104
104
  try {
105
- const deviceInfoData = await this.axiosInstance(CONSTANS.ApiCommands.Status);
106
- const deviceInfo = deviceInfoData.data;
105
+ const deviceInfoData = await this.axiosInstance(CONSTANTS.ApiCommands.Status);
106
+ const deviceInfo = deviceInfoData.data ?? {};
107
107
  const debug = this.enableDebugMode ? this.emit('debug', `Info: ${JSON.stringify(deviceInfo, null, 2)}`) : false;
108
108
 
109
109
  //keys
@@ -120,8 +120,9 @@ class TasmotaDevice extends EventEmitter {
120
120
 
121
121
  //status fwr
122
122
  const statusFWRSupported = deviceInfoKeys.includes('StatusFWR');
123
- const firmwareRevision = deviceInfo.StatusFWR.Version ?? 'Unknown';
124
- const modelName = deviceInfo.StatusFWR.Hardware ?? 'Unknown';
123
+ const statusFwr = deviceInfo.StatusFWR ?? {};
124
+ const firmwareRevision = statusFwr.Version ?? 'Unknown';
125
+ const modelName = statusFwr.Hardware ?? 'Unknown';
125
126
 
126
127
  //status net
127
128
  const addressMac = deviceInfo.StatusNET.Mac;
@@ -129,7 +130,7 @@ class TasmotaDevice extends EventEmitter {
129
130
  //status sns
130
131
  const statusSNSSupported = deviceInfoKeys.includes('StatusSNS') ?? false;
131
132
  if (statusSNSSupported) {
132
- const sensorTypes = CONSTANS.SensorKeys;
133
+ const sensorTypes = CONSTANTS.SensorKeys;
133
134
  const sensor = Object.entries(deviceInfo.StatusSNS)
134
135
  .filter(([key]) => sensorTypes.some(type => key.includes(type)))
135
136
  .reduce((obj, [key, value]) => {
@@ -188,18 +189,18 @@ class TasmotaDevice extends EventEmitter {
188
189
  this.hue = [];
189
190
  this.saturation = [];
190
191
 
191
- const powersStatusData = await this.axiosInstance(CONSTANS.ApiCommands.PowerStatus);
192
+ const powersStatusData = await this.axiosInstance(CONSTANTS.ApiCommands.PowerStatus);
192
193
  const powersStatus = powersStatusData.data ?? {};
193
194
  const debug = this.enableDebugMode ? this.emit('debug', `Power status: ${JSON.stringify(powersStatus, null, 2)}`) : false;
194
195
 
195
196
  //power status keys and device type
196
197
  const powerKeys = Object.keys(powersStatus);
197
- const deviceType = powerKeys.some(key => CONSTANS.LightKeys.includes(key)) ? 1 : 0; //0 - switch/outlet, 1 - light
198
+ const deviceType = powerKeys.some(key => CONSTANTS.LightKeys.includes(key)) ? 1 : 0; //0 - switch/outlet, 1 - light
198
199
 
199
200
  for (let i = 0; i < relaysCount; i++) {
200
201
  const powerNr = i + 1;
201
202
  const powerKey = relaysCount === 1 ? 'POWER' : `POWER${powerNr}`;
202
- const powerState = powersStatus[powerKey] === 'ON' ?? false;
203
+ const powerState = powersStatus[powerKey] === 'ON';
203
204
  const brightness = powersStatus.Dimmer ?? false;
204
205
  const colorTemperature = powersStatus.CT ?? false;
205
206
  const hue = powersStatus.HSBColor1 ?? false;
@@ -251,7 +252,7 @@ class TasmotaDevice extends EventEmitter {
251
252
  this.sensorsAmbientLight = [];
252
253
  this.sensorsMotion = [];
253
254
 
254
- const sensorsStatusData = await this.axiosInstance(CONSTANS.ApiCommands.Status);
255
+ const sensorsStatusData = await this.axiosInstance(CONSTANTS.ApiCommands.Status);
255
256
  const sensorsStatus = sensorsStatusData.data.StatusSNS ?? {};
256
257
  const debug = this.enableDebugMode ? this.emit('debug', `Sensors status: ${JSON.stringify(sensorsStatus, null, 2)}`) : false;
257
258
 
@@ -270,7 +271,7 @@ class TasmotaDevice extends EventEmitter {
270
271
  const gas = sensorData.Gas ?? false;
271
272
  const carbonDioxyde = sensorData.CarbonDioxyde ?? false;
272
273
  const ambientLight = sensorData.Ambient ?? false;
273
- const motion = sensorData === 'ON' ?? false;
274
+ const motion = sensorData === 'ON';
274
275
 
275
276
  //energy
276
277
  const energyTotal = sensorData.Total ?? false;
@@ -396,7 +397,7 @@ class TasmotaDevice extends EventEmitter {
396
397
 
397
398
  try {
398
399
  const accessoryName = this.deviceName;
399
- const accessoryUUID = UUID.generate(this.serialNumber);
400
+ const accessoryUUID = AccessoryUUID.generate(this.serialNumber);
400
401
  const accessoryCategory = Categories.OTHER;
401
402
  const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
402
403
 
@@ -437,8 +438,8 @@ class TasmotaDevice extends EventEmitter {
437
438
  .onSet(async (state) => {
438
439
  try {
439
440
  const relayNr = i + 1;
440
- const powerOn = relaysCount === 1 ? CONSTANS.ApiCommands.PowerOn : `${CONSTANS.ApiCommands.Power}${relayNr}${CONSTANS.ApiCommands.On}`;
441
- const powerOff = relaysCount === 1 ? CONSTANS.ApiCommands.PowerOff : `${CONSTANS.ApiCommands.Power}${relayNr}${CONSTANS.ApiCommands.Off}`;
441
+ const powerOn = relaysCount === 1 ? CONSTANTS.ApiCommands.PowerOn : `${CONSTANTS.ApiCommands.Power}${relayNr}${CONSTANTS.ApiCommands.On}`;
442
+ const powerOff = relaysCount === 1 ? CONSTANTS.ApiCommands.PowerOff : `${CONSTANTS.ApiCommands.Power}${relayNr}${CONSTANTS.ApiCommands.Off}`;
442
443
  state = state ? powerOn : powerOff;
443
444
 
444
445
  await this.axiosInstance(state);
@@ -457,7 +458,7 @@ class TasmotaDevice extends EventEmitter {
457
458
  })
458
459
  .onSet(async (value) => {
459
460
  try {
460
- const brightness = `${CONSTANS.ApiCommands.Dimmer}${value}`; //0..100
461
+ const brightness = `${CONSTANTS.ApiCommands.Dimmer}${value}`; //0..100
461
462
  await this.axiosInstance(brightness);
462
463
  const logInfo = this.disableLogInfo ? false : this.emit('message', `set brightness: ${value} %`);
463
464
  } catch (error) {
@@ -475,7 +476,7 @@ class TasmotaDevice extends EventEmitter {
475
476
  .onSet(async (value) => {
476
477
  try {
477
478
  value = value < 153 ? 153 : value;
478
- const colorTemperature = `${CONSTANS.ApiCommands.ColorTemperature}${value}`; //140..500
479
+ const colorTemperature = `${CONSTANTS.ApiCommands.ColorTemperature}${value}`; //140..500
479
480
  await this.axiosInstance(colorTemperature);
480
481
  const logInfo = this.disableLogInfo ? false : this.emit('message', `set color temperatur: ${value} °`);
481
482
  } catch (error) {
@@ -492,7 +493,7 @@ class TasmotaDevice extends EventEmitter {
492
493
  })
493
494
  .onSet(async (value) => {
494
495
  try {
495
- const hue = `${CONSTANS.ApiCommands.HSBHue}${value}`; //0..360
496
+ const hue = `${CONSTANTS.ApiCommands.HSBHue}${value}`; //0..360
496
497
  await this.axiosInstance(hue);
497
498
  const logInfo = this.disableLogInfo ? false : this.emit('message', `set hue: ${value} °`);
498
499
  } catch (error) {
@@ -509,7 +510,7 @@ class TasmotaDevice extends EventEmitter {
509
510
  })
510
511
  .onSet(async (value) => {
511
512
  try {
512
- const saturation = `${CONSTANS.ApiCommands.HSBSaturation}${value}`; //0..100
513
+ const saturation = `${CONSTANTS.ApiCommands.HSBSaturation}${value}`; //0..100
513
514
  await this.axiosInstance(saturation);
514
515
  const logInfo = this.disableLogInfo ? false : this.emit('message', `set saturation: ${value} °`);
515
516
  } catch (error) {
File without changes