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