@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
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 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- 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 +117 -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 +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- 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 +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -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 +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 +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- 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/dist/devices/plugs.js
CHANGED
|
@@ -9,18 +9,17 @@ class Plug {
|
|
|
9
9
|
this.platform = platform;
|
|
10
10
|
this.accessory = accessory;
|
|
11
11
|
this.device = device;
|
|
12
|
-
// Config
|
|
13
|
-
this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
|
|
14
|
-
this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
15
|
-
// Bot Config
|
|
16
|
-
this.platform.device(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
|
|
17
12
|
// default placeholders
|
|
13
|
+
this.refreshRate();
|
|
14
|
+
this.logs();
|
|
18
15
|
if (this.On === undefined) {
|
|
19
16
|
this.On = false;
|
|
20
17
|
}
|
|
21
18
|
else {
|
|
22
19
|
this.On = this.accessory.context.On;
|
|
23
20
|
}
|
|
21
|
+
// Plug Config
|
|
22
|
+
this.debugLog(`Plug: ${this.accessory.displayName} Config: (offline: ${device.offline})`);
|
|
24
23
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
25
24
|
this.doPlugUpdate = new rxjs_1.Subject();
|
|
26
25
|
this.plugUpdateInProgress = false;
|
|
@@ -50,7 +49,7 @@ class Plug {
|
|
|
50
49
|
// Update Homekit
|
|
51
50
|
this.updateHomeKitCharacteristics();
|
|
52
51
|
// Start an update interval
|
|
53
|
-
(0, rxjs_1.interval)(this.
|
|
52
|
+
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
54
53
|
.pipe((0, operators_1.skipWhile)(() => this.plugUpdateInProgress))
|
|
55
54
|
.subscribe(() => {
|
|
56
55
|
this.refreshStatus();
|
|
@@ -66,20 +65,54 @@ class Plug {
|
|
|
66
65
|
await this.pushChanges();
|
|
67
66
|
}
|
|
68
67
|
catch (e) {
|
|
69
|
-
this.
|
|
70
|
-
if (this.
|
|
71
|
-
this.
|
|
68
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges`);
|
|
69
|
+
if (this.deviceLogging === 'debug') {
|
|
70
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,`
|
|
72
71
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
73
72
|
}
|
|
74
|
-
if (this.
|
|
75
|
-
this.
|
|
73
|
+
if (this.platform.debugMode) {
|
|
74
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,`
|
|
76
75
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
77
76
|
}
|
|
78
|
-
this.apiError(
|
|
77
|
+
this.apiError();
|
|
79
78
|
}
|
|
80
79
|
this.plugUpdateInProgress = false;
|
|
81
80
|
});
|
|
82
81
|
}
|
|
82
|
+
refreshRate() {
|
|
83
|
+
if (this.device.refreshRate) {
|
|
84
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
85
|
+
if (this.platform.debugMode) {
|
|
86
|
+
this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (this.platform.config.options.refreshRate) {
|
|
90
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
91
|
+
if (this.platform.debugMode) {
|
|
92
|
+
this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
logs() {
|
|
97
|
+
if (this.device.logging) {
|
|
98
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
99
|
+
if (this.platform.debugMode) {
|
|
100
|
+
this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (this.platform.config.options?.logging) {
|
|
104
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
105
|
+
if (this.platform.debugMode) {
|
|
106
|
+
this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
111
|
+
if (this.platform.debugMode) {
|
|
112
|
+
this.warnLog('Using Device Standard Logging');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
83
116
|
parseStatus() {
|
|
84
117
|
switch (this.deviceStatus.body.power) {
|
|
85
118
|
case 'on':
|
|
@@ -88,26 +121,26 @@ class Plug {
|
|
|
88
121
|
default:
|
|
89
122
|
this.On = false;
|
|
90
123
|
}
|
|
91
|
-
this.
|
|
124
|
+
this.debugLog(`Plug ${this.accessory.displayName} On: ${this.On}`);
|
|
92
125
|
}
|
|
93
126
|
async refreshStatus() {
|
|
94
127
|
try {
|
|
95
128
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
96
|
-
this.
|
|
129
|
+
this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
97
130
|
this.parseStatus();
|
|
98
131
|
this.updateHomeKitCharacteristics();
|
|
99
132
|
}
|
|
100
133
|
catch (e) {
|
|
101
|
-
this.
|
|
102
|
-
if (this.
|
|
103
|
-
this.
|
|
134
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
135
|
+
if (this.deviceLogging === 'debug') {
|
|
136
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
104
137
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
105
138
|
}
|
|
106
|
-
if (this.
|
|
107
|
-
this.
|
|
139
|
+
if (this.platform.debugMode) {
|
|
140
|
+
this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
108
141
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
109
142
|
}
|
|
110
|
-
this.apiError(
|
|
143
|
+
this.apiError();
|
|
111
144
|
}
|
|
112
145
|
}
|
|
113
146
|
/**
|
|
@@ -128,11 +161,11 @@ class Plug {
|
|
|
128
161
|
else {
|
|
129
162
|
payload.command = 'turnOff';
|
|
130
163
|
}
|
|
131
|
-
this.
|
|
164
|
+
this.infoLog(`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
132
165
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
133
166
|
// Make the API request
|
|
134
167
|
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
135
|
-
this.
|
|
168
|
+
this.debugLog(`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
136
169
|
this.statusCode(push);
|
|
137
170
|
this.OnCached = this.On;
|
|
138
171
|
this.accessory.context.On = this.OnCached;
|
|
@@ -146,44 +179,44 @@ class Plug {
|
|
|
146
179
|
}
|
|
147
180
|
updateHomeKitCharacteristics() {
|
|
148
181
|
if (this.On === undefined) {
|
|
149
|
-
this.
|
|
182
|
+
this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
|
|
150
183
|
}
|
|
151
184
|
else {
|
|
152
185
|
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
153
|
-
this.
|
|
186
|
+
this.debugLog(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
154
187
|
}
|
|
155
188
|
}
|
|
156
|
-
apiError(
|
|
157
|
-
this.
|
|
189
|
+
apiError() {
|
|
190
|
+
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */);
|
|
158
191
|
}
|
|
159
192
|
statusCode(push) {
|
|
160
193
|
switch (push.data.statusCode) {
|
|
161
194
|
case 151:
|
|
162
|
-
this.
|
|
195
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
163
196
|
break;
|
|
164
197
|
case 152:
|
|
165
|
-
this.
|
|
198
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Device not found.`);
|
|
166
199
|
break;
|
|
167
200
|
case 160:
|
|
168
|
-
this.
|
|
201
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Command is not supported.`);
|
|
169
202
|
break;
|
|
170
203
|
case 161:
|
|
171
|
-
this.
|
|
204
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Device is offline.`);
|
|
172
205
|
this.offlineOff();
|
|
173
206
|
break;
|
|
174
207
|
case 171:
|
|
175
|
-
this.
|
|
208
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
176
209
|
this.offlineOff();
|
|
177
210
|
break;
|
|
178
211
|
case 190:
|
|
179
|
-
this.
|
|
212
|
+
this.errorLog(`Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
180
213
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
181
214
|
break;
|
|
182
215
|
case 100:
|
|
183
|
-
this.
|
|
216
|
+
this.debugLog(`Plug: ${this.accessory.displayName} Command successfully sent.`);
|
|
184
217
|
break;
|
|
185
218
|
default:
|
|
186
|
-
this.
|
|
219
|
+
this.debugLog(`Plug: ${this.accessory.displayName} Unknown statusCode.`);
|
|
187
220
|
}
|
|
188
221
|
}
|
|
189
222
|
offlineOff() {
|
|
@@ -196,10 +229,41 @@ class Plug {
|
|
|
196
229
|
* Handle requests to set the value of the "On" characteristic
|
|
197
230
|
*/
|
|
198
231
|
OnSet(value) {
|
|
199
|
-
this.
|
|
232
|
+
this.debugLog(`Plug: ${this.accessory.displayName} - Set On: ${value}`);
|
|
200
233
|
this.On = value;
|
|
201
234
|
this.doPlugUpdate.next();
|
|
202
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Logging for Device
|
|
238
|
+
*/
|
|
239
|
+
infoLog(...log) {
|
|
240
|
+
if (this.enablingDeviceLogging()) {
|
|
241
|
+
this.platform.log.info(String(...log));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
warnLog(...log) {
|
|
245
|
+
if (this.enablingDeviceLogging()) {
|
|
246
|
+
this.platform.log.warn(String(...log));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
errorLog(...log) {
|
|
250
|
+
if (this.enablingDeviceLogging()) {
|
|
251
|
+
this.platform.log.error(String(...log));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
debugLog(...log) {
|
|
255
|
+
if (this.enablingDeviceLogging()) {
|
|
256
|
+
if (this.deviceLogging === 'debug') {
|
|
257
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this.platform.log.debug(String(...log));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
enablingDeviceLogging() {
|
|
265
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
266
|
+
}
|
|
203
267
|
}
|
|
204
268
|
exports.Plug = Plug;
|
|
205
269
|
//# sourceMappingURL=plugs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugs.js","sourceRoot":"","sources":["../../src/devices/plugs.ts"],"names":[],"mappings":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L: number;
|
|
31
31
|
static MODE_HEAT: number;
|
|
32
|
-
|
|
33
|
-
private readonly debugDebug;
|
|
32
|
+
deviceLogging: string;
|
|
34
33
|
constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: irdevice & irDevicesConfig);
|
|
34
|
+
logs(): void;
|
|
35
35
|
private RotationSpeedSet;
|
|
36
36
|
private RotationSpeedGet;
|
|
37
37
|
private ActiveSet;
|
|
@@ -56,6 +56,14 @@ export declare class AirConditioner {
|
|
|
56
56
|
pushAirConditionerDetailsChanges(): Promise<void>;
|
|
57
57
|
pushChanges(payload: payload): Promise<void>;
|
|
58
58
|
private statusCode;
|
|
59
|
-
apiError(
|
|
59
|
+
apiError(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Logging for Device
|
|
62
|
+
*/
|
|
63
|
+
infoLog(...log: any[]): void;
|
|
64
|
+
warnLog(...log: any[]): void;
|
|
65
|
+
errorLog(...log: any[]): void;
|
|
66
|
+
debugLog(...log: any[]): void;
|
|
67
|
+
enablingDeviceLogging(): boolean;
|
|
60
68
|
}
|
|
61
69
|
//# sourceMappingURL=airconditioners.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"airconditioners.d.ts","sourceRoot":"","sources":["../../src/irdevices/airconditioners.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAa,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"airconditioners.d.ts","sourceRoot":"","sources":["../../src/irdevices/airconditioners.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAa,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAa,iBAAiB,EAAE,OAAO,EA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;IACG,2BAA2B;IAW3B,4BAA4B;IAW5B,+BAA+B;IAW/B,gCAAgC;IAqCzB,WAAW,CAAC,OAAO,EAAE,OAAO;IA0BzC,OAAO,CAAC,UAAU;IA6BX,QAAQ;IAIf;;KAEC;IACD,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMrB,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMrB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAMtB,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE;IAUtB,qBAAqB,IAAI,OAAO;CAGjC"}
|
|
@@ -13,10 +13,8 @@ class AirConditioner {
|
|
|
13
13
|
this.accessory = accessory;
|
|
14
14
|
this.device = device;
|
|
15
15
|
this.Timeout = null;
|
|
16
|
-
// Config
|
|
17
|
-
this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
|
|
18
|
-
this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
|
|
19
16
|
// default placeholders
|
|
17
|
+
this.logs();
|
|
20
18
|
if (this.Active === undefined) {
|
|
21
19
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
22
20
|
}
|
|
@@ -107,6 +105,17 @@ class AirConditioner {
|
|
|
107
105
|
})
|
|
108
106
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
109
107
|
}
|
|
108
|
+
logs() {
|
|
109
|
+
if (this.device.logging) {
|
|
110
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
111
|
+
}
|
|
112
|
+
else if (this.platform.config.options?.logging) {
|
|
113
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
110
119
|
RotationSpeedSet(value) {
|
|
111
120
|
if (value === 4) {
|
|
112
121
|
this.CurrentFanSpeed = 1;
|
|
@@ -127,14 +136,14 @@ class AirConditioner {
|
|
|
127
136
|
return this.RotationSpeed;
|
|
128
137
|
}
|
|
129
138
|
ActiveSet(value) {
|
|
130
|
-
this.
|
|
139
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
|
|
131
140
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
132
141
|
this.pushAirConditionerOffChanges();
|
|
133
|
-
this.
|
|
142
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
134
143
|
}
|
|
135
144
|
else {
|
|
136
145
|
this.pushAirConditionerOnChanges();
|
|
137
|
-
this.
|
|
146
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
138
147
|
}
|
|
139
148
|
this.Active = value;
|
|
140
149
|
this.ActiveCached = this.Active;
|
|
@@ -142,54 +151,54 @@ class AirConditioner {
|
|
|
142
151
|
}
|
|
143
152
|
updateHomeKitCharacteristics() {
|
|
144
153
|
if (this.Active === undefined) {
|
|
145
|
-
this.
|
|
154
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
146
155
|
}
|
|
147
156
|
else {
|
|
148
157
|
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
149
|
-
this.
|
|
158
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
150
159
|
}
|
|
151
160
|
if (this.RotationSpeed === undefined) {
|
|
152
|
-
this.
|
|
161
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
153
162
|
}
|
|
154
163
|
else {
|
|
155
164
|
this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
156
|
-
this.
|
|
165
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
157
166
|
}
|
|
158
167
|
if (this.CurrentTemperature === undefined) {
|
|
159
|
-
this.
|
|
168
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
160
169
|
}
|
|
161
170
|
else {
|
|
162
171
|
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
163
|
-
this.
|
|
172
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
164
173
|
}
|
|
165
174
|
if (this.TargetHeaterCoolerState === undefined) {
|
|
166
|
-
this.
|
|
175
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
167
176
|
}
|
|
168
177
|
else {
|
|
169
178
|
this.service?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
|
|
170
|
-
this.
|
|
179
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
|
|
171
180
|
+ ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
172
181
|
}
|
|
173
182
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
174
|
-
this.
|
|
183
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
175
184
|
}
|
|
176
185
|
else {
|
|
177
186
|
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
178
|
-
this.
|
|
187
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
|
|
179
188
|
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
180
189
|
}
|
|
181
190
|
if (this.HeatingThresholdTemperature === undefined) {
|
|
182
|
-
this.
|
|
191
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
183
192
|
}
|
|
184
193
|
else {
|
|
185
194
|
this.service?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
|
|
186
|
-
this.
|
|
195
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName}`
|
|
187
196
|
+ ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
188
197
|
}
|
|
189
198
|
}
|
|
190
199
|
CurrentTemperatureGet(value) {
|
|
191
200
|
value = Number(this.CurrentTemperature) || 24;
|
|
192
|
-
this.
|
|
201
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}`);
|
|
193
202
|
this.service
|
|
194
203
|
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
195
204
|
.updateValue(value);
|
|
@@ -223,19 +232,19 @@ class AirConditioner {
|
|
|
223
232
|
else {
|
|
224
233
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
225
234
|
}
|
|
226
|
-
this.
|
|
235
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
227
236
|
return this.CurrentHeaterCoolerState;
|
|
228
237
|
}
|
|
229
238
|
HeatingThresholdTemperatureGet() {
|
|
230
239
|
this.CurrentTemperature = this.CurrentTemperature || 24;
|
|
231
|
-
this.
|
|
240
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
232
241
|
return this.CurrentTemperature;
|
|
233
242
|
}
|
|
234
243
|
HeatingThresholdTemperatureSet(value) {
|
|
235
244
|
this.pushAirConditionerStatusChanges();
|
|
236
245
|
this.LastTemperature = Number(this.CurrentTemperature);
|
|
237
246
|
this.CurrentTemperature = Number(value);
|
|
238
|
-
this.
|
|
247
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature},`
|
|
239
248
|
+ ` LastTemperature: ${this.LastTemperature}`);
|
|
240
249
|
}
|
|
241
250
|
/**
|
|
@@ -313,64 +322,90 @@ class AirConditioner {
|
|
|
313
322
|
}
|
|
314
323
|
async pushChanges(payload) {
|
|
315
324
|
try {
|
|
316
|
-
this.
|
|
325
|
+
this.infoLog(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
317
326
|
+ ` parameter: [${payload.parameter}], commandType: ${payload.commandType}`);
|
|
318
327
|
// Make the API request
|
|
319
328
|
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
320
|
-
this.
|
|
329
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
321
330
|
this.statusCode(push);
|
|
322
331
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
323
332
|
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
324
333
|
this.updateHomeKitCharacteristics();
|
|
325
334
|
}
|
|
326
335
|
catch (e) {
|
|
327
|
-
this.
|
|
328
|
-
if (this.
|
|
329
|
-
this.
|
|
336
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
|
|
337
|
+
if (this.deviceLogging === 'debug') {
|
|
338
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,`
|
|
330
339
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
331
340
|
}
|
|
332
|
-
if (this.
|
|
333
|
-
this.
|
|
341
|
+
if (this.platform.debugMode) {
|
|
342
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,`
|
|
334
343
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
335
344
|
}
|
|
336
|
-
this.apiError(
|
|
345
|
+
this.apiError();
|
|
337
346
|
}
|
|
338
347
|
}
|
|
339
348
|
statusCode(push) {
|
|
340
349
|
switch (push.data.statusCode) {
|
|
341
350
|
case 151:
|
|
342
|
-
this.
|
|
351
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
343
352
|
break;
|
|
344
353
|
case 152:
|
|
345
|
-
this.
|
|
354
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device not found.`);
|
|
346
355
|
break;
|
|
347
356
|
case 160:
|
|
348
|
-
this.
|
|
357
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command is not supported.`);
|
|
349
358
|
break;
|
|
350
359
|
case 161:
|
|
351
|
-
this.
|
|
360
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device is offline.`);
|
|
352
361
|
break;
|
|
353
362
|
case 171:
|
|
354
|
-
this.
|
|
363
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
355
364
|
break;
|
|
356
365
|
case 190:
|
|
357
|
-
this.
|
|
366
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
358
367
|
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
359
368
|
break;
|
|
360
369
|
case 100:
|
|
361
|
-
this.
|
|
370
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Command successfully sent.`);
|
|
362
371
|
break;
|
|
363
372
|
default:
|
|
364
|
-
this.
|
|
373
|
+
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Unknown statusCode.`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
apiError() {
|
|
377
|
+
throw new this.platform.api.hap.HapStatusError(-70402 /* SERVICE_COMMUNICATION_FAILURE */);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Logging for Device
|
|
381
|
+
*/
|
|
382
|
+
infoLog(...log) {
|
|
383
|
+
if (this.enablingDeviceLogging()) {
|
|
384
|
+
this.platform.log.info(String(...log));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
warnLog(...log) {
|
|
388
|
+
if (this.enablingDeviceLogging()) {
|
|
389
|
+
this.platform.log.warn(String(...log));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
errorLog(...log) {
|
|
393
|
+
if (this.enablingDeviceLogging()) {
|
|
394
|
+
this.platform.log.error(String(...log));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
debugLog(...log) {
|
|
398
|
+
if (this.enablingDeviceLogging()) {
|
|
399
|
+
if (this.deviceLogging === 'debug') {
|
|
400
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
this.platform.log.debug(String(...log));
|
|
404
|
+
}
|
|
365
405
|
}
|
|
366
406
|
}
|
|
367
|
-
|
|
368
|
-
this.
|
|
369
|
-
this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
370
|
-
this.service.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
371
|
-
this.service.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
|
|
372
|
-
this.service.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
373
|
-
this.service.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
|
|
407
|
+
enablingDeviceLogging() {
|
|
408
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
374
409
|
}
|
|
375
410
|
}
|
|
376
411
|
exports.AirConditioner = AirConditioner;
|