homebridge-tuya-plus 3.4.0 → 3.5.1

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 (36) hide show
  1. package/Readme.MD +1 -1
  2. package/config.schema.json +11 -0
  3. package/index.js +14 -10
  4. package/lib/AirConditionerAccessory.js +362 -445
  5. package/lib/AirPurifierAccessory.js +150 -335
  6. package/lib/BaseAccessory.js +34 -0
  7. package/lib/ConvectorAccessory.js +250 -313
  8. package/lib/CustomMultiOutletAccessory.js +97 -111
  9. package/lib/DehumidifierAccessory.js +40 -115
  10. package/lib/EnergyCharacteristics.js +5 -5
  11. package/lib/GarageDoorAccessory.js +225 -307
  12. package/lib/MultiOutletAccessory.js +92 -106
  13. package/lib/OilDiffuserAccessory.js +379 -480
  14. package/lib/OutletAccessory.js +83 -83
  15. package/lib/RGBTWLightAccessory.js +219 -249
  16. package/lib/RGBTWOutletAccessory.js +270 -296
  17. package/lib/SimpleBlindsAccessory.js +56 -85
  18. package/lib/SimpleDimmer2Accessory.js +54 -54
  19. package/lib/SimpleDimmerAccessory.js +54 -54
  20. package/lib/SimpleFanAccessory.js +31 -67
  21. package/lib/SimpleFanLightAccessory.js +58 -117
  22. package/lib/SimpleHeaterAccessory.js +140 -166
  23. package/lib/SimpleLightAccessory.js +2 -2
  24. package/lib/SwitchAccessory.js +16 -30
  25. package/lib/TWLightAccessory.js +92 -94
  26. package/lib/ValveAccessory.js +60 -72
  27. package/lib/VerticalBlindsWithTilt.js +66 -186
  28. package/package.json +6 -5
  29. package/test/BaseAccessory.test.js +269 -0
  30. package/test/EnergyCharacteristics.test.js +74 -0
  31. package/test/GarageDoorAccessory.test.js +131 -0
  32. package/test/MultiOutletAccessory.test.js +86 -0
  33. package/test/RGBTWLightAccessory.test.js +143 -0
  34. package/test/support/mocks.js +163 -0
  35. package/wiki/Supported-Device-Types.md +19 -0
  36. package/wiki/User-documented-device-config.md +27 -0
package/Readme.MD CHANGED
@@ -43,7 +43,7 @@ A community-maintained Homebridge plugin for controlling Tuya devices locally ov
43
43
  * Color<sup>[12](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md#white-and-color-light-bulbs)</sup> (Hue, Saturation, Adaptive Lighting)
44
44
  * Oil Diffusers<sup>[13](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md)</sup>
45
45
  * Outlets<sup>[14](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md#outlets)</sup>
46
- * Switches<sup>[15](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md)</sup>
46
+ * Switches<sup>[15](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md#switch)</sup>
47
47
  * Vertical Blinds<sup>[16](https://github.com/adrianjagielak/homebridge-tuya-plus/blob/main/wiki/Supported-Device-Types.md#vertical-blinds-with-tilt)</sup>
48
48
 
49
49
  Note: Motion, and other sensor types don't behave well with responce requests, so they will not be added.
@@ -30,6 +30,10 @@
30
30
  "title": "Please select device type...",
31
31
  "enum": ["null"]
32
32
  },
33
+ {
34
+ "title": "Switch Gang / Basic Switch",
35
+ "enum": ["Switch"]
36
+ },
33
37
  {
34
38
  "title": "Smart Plug / Barely Smart Power Strip",
35
39
  "enum": ["Outlet"]
@@ -147,6 +151,13 @@
147
151
  "functionBody": "return model.devices && model.devices[arrayIndices].type !== 'null';"
148
152
  }
149
153
  },
154
+ "switchCount": {
155
+ "type": "integer",
156
+ "placeholder": "3",
157
+ "condition": {
158
+ "functionBody": "return model.devices && model.devices[arrayIndices] && ['Switch'].includes(model.devices[arrayIndices].type);"
159
+ }
160
+ },
150
161
  "voltsId": {
151
162
  "type": "integer",
152
163
  "placeholder": "9",
package/index.js CHANGED
@@ -25,8 +25,12 @@ const OilDiffuserAccessory = require('./lib/OilDiffuserAccessory');
25
25
  const DoorbellAccessory = require('./lib/DoorbellAccessory');
26
26
  const VerticalBlindsWithTilt = require('./lib/VerticalBlindsWithTilt');
27
27
 
28
- const PLUGIN_NAME = 'homebridge-tuya';
28
+ const PLUGIN_NAME = 'homebridge-tuya-plus';
29
29
  const PLATFORM_NAME = 'TuyaLan';
30
+ // Seed used to derive accessory UUIDs. Must remain 'homebridge-tuya' so that
31
+ // devices already paired with HomeKit keep their existing identity (names,
32
+ // rooms, automations).
33
+ const UUID_SEED = 'homebridge-tuya';
30
34
  const DEFAULT_DISCOVER_TIMEOUT = 60000;
31
35
 
32
36
  const CLASS_DEF = {
@@ -55,12 +59,12 @@ const CLASS_DEF = {
55
59
  verticalblindswithtilt: VerticalBlindsWithTilt
56
60
  };
57
61
 
58
- let Characteristic, PlatformAccessory, Service, Categories, AdaptiveLightingController, UUID;
62
+ let Characteristic, Formats, Perms, Categories, PlatformAccessory, Service, AdaptiveLightingController, UUID;
59
63
 
60
64
  module.exports = function(homebridge) {
61
65
  ({
62
66
  platformAccessory: PlatformAccessory,
63
- hap: {Characteristic, Service, AdaptiveLightingController, Accessory: {Categories}, uuid: UUID}
67
+ hap: {Characteristic, Formats, Perms, Categories, Service, AdaptiveLightingController, uuid: UUID}
64
68
  } = homebridge);
65
69
 
66
70
  homebridge.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, TuyaLan, true);
@@ -71,14 +75,14 @@ class TuyaLan {
71
75
  [this.log, this.config, this.api] = [...props];
72
76
 
73
77
  this.cachedAccessories = new Map();
74
- this.api.hap.EnergyCharacteristics = require('./lib/EnergyCharacteristics')(this.api.hap.Characteristic);
78
+ this.api.hap.EnergyCharacteristics = require('./lib/EnergyCharacteristics')(this.api.hap);
75
79
 
76
80
  if(!this.config || !this.config.devices) {
77
81
  this.log("No devices found. Check that you have specified them in your config.json file.");
78
82
  return false;
79
83
  }
80
84
 
81
- this._expectedUUIDs = this.config.devices.map(device => UUID.generate(PLUGIN_NAME +(device.fake ? ':fake:' : ':') + device.id));
85
+ this._expectedUUIDs = this.config.devices.map(device => UUID.generate(UUID_SEED +(device.fake ? ':fake:' : ':') + device.id));
82
86
 
83
87
  this.api.on('didFinishLaunching', () => {
84
88
  this.discoverDevices();
@@ -122,7 +126,7 @@ class TuyaLan {
122
126
  const device = new TuyaAccessory({
123
127
  ...devices[config.id], ...config,
124
128
  log: this.log,
125
- UUID: UUID.generate(PLUGIN_NAME + ':' + config.id),
129
+ UUID: UUID.generate(UUID_SEED + ':' + config.id),
126
130
  connect: false
127
131
  });
128
132
  this.addAccessory(device);
@@ -133,7 +137,7 @@ class TuyaLan {
133
137
  this.addAccessory(new TuyaAccessory({
134
138
  ...config,
135
139
  log: this.log,
136
- UUID: UUID.generate(PLUGIN_NAME + ':fake:' + config.id),
140
+ UUID: UUID.generate(UUID_SEED + ':fake:' + config.id),
137
141
  connect: false
138
142
  }));
139
143
  });
@@ -149,7 +153,7 @@ class TuyaLan {
149
153
  const device = new TuyaAccessory({
150
154
  ...devices[deviceId],
151
155
  log: this.log,
152
- UUID: UUID.generate(PLUGIN_NAME + ':' + deviceId),
156
+ UUID: UUID.generate(UUID_SEED + ':' + deviceId),
153
157
  connect: false
154
158
  });
155
159
  this.addAccessory(device);
@@ -174,7 +178,7 @@ class TuyaLan {
174
178
  if (!characteristic.props ||
175
179
  !Array.isArray(characteristic.props.perms) ||
176
180
  characteristic.props.perms.length !== 3 ||
177
- !(characteristic.props.perms.includes(Characteristic.Perms.WRITE) && characteristic.props.perms.includes(Characteristic.Perms.NOTIFY))
181
+ !(characteristic.props.perms.includes(Perms.WRITE) && characteristic.props.perms.includes(Perms.NOTIFY))
178
182
  ) return;
179
183
 
180
184
  this.log.info('Marked %s unreachable by faulting Service.%s.%s', accessory.displayName, service.displayName, characteristic.displayName);
@@ -236,7 +240,7 @@ class TuyaLan {
236
240
  this.log.warn('Unregistering', homebridgeAccessory.displayName);
237
241
 
238
242
  delete this.cachedAccessories[homebridgeAccessory.UUID];
239
- this.api.unregisterPlatformAccessories(PLATFORM_NAME, PLATFORM_NAME, [homebridgeAccessory]);
243
+ this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [homebridgeAccessory]);
240
244
  }
241
245
 
242
246
  removeAccessoryByUUID(uuid) {