@switchbot/homebridge-switchbot 1.4.1-beta.0 → 1.4.1-beta.4

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 (103) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/config.schema.json +83 -11
  3. package/dist/devices/bots.d.ts +12 -2
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +155 -89
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +12 -2
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +153 -84
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +12 -2
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +116 -52
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +13 -4
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +191 -124
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +12 -2
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +171 -108
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +12 -2
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +113 -49
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +12 -2
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +101 -37
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +12 -2
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +95 -31
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +10 -2
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +77 -37
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +10 -2
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +65 -25
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +10 -2
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +61 -21
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +10 -2
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +71 -30
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +10 -2
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +62 -22
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +10 -2
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +68 -28
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +10 -2
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +78 -38
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +10 -2
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +61 -21
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +10 -2
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +61 -21
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/platform.d.ts +10 -10
  72. package/dist/platform.d.ts.map +1 -1
  73. package/dist/platform.js +290 -307
  74. package/dist/platform.js.map +1 -1
  75. package/dist/settings.d.ts +4 -1
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/nodemon.json +1 -1
  79. package/package.json +10 -6
  80. package/src/devices/bots.ts +161 -89
  81. package/src/devices/colorbulb.ts +161 -86
  82. package/src/devices/contact.ts +122 -52
  83. package/src/devices/curtains.ts +199 -128
  84. package/src/devices/humidifiers.ts +177 -109
  85. package/src/devices/meters.ts +119 -49
  86. package/src/devices/motion.ts +106 -36
  87. package/src/devices/plugs.ts +99 -31
  88. package/src/irdevices/airconditioners.ts +81 -36
  89. package/src/irdevices/airpurifiers.ts +69 -24
  90. package/src/irdevices/cameras.ts +65 -20
  91. package/src/irdevices/fans.ts +75 -30
  92. package/src/irdevices/lights.ts +66 -21
  93. package/src/irdevices/others.ts +72 -27
  94. package/src/irdevices/tvs.ts +82 -37
  95. package/src/irdevices/vacuumcleaners.ts +65 -20
  96. package/src/irdevices/waterheaters.ts +65 -20
  97. package/src/platform.ts +285 -302
  98. package/src/settings.ts +4 -1
  99. package/dist/devices/indoorcam.d.ts +0 -64
  100. package/dist/devices/indoorcam.d.ts.map +0 -1
  101. package/dist/devices/indoorcam.js +0 -249
  102. package/dist/devices/indoorcam.js.map +0 -1
  103. package/src/devices/indoorcam.ts +0 -309
@@ -17,8 +17,7 @@ export class WaterHeater {
17
17
  ActiveCached!: CharacteristicValue;
18
18
 
19
19
  // Config
20
- private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
21
- private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
20
+ deviceLogging!: string;
22
21
 
23
22
  constructor(
24
23
  private readonly platform: SwitchBotPlatform,
@@ -26,6 +25,7 @@ export class WaterHeater {
26
25
  public device: irdevice & irDevicesConfig,
27
26
  ) {
28
27
  // default placeholders
28
+ this.logs();
29
29
  if (this.Active === undefined) {
30
30
  this.Active = this.platform.Characteristic.Active.INACTIVE;
31
31
  } else {
@@ -66,8 +66,18 @@ export class WaterHeater {
66
66
  this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
67
67
  }
68
68
 
69
+ logs() {
70
+ if (this.device.logging) {
71
+ this.deviceLogging = this.accessory.context.logging = this.device.logging;
72
+ } else if (this.platform.config.options?.logging) {
73
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
74
+ } else {
75
+ this.deviceLogging = this.accessory.context.logging = 'standard';
76
+ }
77
+ }
78
+
69
79
  private ActiveSet(value: CharacteristicValue) {
70
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
80
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
71
81
  if (value === this.platform.Characteristic.Active.INACTIVE) {
72
82
  this.pushWaterHeaterOffChanges();
73
83
  this.service.setCharacteristic(
@@ -85,10 +95,10 @@ export class WaterHeater {
85
95
 
86
96
  private updateHomeKitCharacteristics() {
87
97
  if (this.Active === undefined) {
88
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
98
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
89
99
  } else {
90
100
  this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
91
- this.platform.device(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
101
+ this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
92
102
  }
93
103
  }
94
104
 
@@ -126,22 +136,22 @@ export class WaterHeater {
126
136
 
127
137
  public async pushChanges(payload: payload) {
128
138
  try {
129
- this.platform.log.info(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
139
+ this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
130
140
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
131
141
 
132
142
  // Make the API request
133
143
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
134
- this.platform.debug(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
144
+ this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
135
145
  this.statusCode(push);
136
146
  this.updateHomeKitCharacteristics();
137
147
  } catch (e: any) {
138
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
139
- if (this.deviceDebug) {
140
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
148
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
149
+ if (this.deviceLogging === 'debug') {
150
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
141
151
  + ` Error Message: ${JSON.stringify(e.message)}`);
142
152
  }
143
- if (this.debugDebug) {
144
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
153
+ if (this.platform.debugMode) {
154
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
145
155
  + ` Error: ${JSON.stringify(e)}`);
146
156
  }
147
157
  this.apiError();
@@ -151,33 +161,68 @@ export class WaterHeater {
151
161
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
152
162
  switch (push.data.statusCode) {
153
163
  case 151:
154
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
164
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
155
165
  break;
156
166
  case 152:
157
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device not found.`);
167
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
158
168
  break;
159
169
  case 160:
160
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
170
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
161
171
  break;
162
172
  case 161:
163
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device is offline.`);
173
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
164
174
  break;
165
175
  case 171:
166
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
176
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
167
177
  break;
168
178
  case 190:
169
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
179
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
170
180
  + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
171
181
  break;
172
182
  case 100:
173
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
183
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
174
184
  break;
175
185
  default:
176
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
186
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
177
187
  }
178
188
  }
179
189
 
180
190
  public apiError() {
181
191
  throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
182
192
  }
193
+
194
+ /**
195
+ * Logging for Device
196
+ */
197
+ infoLog(...log: any[]) {
198
+ if (this.enablingDeviceLogging()) {
199
+ this.platform.log.info(String(...log));
200
+ }
201
+ }
202
+
203
+ warnLog(...log: any[]) {
204
+ if (this.enablingDeviceLogging()) {
205
+ this.platform.log.warn(String(...log));
206
+ }
207
+ }
208
+
209
+ errorLog(...log: any[]) {
210
+ if (this.enablingDeviceLogging()) {
211
+ this.platform.log.error(String(...log));
212
+ }
213
+ }
214
+
215
+ debugLog(...log: any[]) {
216
+ if (this.enablingDeviceLogging()) {
217
+ if (this.deviceLogging === 'debug') {
218
+ this.platform.log.info('[DEBUG]', String(...log));
219
+ } else {
220
+ this.platform.log.debug(String(...log));
221
+ }
222
+ }
223
+ }
224
+
225
+ enablingDeviceLogging(): boolean {
226
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
227
+ }
183
228
  }