@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.
- package/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
package/src/irdevices/tvs.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
4
|
-
import {
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { SwitchBotPlatform } from "../platform";
|
|
3
|
+
import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
|
|
4
|
+
import {
|
|
5
|
+
DeviceURL,
|
|
6
|
+
irdevice,
|
|
7
|
+
deviceStatusResponse,
|
|
8
|
+
irDevicesConfig,
|
|
9
|
+
payload,
|
|
10
|
+
} from "../settings";
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* Platform Accessory
|
|
@@ -41,35 +47,45 @@ export class TV {
|
|
|
41
47
|
// set accessory information
|
|
42
48
|
accessory
|
|
43
49
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
44
|
-
.setCharacteristic(
|
|
45
|
-
|
|
50
|
+
.setCharacteristic(
|
|
51
|
+
this.platform.Characteristic.Name,
|
|
52
|
+
`${device.deviceName} ${device.remoteType}`,
|
|
53
|
+
)
|
|
54
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
46
55
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
47
|
-
.setCharacteristic(
|
|
56
|
+
.setCharacteristic(
|
|
57
|
+
this.platform.Characteristic.SerialNumber,
|
|
58
|
+
device.deviceId!,
|
|
59
|
+
);
|
|
48
60
|
|
|
49
61
|
// set the accessory category
|
|
50
62
|
switch (device.remoteType) {
|
|
51
|
-
case
|
|
52
|
-
case
|
|
63
|
+
case "Speaker":
|
|
64
|
+
case "DIY Speaker":
|
|
53
65
|
accessory.category = this.platform.api.hap.Categories.SPEAKER;
|
|
54
66
|
(this.service =
|
|
55
67
|
accessory.getService(this.platform.Service.Television) ||
|
|
56
|
-
accessory.addService(this.platform.Service.Television)),
|
|
68
|
+
accessory.addService(this.platform.Service.Television)),
|
|
69
|
+
`${accessory.displayName} Speaker`;
|
|
57
70
|
break;
|
|
58
|
-
case
|
|
59
|
-
case
|
|
60
|
-
accessory.category =
|
|
71
|
+
case "IPTV":
|
|
72
|
+
case "DIY IPTV":
|
|
73
|
+
accessory.category =
|
|
74
|
+
this.platform.api.hap.Categories.TV_STREAMING_STICK;
|
|
61
75
|
(this.service =
|
|
62
76
|
accessory.getService(this.platform.Service.Television) ||
|
|
63
|
-
accessory.addService(this.platform.Service.Television)),
|
|
77
|
+
accessory.addService(this.platform.Service.Television)),
|
|
78
|
+
`${accessory.displayName} Streaming Stick`;
|
|
64
79
|
break;
|
|
65
|
-
case
|
|
66
|
-
case
|
|
67
|
-
case
|
|
68
|
-
case
|
|
80
|
+
case "DVD":
|
|
81
|
+
case "DIY DVD":
|
|
82
|
+
case "Set Top Box":
|
|
83
|
+
case "DIY Set Top Box":
|
|
69
84
|
accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
|
|
70
85
|
(this.service =
|
|
71
86
|
accessory.getService(this.platform.Service.Television) ||
|
|
72
|
-
accessory.addService(this.platform.Service.Television)),
|
|
87
|
+
accessory.addService(this.platform.Service.Television)),
|
|
88
|
+
`${accessory.displayName} Set Top Box`;
|
|
73
89
|
break;
|
|
74
90
|
default:
|
|
75
91
|
accessory.category = this.platform.api.hap.Categories.TELEVISION;
|
|
@@ -78,7 +94,8 @@ export class TV {
|
|
|
78
94
|
// you can create multiple services for each accessory
|
|
79
95
|
(this.service =
|
|
80
96
|
accessory.getService(this.platform.Service.Television) ||
|
|
81
|
-
accessory.addService(this.platform.Service.Television)),
|
|
97
|
+
accessory.addService(this.platform.Service.Television)),
|
|
98
|
+
`${accessory.displayName} TV`;
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -96,15 +113,24 @@ export class TV {
|
|
|
96
113
|
);
|
|
97
114
|
|
|
98
115
|
// handle on / off events using the Active characteristic
|
|
99
|
-
this.service
|
|
116
|
+
this.service
|
|
117
|
+
.getCharacteristic(this.platform.Characteristic.Active)
|
|
118
|
+
.onSet(this.ActiveSet.bind(this));
|
|
100
119
|
|
|
101
|
-
this.service.setCharacteristic(
|
|
120
|
+
this.service.setCharacteristic(
|
|
121
|
+
this.platform.Characteristic.ActiveIdentifier,
|
|
122
|
+
1,
|
|
123
|
+
);
|
|
102
124
|
|
|
103
125
|
// handle input source changes
|
|
104
|
-
this.service
|
|
126
|
+
this.service
|
|
127
|
+
.getCharacteristic(this.platform.Characteristic.ActiveIdentifier)
|
|
128
|
+
.onSet(this.ActiveIdentifierSet.bind(this));
|
|
105
129
|
|
|
106
130
|
// handle remote control input
|
|
107
|
-
this.service
|
|
131
|
+
this.service
|
|
132
|
+
.getCharacteristic(this.platform.Characteristic.RemoteKey)
|
|
133
|
+
.onSet(this.RemoteKeySet.bind(this));
|
|
108
134
|
|
|
109
135
|
/**
|
|
110
136
|
* Create a speaker service to allow volume control
|
|
@@ -112,12 +138,19 @@ export class TV {
|
|
|
112
138
|
// create a new Television Speaker service
|
|
113
139
|
(this.speakerService =
|
|
114
140
|
accessory.getService(this.platform.Service.TelevisionSpeaker) ||
|
|
115
|
-
accessory.addService(this.platform.Service.TelevisionSpeaker)),
|
|
141
|
+
accessory.addService(this.platform.Service.TelevisionSpeaker)),
|
|
142
|
+
`${accessory.displayName} Speaker`;
|
|
116
143
|
|
|
117
|
-
this.speakerService.setCharacteristic(
|
|
144
|
+
this.speakerService.setCharacteristic(
|
|
145
|
+
this.platform.Characteristic.Name,
|
|
146
|
+
`${accessory.displayName} Speaker`,
|
|
147
|
+
);
|
|
118
148
|
|
|
119
149
|
this.speakerService
|
|
120
|
-
.setCharacteristic(
|
|
150
|
+
.setCharacteristic(
|
|
151
|
+
this.platform.Characteristic.Active,
|
|
152
|
+
this.platform.Characteristic.Active.ACTIVE,
|
|
153
|
+
)
|
|
121
154
|
.setCharacteristic(
|
|
122
155
|
this.platform.Characteristic.VolumeControlType,
|
|
123
156
|
this.platform.Characteristic.VolumeControlType.ABSOLUTE,
|
|
@@ -130,7 +163,9 @@ export class TV {
|
|
|
130
163
|
}
|
|
131
164
|
|
|
132
165
|
private VolumeSelectorSet(value: CharacteristicValue) {
|
|
133
|
-
this.debugLog(
|
|
166
|
+
this.debugLog(
|
|
167
|
+
`${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`,
|
|
168
|
+
);
|
|
134
169
|
if (value === this.platform.Characteristic.VolumeSelector.INCREMENT) {
|
|
135
170
|
this.pushVolumeUpChanges();
|
|
136
171
|
} else {
|
|
@@ -141,61 +176,87 @@ export class TV {
|
|
|
141
176
|
private RemoteKeySet(value: CharacteristicValue) {
|
|
142
177
|
switch (value) {
|
|
143
178
|
case this.platform.Characteristic.RemoteKey.REWIND: {
|
|
144
|
-
this.debugLog(
|
|
179
|
+
this.debugLog(
|
|
180
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`,
|
|
181
|
+
);
|
|
145
182
|
break;
|
|
146
183
|
}
|
|
147
184
|
case this.platform.Characteristic.RemoteKey.FAST_FORWARD: {
|
|
148
|
-
this.debugLog(
|
|
185
|
+
this.debugLog(
|
|
186
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: FAST_FORWARD`,
|
|
187
|
+
);
|
|
149
188
|
break;
|
|
150
189
|
}
|
|
151
190
|
case this.platform.Characteristic.RemoteKey.NEXT_TRACK: {
|
|
152
|
-
this.debugLog(
|
|
191
|
+
this.debugLog(
|
|
192
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: NEXT_TRACK`,
|
|
193
|
+
);
|
|
153
194
|
break;
|
|
154
195
|
}
|
|
155
196
|
case this.platform.Characteristic.RemoteKey.PREVIOUS_TRACK: {
|
|
156
|
-
this.debugLog(
|
|
197
|
+
this.debugLog(
|
|
198
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PREVIOUS_TRACK`,
|
|
199
|
+
);
|
|
157
200
|
break;
|
|
158
201
|
}
|
|
159
202
|
case this.platform.Characteristic.RemoteKey.ARROW_UP: {
|
|
160
|
-
this.debugLog(
|
|
203
|
+
this.debugLog(
|
|
204
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_UP`,
|
|
205
|
+
);
|
|
161
206
|
//this.pushUpChanges();
|
|
162
207
|
break;
|
|
163
208
|
}
|
|
164
209
|
case this.platform.Characteristic.RemoteKey.ARROW_DOWN: {
|
|
165
|
-
this.debugLog(
|
|
210
|
+
this.debugLog(
|
|
211
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_DOWN`,
|
|
212
|
+
);
|
|
166
213
|
//this.pushDownChanges();
|
|
167
214
|
break;
|
|
168
215
|
}
|
|
169
216
|
case this.platform.Characteristic.RemoteKey.ARROW_LEFT: {
|
|
170
|
-
this.debugLog(
|
|
217
|
+
this.debugLog(
|
|
218
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_LEFT`,
|
|
219
|
+
);
|
|
171
220
|
//this.pushLeftChanges();
|
|
172
221
|
break;
|
|
173
222
|
}
|
|
174
223
|
case this.platform.Characteristic.RemoteKey.ARROW_RIGHT: {
|
|
175
|
-
this.debugLog(
|
|
224
|
+
this.debugLog(
|
|
225
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_RIGHT`,
|
|
226
|
+
);
|
|
176
227
|
//this.pushRightChanges();
|
|
177
228
|
break;
|
|
178
229
|
}
|
|
179
230
|
case this.platform.Characteristic.RemoteKey.SELECT: {
|
|
180
|
-
this.debugLog(
|
|
231
|
+
this.debugLog(
|
|
232
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: SELECT`,
|
|
233
|
+
);
|
|
181
234
|
//this.pushOkChanges();
|
|
182
235
|
break;
|
|
183
236
|
}
|
|
184
237
|
case this.platform.Characteristic.RemoteKey.BACK: {
|
|
185
|
-
this.debugLog(
|
|
238
|
+
this.debugLog(
|
|
239
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: BACK`,
|
|
240
|
+
);
|
|
186
241
|
//this.pushBackChanges();
|
|
187
242
|
break;
|
|
188
243
|
}
|
|
189
244
|
case this.platform.Characteristic.RemoteKey.EXIT: {
|
|
190
|
-
this.debugLog(
|
|
245
|
+
this.debugLog(
|
|
246
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: EXIT`,
|
|
247
|
+
);
|
|
191
248
|
break;
|
|
192
249
|
}
|
|
193
250
|
case this.platform.Characteristic.RemoteKey.PLAY_PAUSE: {
|
|
194
|
-
this.debugLog(
|
|
251
|
+
this.debugLog(
|
|
252
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PLAY_PAUSE`,
|
|
253
|
+
);
|
|
195
254
|
break;
|
|
196
255
|
}
|
|
197
256
|
case this.platform.Characteristic.RemoteKey.INFORMATION: {
|
|
198
|
-
this.debugLog(
|
|
257
|
+
this.debugLog(
|
|
258
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: INFORMATION`,
|
|
259
|
+
);
|
|
199
260
|
//this.pushMenuChanges();
|
|
200
261
|
break;
|
|
201
262
|
}
|
|
@@ -203,12 +264,16 @@ export class TV {
|
|
|
203
264
|
}
|
|
204
265
|
|
|
205
266
|
private ActiveIdentifierSet(value: CharacteristicValue) {
|
|
206
|
-
this.debugLog(
|
|
267
|
+
this.debugLog(
|
|
268
|
+
`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`,
|
|
269
|
+
);
|
|
207
270
|
this.ActiveIdentifier = value;
|
|
208
271
|
}
|
|
209
272
|
|
|
210
273
|
private ActiveSet(value: CharacteristicValue) {
|
|
211
|
-
this.debugLog(
|
|
274
|
+
this.debugLog(
|
|
275
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`,
|
|
276
|
+
);
|
|
212
277
|
if (!this.device.irtv?.disable_power) {
|
|
213
278
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
214
279
|
this.pushTvOffChanges();
|
|
@@ -223,17 +288,31 @@ export class TV {
|
|
|
223
288
|
|
|
224
289
|
private updateHomeKitCharacteristics() {
|
|
225
290
|
if (this.Active === undefined) {
|
|
226
|
-
this.debugLog(
|
|
291
|
+
this.debugLog(
|
|
292
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
293
|
+
);
|
|
227
294
|
} else {
|
|
228
|
-
this.service?.updateCharacteristic(
|
|
229
|
-
|
|
295
|
+
this.service?.updateCharacteristic(
|
|
296
|
+
this.platform.Characteristic.Active,
|
|
297
|
+
this.Active,
|
|
298
|
+
);
|
|
299
|
+
this.debugLog(
|
|
300
|
+
`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
301
|
+
);
|
|
230
302
|
}
|
|
231
303
|
if (this.ActiveIdentifier === undefined) {
|
|
232
|
-
this.debugLog(
|
|
304
|
+
this.debugLog(
|
|
305
|
+
`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`,
|
|
306
|
+
);
|
|
233
307
|
} else {
|
|
234
|
-
this.service?.updateCharacteristic(
|
|
235
|
-
|
|
236
|
-
|
|
308
|
+
this.service?.updateCharacteristic(
|
|
309
|
+
this.platform.Characteristic.ActiveIdentifier,
|
|
310
|
+
this.ActiveIdentifier,
|
|
311
|
+
);
|
|
312
|
+
this.debugLog(
|
|
313
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
314
|
+
` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`,
|
|
315
|
+
);
|
|
237
316
|
}
|
|
238
317
|
}
|
|
239
318
|
|
|
@@ -248,164 +327,197 @@ export class TV {
|
|
|
248
327
|
* TV: "command" "channelSub" "default" = previous channel
|
|
249
328
|
*/
|
|
250
329
|
async pushTvOnChanges() {
|
|
251
|
-
if (this.Active !==
|
|
330
|
+
if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
|
|
252
331
|
const payload = {
|
|
253
|
-
commandType:
|
|
254
|
-
parameter:
|
|
255
|
-
command:
|
|
332
|
+
commandType: "command",
|
|
333
|
+
parameter: "default",
|
|
334
|
+
command: "turnOn",
|
|
256
335
|
} as payload;
|
|
257
336
|
await this.pushTVChanges(payload);
|
|
258
337
|
}
|
|
259
338
|
}
|
|
260
339
|
|
|
261
340
|
async pushTvOffChanges() {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
341
|
+
if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
|
|
342
|
+
const payload = {
|
|
343
|
+
commandType: "command",
|
|
344
|
+
parameter: "default",
|
|
345
|
+
command: "turnOff",
|
|
346
|
+
} as payload;
|
|
347
|
+
await this.pushTVChanges(payload);
|
|
348
|
+
}
|
|
268
349
|
}
|
|
269
350
|
|
|
270
351
|
async pushOkChanges() {
|
|
271
352
|
const payload = {
|
|
272
|
-
commandType:
|
|
273
|
-
parameter:
|
|
274
|
-
command:
|
|
353
|
+
commandType: "command",
|
|
354
|
+
parameter: "default",
|
|
355
|
+
command: "Ok",
|
|
275
356
|
} as payload;
|
|
276
357
|
await this.pushTVChanges(payload);
|
|
277
358
|
}
|
|
278
359
|
|
|
279
360
|
async pushBackChanges() {
|
|
280
361
|
const payload = {
|
|
281
|
-
commandType:
|
|
282
|
-
parameter:
|
|
283
|
-
command:
|
|
362
|
+
commandType: "command",
|
|
363
|
+
parameter: "default",
|
|
364
|
+
command: "Back",
|
|
284
365
|
} as payload;
|
|
285
366
|
await this.pushTVChanges(payload);
|
|
286
367
|
}
|
|
287
368
|
|
|
288
369
|
async pushMenuChanges() {
|
|
289
370
|
const payload = {
|
|
290
|
-
commandType:
|
|
291
|
-
parameter:
|
|
292
|
-
command:
|
|
371
|
+
commandType: "command",
|
|
372
|
+
parameter: "default",
|
|
373
|
+
command: "Menu",
|
|
293
374
|
} as payload;
|
|
294
375
|
await this.pushTVChanges(payload);
|
|
295
376
|
}
|
|
296
377
|
|
|
297
378
|
async pushUpChanges() {
|
|
298
379
|
const payload = {
|
|
299
|
-
commandType:
|
|
300
|
-
parameter:
|
|
301
|
-
command:
|
|
380
|
+
commandType: "command",
|
|
381
|
+
parameter: "default",
|
|
382
|
+
command: "Up",
|
|
302
383
|
} as payload;
|
|
303
384
|
await this.pushTVChanges(payload);
|
|
304
385
|
}
|
|
305
386
|
|
|
306
387
|
async pushDownChanges() {
|
|
307
388
|
const payload = {
|
|
308
|
-
commandType:
|
|
309
|
-
parameter:
|
|
310
|
-
command:
|
|
389
|
+
commandType: "command",
|
|
390
|
+
parameter: "default",
|
|
391
|
+
command: "Down",
|
|
311
392
|
} as payload;
|
|
312
393
|
await this.pushTVChanges(payload);
|
|
313
394
|
}
|
|
314
395
|
|
|
315
396
|
async pushRightChanges() {
|
|
316
397
|
const payload = {
|
|
317
|
-
commandType:
|
|
318
|
-
parameter:
|
|
319
|
-
command:
|
|
398
|
+
commandType: "command",
|
|
399
|
+
parameter: "default",
|
|
400
|
+
command: "Right",
|
|
320
401
|
} as payload;
|
|
321
402
|
await this.pushTVChanges(payload);
|
|
322
403
|
}
|
|
323
404
|
|
|
324
405
|
async pushLeftChanges() {
|
|
325
406
|
const payload = {
|
|
326
|
-
commandType:
|
|
327
|
-
parameter:
|
|
328
|
-
command:
|
|
407
|
+
commandType: "command",
|
|
408
|
+
parameter: "default",
|
|
409
|
+
command: "Left",
|
|
329
410
|
} as payload;
|
|
330
411
|
await this.pushTVChanges(payload);
|
|
331
412
|
}
|
|
332
413
|
|
|
333
414
|
async pushVolumeUpChanges() {
|
|
334
415
|
const payload = {
|
|
335
|
-
commandType:
|
|
336
|
-
parameter:
|
|
337
|
-
command:
|
|
416
|
+
commandType: "command",
|
|
417
|
+
parameter: "default",
|
|
418
|
+
command: "volumeAdd",
|
|
338
419
|
} as payload;
|
|
339
420
|
await this.pushTVChanges(payload);
|
|
340
421
|
}
|
|
341
422
|
|
|
342
423
|
async pushVolumeDownChanges() {
|
|
343
424
|
const payload = {
|
|
344
|
-
commandType:
|
|
345
|
-
parameter:
|
|
346
|
-
command:
|
|
425
|
+
commandType: "command",
|
|
426
|
+
parameter: "default",
|
|
427
|
+
command: "volumeSub",
|
|
347
428
|
} as payload;
|
|
348
429
|
await this.pushTVChanges(payload);
|
|
349
430
|
}
|
|
350
431
|
|
|
351
432
|
public async pushTVChanges(payload: payload) {
|
|
352
433
|
try {
|
|
353
|
-
this.infoLog(
|
|
354
|
-
|
|
434
|
+
this.infoLog(
|
|
435
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
436
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
437
|
+
);
|
|
355
438
|
|
|
356
439
|
// Make the API request
|
|
357
|
-
const push = await this.platform.axios.post(
|
|
358
|
-
|
|
440
|
+
const push = await this.platform.axios.post(
|
|
441
|
+
`${DeviceURL}/${this.device.deviceId}/commands`,
|
|
442
|
+
payload,
|
|
443
|
+
);
|
|
444
|
+
this.debugLog(
|
|
445
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
446
|
+
);
|
|
359
447
|
this.statusCode(push);
|
|
360
448
|
this.updateHomeKitCharacteristics();
|
|
361
449
|
} catch (e: any) {
|
|
362
|
-
this.errorLog(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
450
|
+
this.errorLog(
|
|
451
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
452
|
+
);
|
|
453
|
+
if (this.deviceLogging === "debug") {
|
|
454
|
+
this.errorLog(
|
|
455
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
456
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
457
|
+
);
|
|
366
458
|
}
|
|
367
459
|
if (this.platform.debugMode) {
|
|
368
|
-
this.errorLog(
|
|
369
|
-
|
|
460
|
+
this.errorLog(
|
|
461
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
462
|
+
` Error: ${JSON.stringify(e)}`,
|
|
463
|
+
);
|
|
370
464
|
}
|
|
371
465
|
this.apiError(e);
|
|
372
466
|
}
|
|
373
467
|
}
|
|
374
468
|
|
|
375
|
-
|
|
376
|
-
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
469
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
377
470
|
switch (push.data.statusCode) {
|
|
378
471
|
case 151:
|
|
379
|
-
this.errorLog(
|
|
472
|
+
this.errorLog(
|
|
473
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
474
|
+
);
|
|
380
475
|
break;
|
|
381
476
|
case 152:
|
|
382
|
-
this.errorLog(
|
|
477
|
+
this.errorLog(
|
|
478
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`,
|
|
479
|
+
);
|
|
383
480
|
break;
|
|
384
481
|
case 160:
|
|
385
|
-
this.errorLog(
|
|
482
|
+
this.errorLog(
|
|
483
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`,
|
|
484
|
+
);
|
|
386
485
|
break;
|
|
387
486
|
case 161:
|
|
388
|
-
this.errorLog(
|
|
487
|
+
this.errorLog(
|
|
488
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`,
|
|
489
|
+
);
|
|
389
490
|
break;
|
|
390
491
|
case 171:
|
|
391
|
-
this.errorLog(
|
|
492
|
+
this.errorLog(
|
|
493
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
494
|
+
);
|
|
392
495
|
break;
|
|
393
496
|
case 190:
|
|
394
|
-
this.errorLog(
|
|
395
|
-
|
|
396
|
-
|
|
497
|
+
this.errorLog(
|
|
498
|
+
`${this.device.remoteType}: ` +
|
|
499
|
+
`${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
500
|
+
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
501
|
+
);
|
|
397
502
|
break;
|
|
398
503
|
case 100:
|
|
399
|
-
this.debugLog(
|
|
504
|
+
this.debugLog(
|
|
505
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`,
|
|
506
|
+
);
|
|
400
507
|
break;
|
|
401
508
|
default:
|
|
402
|
-
this.debugLog(
|
|
509
|
+
this.debugLog(
|
|
510
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`,
|
|
511
|
+
);
|
|
403
512
|
}
|
|
404
513
|
}
|
|
405
514
|
|
|
406
515
|
public apiError(e: any) {
|
|
407
516
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
408
|
-
this.service.updateCharacteristic(
|
|
517
|
+
this.service.updateCharacteristic(
|
|
518
|
+
this.platform.Characteristic.ActiveIdentifier,
|
|
519
|
+
e,
|
|
520
|
+
);
|
|
409
521
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
410
522
|
}
|
|
411
523
|
|
|
@@ -415,32 +527,45 @@ export class TV {
|
|
|
415
527
|
config = device.irtv;
|
|
416
528
|
}
|
|
417
529
|
if (device.logging !== undefined) {
|
|
418
|
-
config[
|
|
530
|
+
config["logging"] = device.logging;
|
|
419
531
|
}
|
|
420
532
|
if (Object.entries(config).length !== 0) {
|
|
421
|
-
this.warnLog(
|
|
533
|
+
this.warnLog(
|
|
534
|
+
`${this.device.remoteType}: ${
|
|
535
|
+
this.accessory.displayName
|
|
536
|
+
} Config: ${JSON.stringify(config)}`,
|
|
537
|
+
);
|
|
422
538
|
}
|
|
423
539
|
}
|
|
424
540
|
|
|
425
541
|
logs(device: irdevice & irDevicesConfig) {
|
|
426
542
|
if (this.platform.debugMode) {
|
|
427
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
428
|
-
this.debugLog(
|
|
543
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
544
|
+
this.debugLog(
|
|
545
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
546
|
+
);
|
|
429
547
|
} else if (device.logging) {
|
|
430
548
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
431
|
-
this.debugLog(
|
|
549
|
+
this.debugLog(
|
|
550
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
551
|
+
);
|
|
432
552
|
} else if (this.platform.config.options?.logging) {
|
|
433
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
434
|
-
|
|
553
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
554
|
+
this.platform.config.options?.logging;
|
|
555
|
+
this.debugLog(
|
|
556
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
557
|
+
);
|
|
435
558
|
} else {
|
|
436
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
437
|
-
this.debugLog(
|
|
559
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
560
|
+
this.debugLog(
|
|
561
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
562
|
+
);
|
|
438
563
|
}
|
|
439
564
|
}
|
|
440
565
|
|
|
441
566
|
/**
|
|
442
|
-
|
|
443
|
-
|
|
567
|
+
* Logging for Device
|
|
568
|
+
*/
|
|
444
569
|
infoLog(...log: any[]) {
|
|
445
570
|
if (this.enablingDeviceLogging()) {
|
|
446
571
|
this.platform.log.info(String(...log));
|
|
@@ -461,8 +586,8 @@ export class TV {
|
|
|
461
586
|
|
|
462
587
|
debugLog(...log: any[]) {
|
|
463
588
|
if (this.enablingDeviceLogging()) {
|
|
464
|
-
if (this.deviceLogging ===
|
|
465
|
-
this.platform.log.info(
|
|
589
|
+
if (this.deviceLogging === "debug") {
|
|
590
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
466
591
|
} else {
|
|
467
592
|
this.platform.log.debug(String(...log));
|
|
468
593
|
}
|
|
@@ -470,6 +595,6 @@ export class TV {
|
|
|
470
595
|
}
|
|
471
596
|
|
|
472
597
|
enablingDeviceLogging(): boolean {
|
|
473
|
-
return this.deviceLogging
|
|
598
|
+
return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
|
|
474
599
|
}
|
|
475
600
|
}
|