@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.11

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 (136) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +44 -17
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -2
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +220 -397
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +3 -2
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +59 -31
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +3 -2
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +57 -29
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +47 -18
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +16 -5
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/device.d.ts +9 -0
  24. package/dist/device/device.d.ts.map +1 -1
  25. package/dist/device/device.js +30 -3
  26. package/dist/device/device.js.map +1 -1
  27. package/dist/device/fan.d.ts.map +1 -1
  28. package/dist/device/fan.js +44 -18
  29. package/dist/device/fan.js.map +1 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +46 -18
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +45 -20
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts.map +1 -1
  37. package/dist/device/iosensor.js +46 -18
  38. package/dist/device/iosensor.js.map +1 -1
  39. package/dist/device/lightstrip.d.ts +4 -3
  40. package/dist/device/lightstrip.d.ts.map +1 -1
  41. package/dist/device/lightstrip.js +60 -31
  42. package/dist/device/lightstrip.js.map +1 -1
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +48 -17
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts.map +1 -1
  47. package/dist/device/meter.js +46 -18
  48. package/dist/device/meter.js.map +1 -1
  49. package/dist/device/meterplus.d.ts.map +1 -1
  50. package/dist/device/meterplus.js +46 -18
  51. package/dist/device/meterplus.js.map +1 -1
  52. package/dist/device/motion.d.ts.map +1 -1
  53. package/dist/device/motion.js +45 -17
  54. package/dist/device/motion.js.map +1 -1
  55. package/dist/device/plug.d.ts.map +1 -1
  56. package/dist/device/plug.js +40 -18
  57. package/dist/device/plug.js.map +1 -1
  58. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  59. package/dist/device/robotvacuumcleaner.js +42 -17
  60. package/dist/device/robotvacuumcleaner.js.map +1 -1
  61. package/dist/device/waterdetector.d.ts.map +1 -1
  62. package/dist/device/waterdetector.js +41 -16
  63. package/dist/device/waterdetector.js.map +1 -1
  64. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  65. package/dist/irdevice/airconditioner.js +8 -1
  66. package/dist/irdevice/airconditioner.js.map +1 -1
  67. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  68. package/dist/irdevice/airpurifier.js +6 -0
  69. package/dist/irdevice/airpurifier.js.map +1 -1
  70. package/dist/irdevice/camera.d.ts.map +1 -1
  71. package/dist/irdevice/camera.js +3 -0
  72. package/dist/irdevice/camera.js.map +1 -1
  73. package/dist/irdevice/fan.d.ts.map +1 -1
  74. package/dist/irdevice/fan.js +3 -0
  75. package/dist/irdevice/fan.js.map +1 -1
  76. package/dist/irdevice/irdevice.d.ts +9 -0
  77. package/dist/irdevice/irdevice.d.ts.map +1 -1
  78. package/dist/irdevice/irdevice.js +29 -2
  79. package/dist/irdevice/irdevice.js.map +1 -1
  80. package/dist/irdevice/light.d.ts.map +1 -1
  81. package/dist/irdevice/light.js +9 -0
  82. package/dist/irdevice/light.js.map +1 -1
  83. package/dist/irdevice/other.d.ts +1 -0
  84. package/dist/irdevice/other.d.ts.map +1 -1
  85. package/dist/irdevice/other.js +216 -228
  86. package/dist/irdevice/other.js.map +1 -1
  87. package/dist/irdevice/tv.d.ts.map +1 -1
  88. package/dist/irdevice/tv.js +9 -0
  89. package/dist/irdevice/tv.js.map +1 -1
  90. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  91. package/dist/irdevice/vacuumcleaner.js +3 -0
  92. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  93. package/dist/irdevice/waterheater.js +1 -1
  94. package/dist/irdevice/waterheater.js.map +1 -1
  95. package/dist/platform.d.ts.map +1 -1
  96. package/dist/platform.js +11 -2
  97. package/dist/platform.js.map +1 -1
  98. package/dist/types/bledevicestatus.d.ts +1 -0
  99. package/dist/types/bledevicestatus.d.ts.map +1 -1
  100. package/dist/utils.d.ts +8 -0
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +16 -0
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +6 -6
  105. package/src/device/blindtilt.ts +44 -17
  106. package/src/device/bot.ts +224 -407
  107. package/src/device/ceilinglight.ts +57 -33
  108. package/src/device/colorbulb.ts +55 -31
  109. package/src/device/contact.ts +48 -19
  110. package/src/device/curtain.ts +19 -6
  111. package/src/device/device.ts +36 -3
  112. package/src/device/fan.ts +44 -19
  113. package/src/device/hub.ts +46 -18
  114. package/src/device/humidifier.ts +44 -20
  115. package/src/device/iosensor.ts +46 -18
  116. package/src/device/lightstrip.ts +60 -33
  117. package/src/device/lock.ts +49 -17
  118. package/src/device/meter.ts +46 -18
  119. package/src/device/meterplus.ts +46 -18
  120. package/src/device/motion.ts +46 -18
  121. package/src/device/plug.ts +38 -18
  122. package/src/device/robotvacuumcleaner.ts +41 -17
  123. package/src/device/waterdetector.ts +40 -16
  124. package/src/irdevice/airconditioner.ts +11 -2
  125. package/src/irdevice/airpurifier.ts +8 -0
  126. package/src/irdevice/camera.ts +4 -0
  127. package/src/irdevice/fan.ts +4 -0
  128. package/src/irdevice/irdevice.ts +35 -2
  129. package/src/irdevice/light.ts +12 -0
  130. package/src/irdevice/other.ts +254 -283
  131. package/src/irdevice/tv.ts +12 -0
  132. package/src/irdevice/vacuumcleaner.ts +4 -0
  133. package/src/irdevice/waterheater.ts +1 -1
  134. package/src/platform.ts +11 -2
  135. package/src/types/bledevicestatus.ts +1 -0
  136. package/src/utils.ts +15 -0
@@ -43,13 +43,20 @@ export abstract class irdeviceBase {
43
43
  .getService(this.hap.Service.AccessoryInformation)!
44
44
  .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
45
45
  .setCharacteristic(this.hap.Characteristic.AppMatchingIdentifier, 'id1087374760')
46
- .setCharacteristic(this.hap.Characteristic.Name, device.configDeviceName ?? device.deviceName ?? accessory.displayName)
47
- .setCharacteristic(this.hap.Characteristic.ConfiguredName, device.configDeviceName ?? device.deviceName ?? accessory.displayName)
46
+ .setCharacteristic(this.hap.Characteristic.Name, this.validName(accessory, device))
47
+ .setCharacteristic(this.hap.Characteristic.ConfiguredName, this.validName(accessory, device))
48
48
  .setCharacteristic(this.hap.Characteristic.Model, accessory.context.model ?? 'Unknown')
49
49
  .setCharacteristic(this.hap.Characteristic.ProductData, accessory.context.deviceId)
50
50
  .setCharacteristic(this.hap.Characteristic.SerialNumber, accessory.context.deviceId);
51
51
  }
52
52
 
53
+ public validName(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) {
54
+ const Name = device.configDeviceName ?? device.deviceName ?? accessory.displayName;
55
+ const NameOfName = device.configDeviceName ? 'configDeviceName' : device.deviceName ? 'deviceName' : 'displayName';
56
+ const validName = this.validateAndCleanString(Name, NameOfName, Name);
57
+ return validName;
58
+ }
59
+
53
60
  async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
54
61
  if (this.platform.debugMode) {
55
62
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
@@ -346,6 +353,32 @@ export abstract class irdeviceBase {
346
353
  }
347
354
  }
348
355
 
356
+ /**
357
+ * Validate and clean a string value for a Name Characteristic.
358
+ * @param displayName
359
+ * @param name
360
+ * @param value
361
+ * @returns string value
362
+ */
363
+ validateAndCleanString(displayName: string, name: string, value: string): string {
364
+ const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9 ']*[a-zA-Z0-9]$/;
365
+ const invalidCharsPattern = /[^a-zA-Z0-9 ']/g;
366
+
367
+ if (!validPattern.test(value)) {
368
+ this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric,`
369
+ + ' space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may'
370
+ + ' prevent the accessory from being added in the Home App or cause unresponsiveness.');
371
+
372
+ // Remove invalid characters
373
+ value = value.replace(invalidCharsPattern, '');
374
+
375
+ // Ensure it starts and ends with an alphanumeric character
376
+ value = value.replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, '');
377
+ }
378
+
379
+ return value;
380
+ }
381
+
349
382
  /**
350
383
  * Logging for Device
351
384
  */
@@ -48,6 +48,10 @@ export class Light extends irdeviceBase {
48
48
  if (!device.irlight?.stateless) {
49
49
  // Initialize LightBulb Service
50
50
  accessory.context.LightBulb = accessory.context.LightBulb ?? {};
51
+ if (accessory.context.LightBulb.Name) {
52
+ accessory.context.LightBulb.Name = this.validateAndCleanString(accessory.context.LightBulb.Name,
53
+ 'LightBulb Name', accessory.context.LightBulb.Name);
54
+ }
51
55
  this.LightBulb = {
52
56
  Name: accessory.context.LightBulb.Name ?? `${accessory.displayName} ${device.remoteType}`,
53
57
  Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb) as Service,
@@ -65,6 +69,10 @@ export class Light extends irdeviceBase {
65
69
  } else {
66
70
  // Initialize ProgrammableSwitchOn Service
67
71
  accessory.context.ProgrammableSwitchOn = accessory.context.ProgrammableSwitchOn ?? {};
72
+ if (accessory.context.ProgrammableSwitchOn.Name) {
73
+ accessory.context.ProgrammableSwitchOn.Name = this.validateAndCleanString(accessory.context.ProgrammableSwitchOn.Name,
74
+ 'ProgrammableSwitchOn Name', accessory.context.ProgrammableSwitchOn.Name);
75
+ }
68
76
  this.ProgrammableSwitchOn = {
69
77
  Name: accessory.context.ProgrammableSwitchOn.Name ?? `${accessory.displayName} ${device.remoteType} On`,
70
78
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
@@ -96,6 +104,10 @@ export class Light extends irdeviceBase {
96
104
 
97
105
  // Initialize ProgrammableSwitchOff Service
98
106
  accessory.context.ProgrammableSwitchOff = accessory.context.ProgrammableSwitchOff ?? {};
107
+ if (accessory.context.ProgrammableSwitchOff.Name) {
108
+ accessory.context.ProgrammableSwitchOff.Name = this.validateAndCleanString(accessory.context.ProgrammableSwitchOff.Name,
109
+ 'ProgrammableSwitchOff Name', accessory.context.ProgrammableSwitchOff.Name);
110
+ }
99
111
  this.ProgrammableSwitchOff = {
100
112
  Name: accessory.context.ProgrammableSwitchOff.Name ?? `${accessory.displayName} ${device.remoteType} Off`,
101
113
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)