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