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