@switchbot/homebridge-switchbot 2.0.0-beta.17 → 2.0.0-beta.19

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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/config.schema.json +14 -4
  3. package/dist/device/bot.d.ts +2 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +201 -163
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +2 -0
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +250 -218
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +2 -0
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +85 -66
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +2 -0
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +166 -136
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +126 -115
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +2 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +156 -130
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +2 -0
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +85 -64
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +2 -0
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +78 -59
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +2 -0
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +76 -57
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -0
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +133 -107
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +2 -0
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +224 -195
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/irdevice/airconditioner.d.ts +2 -0
  47. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  48. package/dist/irdevice/airconditioner.js +127 -105
  49. package/dist/irdevice/airconditioner.js.map +1 -1
  50. package/dist/irdevice/airpurifier.d.ts +2 -0
  51. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  52. package/dist/irdevice/airpurifier.js +83 -66
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/irdevice/camera.d.ts +8 -6
  55. package/dist/irdevice/camera.d.ts.map +1 -1
  56. package/dist/irdevice/camera.js +83 -68
  57. package/dist/irdevice/camera.js.map +1 -1
  58. package/dist/irdevice/fan.d.ts +7 -5
  59. package/dist/irdevice/fan.d.ts.map +1 -1
  60. package/dist/irdevice/fan.js +90 -75
  61. package/dist/irdevice/fan.js.map +1 -1
  62. package/dist/irdevice/light.d.ts +8 -6
  63. package/dist/irdevice/light.d.ts.map +1 -1
  64. package/dist/irdevice/light.js +83 -68
  65. package/dist/irdevice/light.js.map +1 -1
  66. package/dist/irdevice/other.d.ts +8 -6
  67. package/dist/irdevice/other.d.ts.map +1 -1
  68. package/dist/irdevice/other.js +93 -78
  69. package/dist/irdevice/other.js.map +1 -1
  70. package/dist/irdevice/tv.d.ts +8 -6
  71. package/dist/irdevice/tv.d.ts.map +1 -1
  72. package/dist/irdevice/tv.js +68 -52
  73. package/dist/irdevice/tv.js.map +1 -1
  74. package/dist/irdevice/vacuumcleaner.d.ts +8 -6
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +83 -69
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts +2 -0
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +75 -60
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/settings.d.ts +12 -11
  83. package/dist/settings.d.ts.map +1 -1
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/bot.ts +200 -163
  87. package/src/device/colorbulb.ts +252 -221
  88. package/src/device/contact.ts +85 -66
  89. package/src/device/curtain.ts +165 -136
  90. package/src/device/humidifier.ts +126 -115
  91. package/src/device/lock.ts +156 -131
  92. package/src/device/meter.ts +85 -64
  93. package/src/device/meterplus.ts +78 -59
  94. package/src/device/motion.ts +76 -57
  95. package/src/device/plug.ts +132 -107
  96. package/src/device/striplight.ts +226 -198
  97. package/src/irdevice/airconditioner.ts +126 -103
  98. package/src/irdevice/airpurifier.ts +84 -66
  99. package/src/irdevice/camera.ts +84 -68
  100. package/src/irdevice/fan.ts +91 -75
  101. package/src/irdevice/light.ts +84 -68
  102. package/src/irdevice/other.ts +94 -78
  103. package/src/irdevice/tv.ts +69 -53
  104. package/src/irdevice/vacuumcleaner.ts +83 -68
  105. package/src/irdevice/waterheater.ts +76 -60
  106. package/src/settings.ts +12 -11
@@ -21,6 +21,7 @@ export class VacuumCleaner {
21
21
 
22
22
  // Config
23
23
  deviceLogging!: string;
24
+ OpenAPI?: boolean;
24
25
 
25
26
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
26
27
  // default placeholders
@@ -57,7 +58,7 @@ export class VacuumCleaner {
57
58
  }
58
59
 
59
60
  async OnSet(value: CharacteristicValue): Promise<void> {
60
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${value}`);
61
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
61
62
  this.On = value;
62
63
  if (this.On) {
63
64
  await this.pushOnChanges();
@@ -68,22 +69,22 @@ export class VacuumCleaner {
68
69
 
69
70
  async updateHomeKitCharacteristics(): Promise<void> {
70
71
  if (this.On === undefined) {
71
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
72
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
72
73
  } else {
73
74
  this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
74
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
75
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
75
76
  }
76
77
  }
77
78
 
78
79
  /**
79
80
  * Pushes the requested changes to the SwitchBot API
80
81
  * deviceType commandType Command command parameter Description
81
- * Light: "command" "turnOff" "default" = set to OFF state
82
- * Light: "command" "turnOn" "default" = set to ON state
83
- * Light: "command" "volumeAdd" "default" = volume up
84
- * Light: "command" "volumeSub" "default" = volume down
85
- * Light: "command" "channelAdd" "default" = next channel
86
- * Light: "command" "channelSub" "default" = previous channel
82
+ * Vacuum Cleaner - "command" "turnOff" "default" = set to OFF state
83
+ * Vacuum Cleaner - "command" "turnOn" "default" = set to ON state
84
+ * Vacuum Cleaner - "command" "volumeAdd" "default" = volume up
85
+ * Vacuum Cleaner - "command" "volumeSub" "default" = volume down
86
+ * Vacuum Cleaner - "command" "channelAdd" "default" = next channel
87
+ * Vacuum Cleaner - "command" "channelSub" "default" = previous channel
87
88
  */
88
89
  async pushOnChanges(): Promise<void> {
89
90
  if (this.On) {
@@ -108,87 +109,89 @@ export class VacuumCleaner {
108
109
  }
109
110
 
110
111
  async pushChanges(body): Promise<void> {
111
- try {
112
+ if (this.OpenAPI) {
113
+ try {
112
114
  // Make Push On request to the API
113
- const t = Date.now();
114
- const nonce = 'requestID';
115
- const data = this.platform.config.credentials?.token + t + nonce;
116
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
117
- .update(Buffer.from(data, 'utf-8'))
118
- .digest();
119
- const sign = signTerm.toString('base64');
120
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} sign: ${sign}`);
121
- this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
122
- const options = {
123
- hostname: HostDomain,
124
- port: 443,
125
- path: `${DevicePath}/${this.device.deviceId}/commands`,
126
- method: 'POST',
127
- headers: {
128
- 'Authorization': this.platform.config.credentials?.token,
129
- 'sign': sign,
130
- 'nonce': nonce,
131
- 't': t,
132
- 'Content-Type': 'application/json',
133
- 'Content-Length': body.length,
134
- },
135
- };
136
- const req = https.request(options, res => {
137
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
138
- this.statusCode({ res });
139
- res.on('data', d => {
140
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} d: ${d}`);
115
+ const t = Date.now();
116
+ const nonce = 'requestID';
117
+ const data = this.platform.config.credentials?.token + t + nonce;
118
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
119
+ .update(Buffer.from(data, 'utf-8'))
120
+ .digest();
121
+ const sign = signTerm.toString('base64');
122
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
123
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
124
+ const options = {
125
+ hostname: HostDomain,
126
+ port: 443,
127
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
128
+ method: 'POST',
129
+ headers: {
130
+ 'Authorization': this.platform.config.credentials?.token,
131
+ 'sign': sign,
132
+ 'nonce': nonce,
133
+ 't': t,
134
+ 'Content-Type': 'application/json',
135
+ 'Content-Length': body.length,
136
+ },
137
+ };
138
+ const req = https.request(options, res => {
139
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
140
+ this.statusCode({ res });
141
+ res.on('data', d => {
142
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
143
+ });
141
144
  });
142
- });
143
- req.on('error', (e: any) => {
144
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} error message: ${e.message}`);
145
- });
146
- req.write(body);
147
- req.end();
148
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
149
- this.OnCached = this.On;
150
- this.accessory.context.On = this.OnCached;
151
- this.updateHomeKitCharacteristics();
152
- } catch (e: any) {
153
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
154
- if (this.deviceLogging.includes('debug')) {
155
- this.errorLog(
156
- `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
145
+ req.on('error', (e: any) => {
146
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
147
+ });
148
+ req.write(body);
149
+ req.end();
150
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
151
+ this.OnCached = this.On;
152
+ this.accessory.context.On = this.OnCached;
153
+ this.updateHomeKitCharacteristics();
154
+ } catch (e: any) {
155
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
156
+ if (this.deviceLogging.includes('debug')) {
157
+ this.errorLog(
158
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
157
159
  ` Error Message: ${superStringify(e.message)}`,
158
- );
160
+ );
161
+ }
162
+ this.apiError(e);
159
163
  }
160
- this.apiError(e);
161
164
  }
162
165
  }
163
166
 
164
167
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
165
168
  switch (res.statusCode) {
166
169
  case 151:
167
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
170
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
168
171
  break;
169
172
  case 152:
170
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
173
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
171
174
  break;
172
175
  case 160:
173
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
176
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
174
177
  break;
175
178
  case 161:
176
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
179
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
177
180
  break;
178
181
  case 171:
179
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
182
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
180
183
  break;
181
184
  case 190:
182
185
  this.errorLog(
183
- `Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
186
+ `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
184
187
  ` with server, Or command: ${superStringify(res)} format is invalid`,
185
188
  );
186
189
  break;
187
190
  case 100:
188
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
191
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
189
192
  break;
190
193
  default:
191
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`);
194
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
192
195
  }
193
196
  }
194
197
 
@@ -197,6 +200,15 @@ export class VacuumCleaner {
197
200
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
198
201
  }
199
202
 
203
+ async openAPI() {
204
+ if (!this.device.openAPI) {
205
+ this.OpenAPI = true;
206
+ } else {
207
+ this.OpenAPI = this.device.openAPI;
208
+ }
209
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
210
+ }
211
+
200
212
  async config(device: irdevice & irDevicesConfig): Promise<void> {
201
213
  let config = {};
202
214
  if (device.irvc) {
@@ -205,24 +217,27 @@ export class VacuumCleaner {
205
217
  if (device.logging !== undefined) {
206
218
  config['logging'] = device.logging;
207
219
  }
220
+ if (device.openAPI !== undefined) {
221
+ config['openAPI'] = device.openAPI;
222
+ }
208
223
  if (Object.entries(config).length !== 0) {
209
- this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${superStringify(config)}`);
224
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
210
225
  }
211
226
  }
212
227
 
213
228
  async logs(device: irdevice & irDevicesConfig): Promise<void> {
214
229
  if (this.platform.debugMode) {
215
230
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
216
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
231
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
217
232
  } else if (device.logging) {
218
233
  this.deviceLogging = this.accessory.context.logging = device.logging;
219
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
234
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
220
235
  } else if (this.platform.config.options?.logging) {
221
236
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
222
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
237
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
223
238
  } else {
224
239
  this.deviceLogging = this.accessory.context.logging = 'standard';
225
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
240
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
226
241
  }
227
242
  }
228
243
 
@@ -21,6 +21,7 @@ export class WaterHeater {
21
21
 
22
22
  // Config
23
23
  deviceLogging!: string;
24
+ OpenAPI?: boolean;
24
25
 
25
26
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
26
27
  // default placeholders
@@ -60,7 +61,7 @@ export class WaterHeater {
60
61
  }
61
62
 
62
63
  async ActiveSet(value: CharacteristicValue): Promise<void> {
63
- this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
64
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
64
65
  if (value === this.platform.Characteristic.Active.INACTIVE) {
65
66
  await this.pushWaterHeaterOffChanges();
66
67
  this.valveService.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.NOT_IN_USE);
@@ -75,10 +76,10 @@ export class WaterHeater {
75
76
 
76
77
  async updateHomeKitCharacteristics(): Promise<void> {
77
78
  if (this.Active === undefined) {
78
- this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
79
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
79
80
  } else {
80
81
  this.valveService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
81
- this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
82
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
82
83
  }
83
84
  }
84
85
 
@@ -115,84 +116,87 @@ export class WaterHeater {
115
116
  }
116
117
 
117
118
  async pushChanges(body): Promise<void> {
118
- try {
119
+ if (this.OpenAPI) {
120
+ try {
119
121
  // Make Push On request to the API
120
- const t = Date.now();
121
- const nonce = 'requestID';
122
- const data = this.platform.config.credentials?.token + t + nonce;
123
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
124
- .update(Buffer.from(data, 'utf-8'))
125
- .digest();
126
- const sign = signTerm.toString('base64');
127
- this.debugLog(`Water Heater: ${this.accessory.displayName} sign: ${sign}`);
128
- this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
129
- const options = {
130
- hostname: HostDomain,
131
- port: 443,
132
- path: `${DevicePath}/${this.device.deviceId}/commands`,
133
- method: 'POST',
134
- headers: {
135
- 'Authorization': this.platform.config.credentials?.token,
136
- 'sign': sign,
137
- 'nonce': nonce,
138
- 't': t,
139
- 'Content-Type': 'application/json',
140
- 'Content-Length': body.length,
141
- },
142
- };
143
- const req = https.request(options, res => {
144
- this.debugLog(`Water Heater: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
145
- this.statusCode({ res });
146
- res.on('data', d => {
147
- this.debugLog(`Water Heater: ${this.accessory.displayName} d: ${d}`);
122
+ const t = Date.now();
123
+ const nonce = 'requestID';
124
+ const data = this.platform.config.credentials?.token + t + nonce;
125
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
126
+ .update(Buffer.from(data, 'utf-8'))
127
+ .digest();
128
+ const sign = signTerm.toString('base64');
129
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
130
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
131
+ const options = {
132
+ hostname: HostDomain,
133
+ port: 443,
134
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
135
+ method: 'POST',
136
+ headers: {
137
+ 'Authorization': this.platform.config.credentials?.token,
138
+ 'sign': sign,
139
+ 'nonce': nonce,
140
+ 't': t,
141
+ 'Content-Type': 'application/json',
142
+ 'Content-Length': body.length,
143
+ },
144
+ };
145
+ const req = https.request(options, res => {
146
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
147
+ this.statusCode({ res });
148
+ res.on('data', d => {
149
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
150
+ });
148
151
  });
149
- });
150
- req.on('error', (e: any) => {
151
- this.errorLog(`Water Heater: ${this.accessory.displayName} error message: ${e.message}`);
152
- });
153
- req.write(body);
154
- req.end();
155
- this.debugLog(`Water Heater: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
156
- this.updateHomeKitCharacteristics();
157
- } catch (e: any) {
158
- this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
159
- if (this.deviceLogging.includes('debug')) {
160
- this.errorLog(
161
- `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
162
- );
152
+ req.on('error', (e: any) => {
153
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
154
+ });
155
+ req.write(body);
156
+ req.end();
157
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
158
+ this.updateHomeKitCharacteristics();
159
+ } catch (e: any) {
160
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
161
+ if (this.deviceLogging.includes('debug')) {
162
+ this.errorLog(
163
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
164
+ + ` Error Message: ${superStringify(e.message)}`,
165
+ );
166
+ }
167
+ this.apiError(e);
163
168
  }
164
- this.apiError(e);
165
169
  }
166
170
  }
167
171
 
168
172
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
169
173
  switch (res.statusCode) {
170
174
  case 151:
171
- this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
175
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
172
176
  break;
173
177
  case 152:
174
- this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
178
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
175
179
  break;
176
180
  case 160:
177
- this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
181
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
178
182
  break;
179
183
  case 161:
180
- this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
184
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
181
185
  break;
182
186
  case 171:
183
- this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
187
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
184
188
  break;
185
189
  case 190:
186
190
  this.errorLog(
187
- `Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
191
+ `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
188
192
  ` with server, Or command: ${superStringify(res)} format is invalid`,
189
193
  );
190
194
  break;
191
195
  case 100:
192
- this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
196
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
193
197
  break;
194
198
  default:
195
- this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
199
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
196
200
  }
197
201
  }
198
202
 
@@ -201,6 +205,15 @@ export class WaterHeater {
201
205
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
202
206
  }
203
207
 
208
+ async openAPI() {
209
+ if (!this.device.openAPI) {
210
+ this.OpenAPI = true;
211
+ } else {
212
+ this.OpenAPI = this.device.openAPI;
213
+ }
214
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
215
+ }
216
+
204
217
  async config(device: irdevice & irDevicesConfig): Promise<void> {
205
218
  let config = {};
206
219
  if (device.irwh) {
@@ -209,24 +222,27 @@ export class WaterHeater {
209
222
  if (device.logging !== undefined) {
210
223
  config['logging'] = device.logging;
211
224
  }
225
+ if (device.openAPI !== undefined) {
226
+ config['openAPI'] = device.openAPI;
227
+ }
212
228
  if (Object.entries(config).length !== 0) {
213
- this.infoLog(`Water Heater: ${this.accessory.displayName} Config: ${superStringify(config)}`);
229
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
214
230
  }
215
231
  }
216
232
 
217
233
  async logs(device: irdevice & irDevicesConfig): Promise<void> {
218
234
  if (this.platform.debugMode) {
219
235
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
220
- this.debugLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
236
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
221
237
  } else if (device.logging) {
222
238
  this.deviceLogging = this.accessory.context.logging = device.logging;
223
- this.debugLog(`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
239
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
224
240
  } else if (this.platform.config.options?.logging) {
225
241
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
226
- this.debugLog(`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
242
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
227
243
  } else {
228
244
  this.deviceLogging = this.accessory.context.logging = 'standard';
229
- this.debugLog(`Water Heater: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
245
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
230
246
  }
231
247
  }
232
248
 
package/src/settings.ts CHANGED
@@ -45,18 +45,9 @@ export interface devicesConfig extends device {
45
45
  configDeviceName?: string;
46
46
  deviceId: string;
47
47
  external?: boolean;
48
- logging?: string;
49
48
  refreshRate?: number;
50
49
  firmware?: string;
51
- bot?: bot;
52
- meter?: meter;
53
- humidifier?: humidifier;
54
- curtain?: curtain;
55
- contact?: contact;
56
- motion?: motion;
57
- colorbulb?: colorbulb;
58
- plug?: Record<any, any>;
59
- lock?: lock;
50
+ logging?: string;
60
51
  ble?: boolean;
61
52
  openAPI?: boolean;
62
53
  customBLEaddress?: string;
@@ -67,6 +58,15 @@ export interface devicesConfig extends device {
67
58
  mqttOptions?: IClientOptions;
68
59
  mqttPubOptions?: IClientOptions;
69
60
  history?: boolean;
61
+ bot?: bot;
62
+ meter?: meter;
63
+ humidifier?: humidifier;
64
+ curtain?: curtain;
65
+ contact?: contact;
66
+ motion?: motion;
67
+ colorbulb?: colorbulb;
68
+ plug?: Record<any, any>;
69
+ lock?: lock;
70
70
  }
71
71
 
72
72
  export type meter = {
@@ -127,6 +127,8 @@ export interface irDevicesConfig extends irdevice {
127
127
  deviceId: string;
128
128
  external?: boolean;
129
129
  logging?: string;
130
+ openAPI?: boolean;
131
+ hide_device?: boolean;
130
132
  irfan?: irfan;
131
133
  irair?: irair;
132
134
  irpur?: Record<any, any>;
@@ -136,7 +138,6 @@ export interface irDevicesConfig extends irdevice {
136
138
  irwh?: Record<any, any>;
137
139
  irtv?: irtv;
138
140
  other?: other;
139
- hide_device?: boolean;
140
141
  }
141
142
 
142
143
  export type irfan = {