@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.
- package/CHANGELOG.md +1 -1
- package/config.schema.json +14 -4
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/irdevice/other.ts
CHANGED
|
@@ -22,6 +22,7 @@ export class Others {
|
|
|
22
22
|
// Config
|
|
23
23
|
deviceLogging!: string;
|
|
24
24
|
otherDeviceType?: string;
|
|
25
|
+
OpenAPI?: boolean;
|
|
25
26
|
|
|
26
27
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
|
|
27
28
|
// default placeholders
|
|
@@ -44,15 +45,15 @@ export class Others {
|
|
|
44
45
|
// get the Television service if it exists, otherwise create a new Television service
|
|
45
46
|
// you can create multiple services for each accessory
|
|
46
47
|
if (this.otherDeviceType !== 'Fan') {
|
|
47
|
-
this.debugLog(
|
|
48
|
+
this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Removing Fanv2 Service`);
|
|
48
49
|
|
|
49
50
|
if (this.otherDeviceType === undefined) {
|
|
50
|
-
this.errorLog(
|
|
51
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
|
|
51
52
|
}
|
|
52
53
|
this.fanService = this.accessory.getService(this.platform.Service.Fanv2);
|
|
53
54
|
accessory.removeService(this.fanService!);
|
|
54
55
|
} else if (!this.fanService && this.otherDeviceType === 'Fan') {
|
|
55
|
-
this.debugLog(
|
|
56
|
+
this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Add Fanv2 Service`);
|
|
56
57
|
(this.fanService = this.accessory.getService(this.platform.Service.Fanv2) || this.accessory.addService(this.platform.Service.Fanv2)),
|
|
57
58
|
`${accessory.displayName} Fan`;
|
|
58
59
|
|
|
@@ -60,12 +61,12 @@ export class Others {
|
|
|
60
61
|
|
|
61
62
|
this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
62
63
|
} else {
|
|
63
|
-
this.debugLog(
|
|
64
|
+
this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
68
|
-
this.debugLog(
|
|
69
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
69
70
|
if (value) {
|
|
70
71
|
await this.pushOnChanges();
|
|
71
72
|
} else {
|
|
@@ -78,22 +79,22 @@ export class Others {
|
|
|
78
79
|
|
|
79
80
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
80
81
|
if (this.Active === undefined) {
|
|
81
|
-
this.debugLog(
|
|
82
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
82
83
|
} else {
|
|
83
84
|
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
84
|
-
this.debugLog(
|
|
85
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* Pushes the requested changes to the SwitchBot API
|
|
90
91
|
* deviceType commandType Command command parameter Description
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
92
|
+
* Other - "command" "turnOff" "default" = set to OFF state
|
|
93
|
+
* Other - "command" "turnOn" "default" = set to ON state
|
|
94
|
+
* Other - "command" "volumeAdd" "default" = volume up
|
|
95
|
+
* Other - "command" "volumeSub" "default" = volume down
|
|
96
|
+
* Other - "command" "channelAdd" "default" = next channel
|
|
97
|
+
* Other - "command" "channelSub" "default" = previous channel
|
|
97
98
|
*/
|
|
98
99
|
async pushOnChanges(): Promise<void> {
|
|
99
100
|
if (this.platform.config.options) {
|
|
@@ -108,13 +109,13 @@ export class Others {
|
|
|
108
109
|
await this.pushChanges(body);
|
|
109
110
|
}
|
|
110
111
|
} else {
|
|
111
|
-
this.errorLog(
|
|
112
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
|
|
112
113
|
}
|
|
113
114
|
} else {
|
|
114
|
-
this.errorLog(
|
|
115
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
|
|
115
116
|
}
|
|
116
117
|
} else {
|
|
117
|
-
this.errorLog(
|
|
118
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set`);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -131,95 +132,98 @@ export class Others {
|
|
|
131
132
|
await this.pushChanges(body);
|
|
132
133
|
}
|
|
133
134
|
} else {
|
|
134
|
-
this.errorLog(
|
|
135
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
|
|
135
136
|
}
|
|
136
137
|
} else {
|
|
137
|
-
this.errorLog(
|
|
138
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
|
|
138
139
|
}
|
|
139
140
|
} else {
|
|
140
|
-
this.errorLog(
|
|
141
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set.`);
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
async pushChanges(body): Promise<void> {
|
|
145
|
-
|
|
146
|
+
if (this.OpenAPI) {
|
|
147
|
+
try {
|
|
146
148
|
// Make Push On request to the API
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
149
|
+
const t = Date.now();
|
|
150
|
+
const nonce = 'requestID';
|
|
151
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
152
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
153
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
154
|
+
.digest();
|
|
155
|
+
const sign = signTerm.toString('base64');
|
|
156
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
157
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
158
|
+
const options = {
|
|
159
|
+
hostname: HostDomain,
|
|
160
|
+
port: 443,
|
|
161
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: {
|
|
164
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
165
|
+
'sign': sign,
|
|
166
|
+
'nonce': nonce,
|
|
167
|
+
't': t,
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
'Content-Length': body.length,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const req = https.request(options, res => {
|
|
173
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
174
|
+
this.statusCode({ res });
|
|
175
|
+
res.on('data', d => {
|
|
176
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
177
|
+
});
|
|
175
178
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
179
|
+
req.on('error', (e: any) => {
|
|
180
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
181
|
+
});
|
|
182
|
+
req.write(body);
|
|
183
|
+
req.end();
|
|
184
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
185
|
+
this.updateHomeKitCharacteristics();
|
|
186
|
+
} catch (e: any) {
|
|
187
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
188
|
+
if (this.deviceLogging.includes('debug')) {
|
|
189
|
+
this.errorLog(
|
|
190
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
191
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
this.apiError(e);
|
|
190
195
|
}
|
|
191
|
-
this.apiError(e);
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
196
200
|
switch (res.statusCode) {
|
|
197
201
|
case 151:
|
|
198
|
-
this.errorLog(
|
|
202
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
199
203
|
break;
|
|
200
204
|
case 152:
|
|
201
|
-
this.errorLog(
|
|
205
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
202
206
|
break;
|
|
203
207
|
case 160:
|
|
204
|
-
this.errorLog(
|
|
208
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
205
209
|
break;
|
|
206
210
|
case 161:
|
|
207
|
-
this.errorLog(
|
|
211
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
208
212
|
break;
|
|
209
213
|
case 171:
|
|
210
|
-
this.errorLog(
|
|
214
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
211
215
|
break;
|
|
212
216
|
case 190:
|
|
213
217
|
this.errorLog(
|
|
214
|
-
|
|
218
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
215
219
|
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
216
220
|
);
|
|
217
221
|
break;
|
|
218
222
|
case 100:
|
|
219
|
-
this.debugLog(
|
|
223
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
220
224
|
break;
|
|
221
225
|
default:
|
|
222
|
-
this.debugLog(
|
|
226
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
|
|
@@ -232,13 +236,22 @@ export class Others {
|
|
|
232
236
|
if (device.other?.deviceType) {
|
|
233
237
|
this.otherDeviceType = this.accessory.context.deviceType = device.other.deviceType;
|
|
234
238
|
if (this.deviceLogging.includes('debug') || this.deviceLogging === 'standard') {
|
|
235
|
-
this.warnLog(
|
|
239
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`);
|
|
236
240
|
}
|
|
237
241
|
} else {
|
|
238
|
-
this.errorLog(
|
|
242
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
|
|
246
|
+
async openAPI() {
|
|
247
|
+
if (!this.device.openAPI) {
|
|
248
|
+
this.OpenAPI = true;
|
|
249
|
+
} else {
|
|
250
|
+
this.OpenAPI = this.device.openAPI;
|
|
251
|
+
}
|
|
252
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
242
255
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
243
256
|
let config = {};
|
|
244
257
|
if (device.other) {
|
|
@@ -247,24 +260,27 @@ export class Others {
|
|
|
247
260
|
if (device.logging !== undefined) {
|
|
248
261
|
config['logging'] = device.logging;
|
|
249
262
|
}
|
|
263
|
+
if (device.openAPI !== undefined) {
|
|
264
|
+
config['openAPI'] = device.openAPI;
|
|
265
|
+
}
|
|
250
266
|
if (Object.entries(config).length !== 0) {
|
|
251
|
-
this.infoLog(
|
|
267
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
252
268
|
}
|
|
253
269
|
}
|
|
254
270
|
|
|
255
271
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
256
272
|
if (this.platform.debugMode) {
|
|
257
273
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
258
|
-
this.debugLog(
|
|
274
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
259
275
|
} else if (device.logging) {
|
|
260
276
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
261
|
-
this.debugLog(
|
|
277
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
262
278
|
} else if (this.platform.config.options?.logging) {
|
|
263
279
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
264
|
-
this.debugLog(
|
|
280
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
265
281
|
} else {
|
|
266
282
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
267
|
-
this.debugLog(
|
|
283
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
268
284
|
}
|
|
269
285
|
}
|
|
270
286
|
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -26,6 +26,7 @@ export class TV {
|
|
|
26
26
|
|
|
27
27
|
// Config
|
|
28
28
|
deviceLogging!: string;
|
|
29
|
+
OpenAPI?: boolean;
|
|
29
30
|
|
|
30
31
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
|
|
31
32
|
// default placeholders
|
|
@@ -229,12 +230,12 @@ export class TV {
|
|
|
229
230
|
/**
|
|
230
231
|
* Pushes the requested changes to the SwitchBot API
|
|
231
232
|
* deviceType commandType Command command parameter Description
|
|
232
|
-
* TV
|
|
233
|
-
* TV
|
|
234
|
-
* TV
|
|
235
|
-
* TV
|
|
236
|
-
* TV
|
|
237
|
-
* TV
|
|
233
|
+
* TV - "command" "turnOff" "default" = set to OFF state
|
|
234
|
+
* TV - "command" "turnOn" "default" = set to ON state
|
|
235
|
+
* TV - "command" "volumeAdd" "default" = volume up
|
|
236
|
+
* TV - "command" "volumeSub" "default" = volume down
|
|
237
|
+
* TV - "command" "channelAdd" "default" = next channel
|
|
238
|
+
* TV - "command" "channelSub" "default" = previous channel
|
|
238
239
|
*/
|
|
239
240
|
async pushTvOnChanges(): Promise<void> {
|
|
240
241
|
if (this.Active !== 1) {
|
|
@@ -338,54 +339,57 @@ export class TV {
|
|
|
338
339
|
}
|
|
339
340
|
|
|
340
341
|
async pushTVChanges(body): Promise<void> {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
342
|
+
if (this.OpenAPI) {
|
|
343
|
+
{
|
|
344
|
+
try {
|
|
345
|
+
// Make Push On request to the API
|
|
346
|
+
const t = Date.now();
|
|
347
|
+
const nonce = 'requestID';
|
|
348
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
349
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
350
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
351
|
+
.digest();
|
|
352
|
+
const sign = signTerm.toString('base64');
|
|
353
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
354
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
355
|
+
const options = {
|
|
356
|
+
hostname: HostDomain,
|
|
357
|
+
port: 443,
|
|
358
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
359
|
+
method: 'POST',
|
|
360
|
+
headers: {
|
|
361
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
362
|
+
'sign': sign,
|
|
363
|
+
'nonce': nonce,
|
|
364
|
+
't': t,
|
|
365
|
+
'Content-Type': 'application/json',
|
|
366
|
+
'Content-Length': body.length,
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
const req = https.request(options, res => {
|
|
370
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
371
|
+
this.statusCode({ res });
|
|
372
|
+
res.on('data', d => {
|
|
373
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
req.on('error', (e: any) => {
|
|
377
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
378
|
+
});
|
|
379
|
+
req.write(body);
|
|
380
|
+
req.end();
|
|
381
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
382
|
+
this.updateHomeKitCharacteristics();
|
|
383
|
+
} catch (e: any) {
|
|
384
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
385
|
+
if (this.deviceLogging.includes('debug')) {
|
|
386
|
+
this.errorLog(
|
|
387
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
385
388
|
` Error Message: ${superStringify(e.message)}`,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
this.apiError(e);
|
|
392
|
+
}}
|
|
389
393
|
}
|
|
390
394
|
}
|
|
391
395
|
|
|
@@ -427,6 +431,15 @@ export class TV {
|
|
|
427
431
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
428
432
|
}
|
|
429
433
|
|
|
434
|
+
async openAPI() {
|
|
435
|
+
if (!this.device.openAPI) {
|
|
436
|
+
this.OpenAPI = true;
|
|
437
|
+
} else {
|
|
438
|
+
this.OpenAPI = this.device.openAPI;
|
|
439
|
+
}
|
|
440
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
441
|
+
}
|
|
442
|
+
|
|
430
443
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
431
444
|
let config = {};
|
|
432
445
|
if (device.irtv) {
|
|
@@ -435,6 +448,9 @@ export class TV {
|
|
|
435
448
|
if (device.logging !== undefined) {
|
|
436
449
|
config['logging'] = device.logging;
|
|
437
450
|
}
|
|
451
|
+
if (device.openAPI !== undefined) {
|
|
452
|
+
config['openAPI'] = device.openAPI;
|
|
453
|
+
}
|
|
438
454
|
if (Object.entries(config).length !== 0) {
|
|
439
455
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
440
456
|
}
|