@switchbot/homebridge-switchbot 1.3.1-beta.9 → 1.4.1-beta.2
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 +18 -2
- package/config.schema.json +82 -32
- package/dist/devices/bots.d.ts +15 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +227 -165
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +14 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +163 -105
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +102 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +180 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +14 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +173 -133
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +17 -13
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +150 -105
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +89 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +15 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +115 -53
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +13 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +97 -46
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +13 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +85 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +12 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +73 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +12 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +83 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +12 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +74 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +12 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +80 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +12 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +90 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +12 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +73 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +12 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +73 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -6
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +6 -6
- package/src/devices/bots.ts +221 -152
- package/src/devices/colorbulb.ts +172 -108
- package/src/devices/contact.ts +109 -64
- package/src/devices/curtains.ts +190 -146
- package/src/devices/humidifiers.ts +181 -135
- package/src/devices/meters.ts +156 -105
- package/src/devices/motion.ts +95 -45
- package/src/devices/plugs.ts +121 -53
- package/src/irdevices/airconditioners.ts +102 -46
- package/src/irdevices/airpurifiers.ts +91 -31
- package/src/irdevices/cameras.ts +79 -24
- package/src/irdevices/fans.ts +89 -36
- package/src/irdevices/lights.ts +80 -25
- package/src/irdevices/others.ts +86 -31
- package/src/irdevices/tvs.ts +96 -42
- package/src/irdevices/vacuumcleaners.ts +79 -24
- package/src/irdevices/waterheaters.ts +79 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +10 -6
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/irdevices/others.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
3
|
import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -14,16 +14,24 @@ export class Others {
|
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
|
+
ActiveCached!: CharacteristicValue;
|
|
17
18
|
|
|
18
19
|
// Config
|
|
19
|
-
|
|
20
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
20
|
+
deviceLogging!: string;
|
|
21
21
|
|
|
22
22
|
constructor(
|
|
23
23
|
private readonly platform: SwitchBotPlatform,
|
|
24
24
|
private accessory: PlatformAccessory,
|
|
25
25
|
public device: irdevice & irDevicesConfig,
|
|
26
26
|
) {
|
|
27
|
+
// default placeholders
|
|
28
|
+
this.logs();
|
|
29
|
+
if (this.Active === undefined) {
|
|
30
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
31
|
+
} else {
|
|
32
|
+
this.Active = this.accessory.context.Active;
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
// set accessory information
|
|
28
36
|
accessory
|
|
29
37
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
@@ -42,26 +50,38 @@ export class Others {
|
|
|
42
50
|
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
43
51
|
} else {
|
|
44
52
|
accessory.removeService(this.service!);
|
|
45
|
-
this.
|
|
53
|
+
this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
logs() {
|
|
58
|
+
if (this.device.logging) {
|
|
59
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
60
|
+
} else if (this.platform.config.options?.logging) {
|
|
61
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
62
|
+
} else {
|
|
63
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
46
64
|
}
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
private ActiveSet(value: CharacteristicValue) {
|
|
50
|
-
this.
|
|
68
|
+
this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
|
|
51
69
|
if (this.Active) {
|
|
52
70
|
this.pushOnChanges();
|
|
53
71
|
} else {
|
|
54
72
|
this.pushOffChanges();
|
|
55
73
|
}
|
|
56
74
|
this.Active = value;
|
|
75
|
+
this.ActiveCached = this.Active;
|
|
76
|
+
this.accessory.context.Active = this.ActiveCached;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
79
|
private updateHomeKitCharacteristics() {
|
|
60
80
|
if (this.Active === undefined) {
|
|
61
|
-
this.
|
|
81
|
+
this.debugLog(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
62
82
|
} else {
|
|
63
83
|
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
64
|
-
this.
|
|
84
|
+
this.debugLog(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
65
85
|
}
|
|
66
86
|
}
|
|
67
87
|
|
|
@@ -88,13 +108,13 @@ export class Others {
|
|
|
88
108
|
await this.pushChanges(payload);
|
|
89
109
|
}
|
|
90
110
|
} else {
|
|
91
|
-
this.
|
|
111
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
|
|
92
112
|
}
|
|
93
113
|
} else {
|
|
94
|
-
this.
|
|
114
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
|
|
95
115
|
}
|
|
96
116
|
} else {
|
|
97
|
-
this.
|
|
117
|
+
this.errorLog(`Other: ${this.accessory.displayName} On Command not set`);
|
|
98
118
|
}
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -111,70 +131,105 @@ export class Others {
|
|
|
111
131
|
await this.pushChanges(payload);
|
|
112
132
|
}
|
|
113
133
|
} else {
|
|
114
|
-
this.
|
|
134
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
|
|
115
135
|
}
|
|
116
136
|
} else {
|
|
117
|
-
this.
|
|
137
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
|
|
118
138
|
}
|
|
119
139
|
} else {
|
|
120
|
-
this.
|
|
140
|
+
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set.`);
|
|
121
141
|
}
|
|
122
142
|
}
|
|
123
143
|
|
|
124
144
|
public async pushChanges(payload: payload) {
|
|
125
145
|
try {
|
|
126
|
-
this.
|
|
146
|
+
this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
127
147
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
128
148
|
|
|
129
149
|
// Make the API request
|
|
130
150
|
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
131
|
-
this.
|
|
151
|
+
this.debugLog(`Other: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
132
152
|
this.statusCode(push);
|
|
133
153
|
this.updateHomeKitCharacteristics();
|
|
134
154
|
} catch (e: any) {
|
|
135
|
-
this.
|
|
136
|
-
if (this.
|
|
137
|
-
this.
|
|
155
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
156
|
+
if (this.deviceLogging === 'debug') {
|
|
157
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
138
158
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
139
159
|
}
|
|
140
|
-
if (this.
|
|
141
|
-
this.
|
|
160
|
+
if (this.platform.debugMode) {
|
|
161
|
+
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
142
162
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
143
163
|
}
|
|
144
|
-
this.apiError(
|
|
164
|
+
this.apiError();
|
|
145
165
|
}
|
|
146
166
|
}
|
|
147
167
|
|
|
148
168
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
149
169
|
switch (push.data.statusCode) {
|
|
150
170
|
case 151:
|
|
151
|
-
this.
|
|
171
|
+
this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
152
172
|
break;
|
|
153
173
|
case 152:
|
|
154
|
-
this.
|
|
174
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device not found.`);
|
|
155
175
|
break;
|
|
156
176
|
case 160:
|
|
157
|
-
this.
|
|
177
|
+
this.errorLog(`Other: ${this.accessory.displayName} Command is not supported.`);
|
|
158
178
|
break;
|
|
159
179
|
case 161:
|
|
160
|
-
this.
|
|
180
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device is offline.`);
|
|
161
181
|
break;
|
|
162
182
|
case 171:
|
|
163
|
-
this.
|
|
183
|
+
this.errorLog(`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
164
184
|
break;
|
|
165
185
|
case 190:
|
|
166
|
-
this.
|
|
186
|
+
this.errorLog(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
167
187
|
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
168
188
|
break;
|
|
169
189
|
case 100:
|
|
170
|
-
this.
|
|
190
|
+
this.debugLog(`Other: ${this.accessory.displayName} Command successfully sent.`);
|
|
171
191
|
break;
|
|
172
192
|
default:
|
|
173
|
-
this.
|
|
193
|
+
this.debugLog(`Other: ${this.accessory.displayName} Unknown statusCode.`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public apiError() {
|
|
198
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Logging for Device
|
|
203
|
+
*/
|
|
204
|
+
infoLog(...log: any[]) {
|
|
205
|
+
if (this.enablingDeviceLogging()) {
|
|
206
|
+
this.platform.log.info(String(...log));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
warnLog(...log: any[]) {
|
|
211
|
+
if (this.enablingDeviceLogging()) {
|
|
212
|
+
this.platform.log.warn(String(...log));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
errorLog(...log: any[]) {
|
|
217
|
+
if (this.enablingDeviceLogging()) {
|
|
218
|
+
this.platform.log.error(String(...log));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
debugLog(...log: any[]) {
|
|
223
|
+
if (this.enablingDeviceLogging()) {
|
|
224
|
+
if (this.deviceLogging === 'debug') {
|
|
225
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
226
|
+
} else {
|
|
227
|
+
this.platform.log.debug(String(...log));
|
|
228
|
+
}
|
|
174
229
|
}
|
|
175
230
|
}
|
|
176
231
|
|
|
177
|
-
|
|
178
|
-
this.
|
|
232
|
+
enablingDeviceLogging(): boolean {
|
|
233
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
179
234
|
}
|
|
180
235
|
}
|
package/src/irdevices/tvs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
3
|
+
import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
|
|
4
4
|
import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -15,20 +15,28 @@ export class TV {
|
|
|
15
15
|
|
|
16
16
|
// Characteristic Values
|
|
17
17
|
Active!: CharacteristicValue;
|
|
18
|
+
ActiveCached!: CharacteristicValue;
|
|
18
19
|
ActiveIdentifier!: CharacteristicValue;
|
|
19
20
|
|
|
20
21
|
// Others
|
|
21
22
|
deviceStatus!: deviceStatusResponse;
|
|
22
23
|
|
|
23
24
|
// Config
|
|
24
|
-
|
|
25
|
-
private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
25
|
+
deviceLogging!: string;
|
|
26
26
|
|
|
27
27
|
constructor(
|
|
28
28
|
private readonly platform: SwitchBotPlatform,
|
|
29
29
|
private accessory: PlatformAccessory,
|
|
30
30
|
public device: irdevice & irDevicesConfig,
|
|
31
31
|
) {
|
|
32
|
+
// default placeholders
|
|
33
|
+
this.logs();
|
|
34
|
+
if (this.Active === undefined) {
|
|
35
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
36
|
+
} else {
|
|
37
|
+
this.Active = this.accessory.context.Active;
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
// set accessory information
|
|
33
41
|
accessory
|
|
34
42
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
@@ -120,8 +128,18 @@ export class TV {
|
|
|
120
128
|
.onSet(this.VolumeSelectorSet.bind(this));
|
|
121
129
|
}
|
|
122
130
|
|
|
131
|
+
logs() {
|
|
132
|
+
if (this.device.logging) {
|
|
133
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
134
|
+
} else if (this.platform.config.options?.logging) {
|
|
135
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
136
|
+
} else {
|
|
137
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
123
141
|
private VolumeSelectorSet(value: CharacteristicValue) {
|
|
124
|
-
this.
|
|
142
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`);
|
|
125
143
|
if (value === this.platform.Characteristic.VolumeSelector.INCREMENT) {
|
|
126
144
|
this.pushVolumeUpChanges();
|
|
127
145
|
} else {
|
|
@@ -132,61 +150,61 @@ export class TV {
|
|
|
132
150
|
private RemoteKeySet(value: CharacteristicValue) {
|
|
133
151
|
switch (value) {
|
|
134
152
|
case this.platform.Characteristic.RemoteKey.REWIND: {
|
|
135
|
-
this.
|
|
153
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`);
|
|
136
154
|
break;
|
|
137
155
|
}
|
|
138
156
|
case this.platform.Characteristic.RemoteKey.FAST_FORWARD: {
|
|
139
|
-
this.
|
|
157
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: FAST_FORWARD`);
|
|
140
158
|
break;
|
|
141
159
|
}
|
|
142
160
|
case this.platform.Characteristic.RemoteKey.NEXT_TRACK: {
|
|
143
|
-
this.
|
|
161
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: NEXT_TRACK`);
|
|
144
162
|
break;
|
|
145
163
|
}
|
|
146
164
|
case this.platform.Characteristic.RemoteKey.PREVIOUS_TRACK: {
|
|
147
|
-
this.
|
|
165
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PREVIOUS_TRACK`);
|
|
148
166
|
break;
|
|
149
167
|
}
|
|
150
168
|
case this.platform.Characteristic.RemoteKey.ARROW_UP: {
|
|
151
|
-
this.
|
|
169
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_UP`);
|
|
152
170
|
//this.pushUpChanges();
|
|
153
171
|
break;
|
|
154
172
|
}
|
|
155
173
|
case this.platform.Characteristic.RemoteKey.ARROW_DOWN: {
|
|
156
|
-
this.
|
|
174
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_DOWN`);
|
|
157
175
|
//this.pushDownChanges();
|
|
158
176
|
break;
|
|
159
177
|
}
|
|
160
178
|
case this.platform.Characteristic.RemoteKey.ARROW_LEFT: {
|
|
161
|
-
this.
|
|
179
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_LEFT`);
|
|
162
180
|
//this.pushLeftChanges();
|
|
163
181
|
break;
|
|
164
182
|
}
|
|
165
183
|
case this.platform.Characteristic.RemoteKey.ARROW_RIGHT: {
|
|
166
|
-
this.
|
|
184
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_RIGHT`);
|
|
167
185
|
//this.pushRightChanges();
|
|
168
186
|
break;
|
|
169
187
|
}
|
|
170
188
|
case this.platform.Characteristic.RemoteKey.SELECT: {
|
|
171
|
-
this.
|
|
189
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: SELECT`);
|
|
172
190
|
//this.pushOkChanges();
|
|
173
191
|
break;
|
|
174
192
|
}
|
|
175
193
|
case this.platform.Characteristic.RemoteKey.BACK: {
|
|
176
|
-
this.
|
|
194
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: BACK`);
|
|
177
195
|
//this.pushBackChanges();
|
|
178
196
|
break;
|
|
179
197
|
}
|
|
180
198
|
case this.platform.Characteristic.RemoteKey.EXIT: {
|
|
181
|
-
this.
|
|
199
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: EXIT`);
|
|
182
200
|
break;
|
|
183
201
|
}
|
|
184
202
|
case this.platform.Characteristic.RemoteKey.PLAY_PAUSE: {
|
|
185
|
-
this.
|
|
203
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PLAY_PAUSE`);
|
|
186
204
|
break;
|
|
187
205
|
}
|
|
188
206
|
case this.platform.Characteristic.RemoteKey.INFORMATION: {
|
|
189
|
-
this.
|
|
207
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: INFORMATION`);
|
|
190
208
|
//this.pushMenuChanges();
|
|
191
209
|
break;
|
|
192
210
|
}
|
|
@@ -194,12 +212,12 @@ export class TV {
|
|
|
194
212
|
}
|
|
195
213
|
|
|
196
214
|
private ActiveIdentifierSet(value: CharacteristicValue) {
|
|
197
|
-
this.
|
|
215
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
|
|
198
216
|
this.ActiveIdentifier = value;
|
|
199
217
|
}
|
|
200
218
|
|
|
201
219
|
private ActiveSet(value: CharacteristicValue) {
|
|
202
|
-
this.
|
|
220
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
203
221
|
if (!this.device.irtv?.disable_power) {
|
|
204
222
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
205
223
|
this.pushTvOffChanges();
|
|
@@ -207,21 +225,23 @@ export class TV {
|
|
|
207
225
|
this.pushTvOnChanges();
|
|
208
226
|
}
|
|
209
227
|
this.Active = value;
|
|
228
|
+
this.ActiveCached = this.Active;
|
|
229
|
+
this.accessory.context.Active = this.ActiveCached;
|
|
210
230
|
}
|
|
211
231
|
}
|
|
212
232
|
|
|
213
233
|
private updateHomeKitCharacteristics() {
|
|
214
234
|
if (this.Active === undefined) {
|
|
215
|
-
this.
|
|
235
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
216
236
|
} else {
|
|
217
237
|
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
218
|
-
this.
|
|
238
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
219
239
|
}
|
|
220
240
|
if (this.ActiveIdentifier === undefined) {
|
|
221
|
-
this.
|
|
241
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
222
242
|
} else {
|
|
223
243
|
this.service?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
|
|
224
|
-
this.
|
|
244
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
225
245
|
+ ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
226
246
|
}
|
|
227
247
|
}
|
|
@@ -339,25 +359,25 @@ export class TV {
|
|
|
339
359
|
|
|
340
360
|
public async pushTVChanges(payload: payload) {
|
|
341
361
|
try {
|
|
342
|
-
this.
|
|
362
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
343
363
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
344
364
|
|
|
345
365
|
// Make the API request
|
|
346
366
|
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
347
|
-
this.
|
|
367
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges: ${push.data}`);
|
|
348
368
|
this.statusCode(push);
|
|
349
369
|
this.updateHomeKitCharacteristics();
|
|
350
370
|
} catch (e: any) {
|
|
351
|
-
this.
|
|
352
|
-
if (this.
|
|
353
|
-
this.
|
|
371
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
372
|
+
if (this.deviceLogging === 'debug') {
|
|
373
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
354
374
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
355
375
|
}
|
|
356
|
-
if (this.
|
|
357
|
-
this.
|
|
376
|
+
if (this.platform.debugMode) {
|
|
377
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
358
378
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
359
379
|
}
|
|
360
|
-
this.apiError(
|
|
380
|
+
this.apiError();
|
|
361
381
|
}
|
|
362
382
|
}
|
|
363
383
|
|
|
@@ -365,35 +385,69 @@ export class TV {
|
|
|
365
385
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
366
386
|
switch (push.data.statusCode) {
|
|
367
387
|
case 151:
|
|
368
|
-
this.
|
|
388
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
369
389
|
break;
|
|
370
390
|
case 152:
|
|
371
|
-
this.
|
|
391
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
372
392
|
break;
|
|
373
393
|
case 160:
|
|
374
|
-
this.
|
|
394
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
375
395
|
break;
|
|
376
396
|
case 161:
|
|
377
|
-
this.
|
|
397
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
378
398
|
break;
|
|
379
399
|
case 171:
|
|
380
|
-
this.
|
|
400
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
381
401
|
break;
|
|
382
402
|
case 190:
|
|
383
|
-
this.
|
|
403
|
+
this.errorLog(`${this.device.remoteType}: `
|
|
384
404
|
+ `${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
385
405
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
386
406
|
break;
|
|
387
407
|
case 100:
|
|
388
|
-
this.
|
|
408
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
389
409
|
break;
|
|
390
410
|
default:
|
|
391
|
-
this.
|
|
411
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
public apiError() {
|
|
416
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Logging for Device
|
|
421
|
+
*/
|
|
422
|
+
infoLog(...log: any[]) {
|
|
423
|
+
if (this.enablingDeviceLogging()) {
|
|
424
|
+
this.platform.log.info(String(...log));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
warnLog(...log: any[]) {
|
|
429
|
+
if (this.enablingDeviceLogging()) {
|
|
430
|
+
this.platform.log.warn(String(...log));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
errorLog(...log: any[]) {
|
|
435
|
+
if (this.enablingDeviceLogging()) {
|
|
436
|
+
this.platform.log.error(String(...log));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
debugLog(...log: any[]) {
|
|
441
|
+
if (this.enablingDeviceLogging()) {
|
|
442
|
+
if (this.deviceLogging === 'debug') {
|
|
443
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
444
|
+
} else {
|
|
445
|
+
this.platform.log.debug(String(...log));
|
|
446
|
+
}
|
|
392
447
|
}
|
|
393
448
|
}
|
|
394
449
|
|
|
395
|
-
|
|
396
|
-
this.
|
|
397
|
-
this.service.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
|
|
450
|
+
enablingDeviceLogging(): boolean {
|
|
451
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
398
452
|
}
|
|
399
453
|
}
|