@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0

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 (104) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/extensions.json +5 -0
  3. package/.vscode/settings.json +15 -0
  4. package/dist/devices/bots.d.ts +34 -35
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +241 -184
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +50 -50
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +145 -131
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/contact.d.ts +27 -29
  13. package/dist/devices/contact.d.ts.map +1 -1
  14. package/dist/devices/contact.js +138 -115
  15. package/dist/devices/contact.js.map +1 -1
  16. package/dist/devices/curtains.d.ts +29 -31
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +211 -176
  19. package/dist/devices/curtains.js.map +1 -1
  20. package/dist/devices/humidifiers.d.ts +33 -33
  21. package/dist/devices/humidifiers.d.ts.map +1 -1
  22. package/dist/devices/humidifiers.js +214 -189
  23. package/dist/devices/humidifiers.js.map +1 -1
  24. package/dist/devices/meters.d.ts +30 -31
  25. package/dist/devices/meters.d.ts.map +1 -1
  26. package/dist/devices/meters.js +124 -100
  27. package/dist/devices/meters.js.map +1 -1
  28. package/dist/devices/motion.d.ts +25 -26
  29. package/dist/devices/motion.d.ts.map +1 -1
  30. package/dist/devices/motion.js +120 -102
  31. package/dist/devices/motion.js.map +1 -1
  32. package/dist/devices/plugs.d.ts +23 -23
  33. package/dist/devices/plugs.d.ts.map +1 -1
  34. package/dist/devices/plugs.js +81 -63
  35. package/dist/devices/plugs.js.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +22 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/irdevices/airconditioners.d.ts +6 -6
  41. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  42. package/dist/irdevices/airconditioners.js +105 -79
  43. package/dist/irdevices/airconditioners.js.map +1 -1
  44. package/dist/irdevices/airpurifiers.d.ts +5 -5
  45. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  46. package/dist/irdevices/airpurifiers.js +56 -42
  47. package/dist/irdevices/airpurifiers.js.map +1 -1
  48. package/dist/irdevices/cameras.d.ts +5 -5
  49. package/dist/irdevices/cameras.d.ts.map +1 -1
  50. package/dist/irdevices/cameras.js +31 -27
  51. package/dist/irdevices/cameras.js.map +1 -1
  52. package/dist/irdevices/fans.d.ts +5 -5
  53. package/dist/irdevices/fans.d.ts.map +1 -1
  54. package/dist/irdevices/fans.js +45 -38
  55. package/dist/irdevices/fans.js.map +1 -1
  56. package/dist/irdevices/lights.d.ts +5 -5
  57. package/dist/irdevices/lights.d.ts.map +1 -1
  58. package/dist/irdevices/lights.js +37 -33
  59. package/dist/irdevices/lights.js.map +1 -1
  60. package/dist/irdevices/others.d.ts +5 -5
  61. package/dist/irdevices/others.d.ts.map +1 -1
  62. package/dist/irdevices/others.js +34 -29
  63. package/dist/irdevices/others.js.map +1 -1
  64. package/dist/irdevices/tvs.d.ts +5 -5
  65. package/dist/irdevices/tvs.d.ts.map +1 -1
  66. package/dist/irdevices/tvs.js +91 -76
  67. package/dist/irdevices/tvs.js.map +1 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  69. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  70. package/dist/irdevices/vacuumcleaners.js +31 -27
  71. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  72. package/dist/irdevices/waterheaters.d.ts +5 -5
  73. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  74. package/dist/irdevices/waterheaters.js +31 -27
  75. package/dist/irdevices/waterheaters.js.map +1 -1
  76. package/dist/platform.d.ts +12 -12
  77. package/dist/platform.d.ts.map +1 -1
  78. package/dist/platform.js +241 -172
  79. package/dist/platform.js.map +1 -1
  80. package/dist/settings.d.ts +1 -1
  81. package/dist/settings.d.ts.map +1 -1
  82. package/dist/settings.js +4 -4
  83. package/dist/settings.js.map +1 -1
  84. package/package.json +72 -71
  85. package/src/devices/bots.ts +927 -442
  86. package/src/devices/colorbulb.ts +473 -246
  87. package/src/devices/contact.ts +381 -208
  88. package/src/devices/curtains.ts +613 -321
  89. package/src/devices/humidifiers.ts +594 -323
  90. package/src/devices/meters.ts +331 -186
  91. package/src/devices/motion.ts +327 -184
  92. package/src/devices/plugs.ts +175 -107
  93. package/src/index.ts +5 -5
  94. package/src/irdevices/airconditioners.ts +360 -149
  95. package/src/irdevices/airpurifiers.ts +178 -80
  96. package/src/irdevices/cameras.ts +109 -51
  97. package/src/irdevices/fans.ts +174 -77
  98. package/src/irdevices/lights.ts +110 -57
  99. package/src/irdevices/others.ts +137 -62
  100. package/src/irdevices/tvs.ts +249 -124
  101. package/src/irdevices/vacuumcleaners.ts +112 -52
  102. package/src/irdevices/waterheaters.ts +115 -53
  103. package/src/platform.ts +768 -357
  104. package/src/settings.ts +17 -23
@@ -1,7 +1,7 @@
1
- import { AxiosResponse } from 'axios';
2
- import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { AxiosResponse } from "axios";
2
+ import { SwitchBotPlatform } from "../platform";
3
+ import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
4
+ import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -36,15 +36,19 @@ export class Camera {
36
36
  // set accessory information
37
37
  accessory
38
38
  .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
39
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
40
40
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
41
+ .setCharacteristic(
42
+ this.platform.Characteristic.SerialNumber,
43
+ device.deviceId!,
44
+ );
42
45
 
43
46
  // get the Television service if it exists, otherwise create a new Television service
44
47
  // you can create multiple services for each accessory
45
48
  (this.service =
46
49
  accessory.getService(this.platform.Service.Switch) ||
47
- accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Camera`;
50
+ accessory.addService(this.platform.Service.Switch)),
51
+ `${accessory.displayName} Camera`;
48
52
 
49
53
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
50
54
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -52,10 +56,15 @@ export class Camera {
52
56
 
53
57
  // set the service name, this is what is displayed as the default name on the Home app
54
58
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
55
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
59
+ this.service.setCharacteristic(
60
+ this.platform.Characteristic.Name,
61
+ accessory.displayName,
62
+ );
56
63
 
57
64
  // handle on / off events using the On characteristic
58
- this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
65
+ this.service
66
+ .getCharacteristic(this.platform.Characteristic.On)
67
+ .onSet(this.OnSet.bind(this));
59
68
  }
60
69
 
61
70
  private OnSet(value: CharacteristicValue) {
@@ -72,8 +81,13 @@ export class Camera {
72
81
  if (this.On === undefined) {
73
82
  this.debugLog(`Camera: ${this.accessory.displayName} On: ${this.On}`);
74
83
  } else {
75
- this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
76
- this.debugLog(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
84
+ this.service?.updateCharacteristic(
85
+ this.platform.Characteristic.On,
86
+ this.On,
87
+ );
88
+ this.debugLog(
89
+ `Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
90
+ );
77
91
  }
78
92
  }
79
93
 
@@ -90,9 +104,9 @@ export class Camera {
90
104
  async pushOnChanges() {
91
105
  if (this.On) {
92
106
  const payload = {
93
- commandType: 'command',
94
- parameter: 'default',
95
- command: 'turnOn',
107
+ commandType: "command",
108
+ parameter: "default",
109
+ command: "turnOn",
96
110
  } as payload;
97
111
  await this.pushChanges(payload);
98
112
  }
@@ -101,9 +115,9 @@ export class Camera {
101
115
  async pushOffChanges() {
102
116
  if (!this.On) {
103
117
  const payload = {
104
- commandType: 'command',
105
- parameter: 'default',
106
- command: 'turnOff',
118
+ commandType: "command",
119
+ parameter: "default",
120
+ command: "turnOff",
107
121
  } as payload;
108
122
  await this.pushChanges(payload);
109
123
  }
@@ -111,56 +125,87 @@ export class Camera {
111
125
 
112
126
  public async pushChanges(payload: payload) {
113
127
  try {
114
- this.infoLog(`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
115
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
128
+ this.infoLog(
129
+ `Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
130
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
131
+ );
116
132
 
117
133
  // Make the API request
118
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
119
- this.debugLog(`Camera: ${this.accessory.displayName} pushChanges: ${push.data}`);
134
+ const push = await this.platform.axios.post(
135
+ `${DeviceURL}/${this.device.deviceId}/commands`,
136
+ payload,
137
+ );
138
+ this.debugLog(
139
+ `Camera: ${this.accessory.displayName} pushChanges: ${push.data}`,
140
+ );
120
141
  this.statusCode(push);
121
142
  this.updateHomeKitCharacteristics();
122
143
  this.OnCached = this.On;
123
144
  this.accessory.context.On = this.OnCached;
124
145
  } catch (e: any) {
125
- this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
126
- if (this.deviceLogging === 'debug') {
127
- this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
128
- + ` Error Message: ${JSON.stringify(e.message)}`);
146
+ this.errorLog(
147
+ `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
148
+ );
149
+ if (this.deviceLogging === "debug") {
150
+ this.errorLog(
151
+ `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
152
+ ` Error Message: ${JSON.stringify(e.message)}`,
153
+ );
129
154
  }
130
155
  if (this.platform.debugMode) {
131
- this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
132
- + ` Error: ${JSON.stringify(e)}`);
156
+ this.errorLog(
157
+ `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
158
+ ` Error: ${JSON.stringify(e)}`,
159
+ );
133
160
  }
134
161
  this.apiError(e);
135
162
  }
136
163
  }
137
164
 
138
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
165
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
139
166
  switch (push.data.statusCode) {
140
167
  case 151:
141
- this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
168
+ this.errorLog(
169
+ `Camera: ${this.accessory.displayName} Command not supported by this device type.`,
170
+ );
142
171
  break;
143
172
  case 152:
144
- this.errorLog(`Camera: ${this.accessory.displayName} Device not found.`);
173
+ this.errorLog(
174
+ `Camera: ${this.accessory.displayName} Device not found.`,
175
+ );
145
176
  break;
146
177
  case 160:
147
- this.errorLog(`Camera: ${this.accessory.displayName} Command is not supported.`);
178
+ this.errorLog(
179
+ `Camera: ${this.accessory.displayName} Command is not supported.`,
180
+ );
148
181
  break;
149
182
  case 161:
150
- this.errorLog(`Camera: ${this.accessory.displayName} Device is offline.`);
183
+ this.errorLog(
184
+ `Camera: ${this.accessory.displayName} Device is offline.`,
185
+ );
151
186
  break;
152
187
  case 171:
153
- this.errorLog(`Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
188
+ this.errorLog(
189
+ `Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
190
+ );
154
191
  break;
155
192
  case 190:
156
- this.errorLog(`Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized`
157
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
193
+ this.errorLog(
194
+ `Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
195
+ ` with server, Or command: ${JSON.stringify(
196
+ push.data,
197
+ )} format is invalid`,
198
+ );
158
199
  break;
159
200
  case 100:
160
- this.debugLog(`Camera: ${this.accessory.displayName} Command successfully sent.`);
201
+ this.debugLog(
202
+ `Camera: ${this.accessory.displayName} Command successfully sent.`,
203
+ );
161
204
  break;
162
205
  default:
163
- this.debugLog(`Camera: ${this.accessory.displayName} Unknown statusCode.`);
206
+ this.debugLog(
207
+ `Camera: ${this.accessory.displayName} Unknown statusCode.`,
208
+ );
164
209
  }
165
210
  }
166
211
 
@@ -175,32 +220,45 @@ export class Camera {
175
220
  config = device.ircam;
176
221
  }
177
222
  if (device.logging !== undefined) {
178
- config['logging'] = device.logging;
223
+ config["logging"] = device.logging;
179
224
  }
180
225
  if (Object.entries(config).length !== 0) {
181
- this.warnLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
226
+ this.warnLog(
227
+ `Camera: ${this.accessory.displayName} Config: ${JSON.stringify(
228
+ config,
229
+ )}`,
230
+ );
182
231
  }
183
232
  }
184
233
 
185
234
  logs(device: irdevice & irDevicesConfig) {
186
235
  if (this.platform.debugMode) {
187
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
188
- this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
236
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
237
+ this.debugLog(
238
+ `Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
239
+ );
189
240
  } else if (device.logging) {
190
241
  this.deviceLogging = this.accessory.context.logging = device.logging;
191
- this.debugLog(`Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
242
+ this.debugLog(
243
+ `Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
244
+ );
192
245
  } else if (this.platform.config.options?.logging) {
193
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
194
- this.debugLog(`Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
246
+ this.deviceLogging = this.accessory.context.logging =
247
+ this.platform.config.options?.logging;
248
+ this.debugLog(
249
+ `Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
250
+ );
195
251
  } else {
196
- this.deviceLogging = this.accessory.context.logging = 'standard';
197
- this.debugLog(`Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
252
+ this.deviceLogging = this.accessory.context.logging = "standard";
253
+ this.debugLog(
254
+ `Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
255
+ );
198
256
  }
199
257
  }
200
258
 
201
259
  /**
202
- * Logging for Device
203
- */
260
+ * Logging for Device
261
+ */
204
262
  infoLog(...log: any[]) {
205
263
  if (this.enablingDeviceLogging()) {
206
264
  this.platform.log.info(String(...log));
@@ -221,8 +279,8 @@ export class Camera {
221
279
 
222
280
  debugLog(...log: any[]) {
223
281
  if (this.enablingDeviceLogging()) {
224
- if (this.deviceLogging === 'debug') {
225
- this.platform.log.info('[DEBUG]', String(...log));
282
+ if (this.deviceLogging === "debug") {
283
+ this.platform.log.info("[DEBUG]", String(...log));
226
284
  } else {
227
285
  this.platform.log.debug(String(...log));
228
286
  }
@@ -230,6 +288,6 @@ export class Camera {
230
288
  }
231
289
 
232
290
  enablingDeviceLogging(): boolean {
233
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
291
+ return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
234
292
  }
235
293
  }