@switchbot/homebridge-switchbot 2.0.0-beta.18 → 2.0.0-beta.19
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 +1 -1
- package/config.schema.json +11 -2
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/device/lock.ts
CHANGED
|
@@ -25,6 +25,7 @@ export class Lock {
|
|
|
25
25
|
deviceStatus!: any; //deviceStatusResponse;
|
|
26
26
|
|
|
27
27
|
// Config
|
|
28
|
+
OpenAPI?: boolean;
|
|
28
29
|
scanDuration!: number;
|
|
29
30
|
deviceLogging!: string;
|
|
30
31
|
deviceRefreshRate!: number;
|
|
@@ -36,6 +37,7 @@ export class Lock {
|
|
|
36
37
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
37
38
|
// default placeholders
|
|
38
39
|
this.logs(device);
|
|
40
|
+
this.openAPI();
|
|
39
41
|
this.scan(device);
|
|
40
42
|
this.refreshRate(device);
|
|
41
43
|
this.config(device);
|
|
@@ -83,18 +85,18 @@ export class Lock {
|
|
|
83
85
|
|
|
84
86
|
// Contact Sensor Service
|
|
85
87
|
if (device.lock?.hide_contactsensor) {
|
|
86
|
-
this.debugLog(
|
|
88
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
|
|
87
89
|
this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor);
|
|
88
90
|
accessory.removeService(this.contactSensorService!);
|
|
89
91
|
} else if (!this.contactSensorService) {
|
|
90
|
-
this.debugLog(
|
|
92
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
|
|
91
93
|
(this.contactSensorService =
|
|
92
94
|
this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)),
|
|
93
95
|
`${accessory.displayName} Contact Sensor`;
|
|
94
96
|
|
|
95
97
|
this.contactSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
|
|
96
98
|
} else {
|
|
97
|
-
this.debugLog(
|
|
99
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Contact Sensor Service Not Added`);
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
// Update Homekit
|
|
@@ -120,9 +122,10 @@ export class Lock {
|
|
|
120
122
|
try {
|
|
121
123
|
await this.pushChanges();
|
|
122
124
|
} catch (e: any) {
|
|
123
|
-
this.errorLog(
|
|
125
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
124
126
|
if (this.deviceLogging.includes('debug')) {
|
|
125
|
-
this.errorLog(
|
|
127
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
128
|
+
+ ` Error Message: ${superStringify(e.message)}`);
|
|
126
129
|
}
|
|
127
130
|
this.apiError(e);
|
|
128
131
|
}
|
|
@@ -149,148 +152,157 @@ export class Lock {
|
|
|
149
152
|
default:
|
|
150
153
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
151
154
|
}
|
|
152
|
-
this.debugLog(
|
|
155
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
async refreshStatus(): Promise<void> {
|
|
156
|
-
|
|
159
|
+
if (this.OpenAPI) {
|
|
160
|
+
try {
|
|
161
|
+
const t = Date.now();
|
|
162
|
+
const nonce = 'requestID';
|
|
163
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
164
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
165
|
+
const sign = signTerm.toString('base64');
|
|
166
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
167
|
+
const options = {
|
|
168
|
+
hostname: HostDomain,
|
|
169
|
+
port: 443,
|
|
170
|
+
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
171
|
+
method: 'GET',
|
|
172
|
+
headers: {
|
|
173
|
+
Authorization: this.platform.config.credentials?.token,
|
|
174
|
+
sign: sign,
|
|
175
|
+
nonce: nonce,
|
|
176
|
+
t: t,
|
|
177
|
+
'Content-Type': 'application/json',
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
const req = https.request(options, (res) => {
|
|
181
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
182
|
+
let rawData = '';
|
|
183
|
+
res.on('data', (d) => {
|
|
184
|
+
rawData += d;
|
|
185
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
186
|
+
});
|
|
187
|
+
res.on('end', () => {
|
|
188
|
+
try {
|
|
189
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
190
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
191
|
+
this.lockState = this.deviceStatus.body.lockState;
|
|
192
|
+
this.doorState = this.deviceStatus.body.doorState;
|
|
193
|
+
this.parseStatus();
|
|
194
|
+
this.updateHomeKitCharacteristics();
|
|
195
|
+
} catch (e: any) {
|
|
196
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
req.on('error', (e: any) => {
|
|
201
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
202
|
+
});
|
|
203
|
+
req.end();
|
|
204
|
+
} catch (e: any) {
|
|
205
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
206
|
+
if (this.deviceLogging.includes('debug')) {
|
|
207
|
+
this.errorLog(
|
|
208
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
209
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
this.apiError(e);
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Pushes the requested changes to the SwitchBot API
|
|
221
|
+
* deviceType commandType Command command parameter Description
|
|
222
|
+
* Lock - "command" "lock" "default" = set to ???? state
|
|
223
|
+
* Lock - "command" "unlock" "default" = set to ???? state - LockCurrentState
|
|
224
|
+
*/
|
|
225
|
+
async pushChanges(): Promise<void> {
|
|
226
|
+
if (this.OpenAPI) {
|
|
227
|
+
// Make Push On request to the API
|
|
157
228
|
const t = Date.now();
|
|
158
229
|
const nonce = 'requestID';
|
|
159
230
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
160
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
231
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
232
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
233
|
+
.digest();
|
|
161
234
|
const sign = signTerm.toString('base64');
|
|
162
|
-
this.debugLog(
|
|
235
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
236
|
+
let command = '';
|
|
237
|
+
if (this.LockTargetState) {
|
|
238
|
+
command = 'lock';
|
|
239
|
+
} else {
|
|
240
|
+
command = 'unlock';
|
|
241
|
+
}
|
|
242
|
+
const body = superStringify({
|
|
243
|
+
'command': `${command}`,
|
|
244
|
+
'parameter': 'default',
|
|
245
|
+
'commandType': 'command',
|
|
246
|
+
});
|
|
247
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
163
248
|
const options = {
|
|
164
249
|
hostname: HostDomain,
|
|
165
250
|
port: 443,
|
|
166
|
-
path: `${DevicePath}/${this.device.deviceId}/
|
|
167
|
-
method: '
|
|
251
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
252
|
+
method: 'POST',
|
|
168
253
|
headers: {
|
|
169
|
-
Authorization: this.platform.config.credentials?.token,
|
|
170
|
-
sign: sign,
|
|
171
|
-
nonce: nonce,
|
|
172
|
-
t: t,
|
|
254
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
255
|
+
'sign': sign,
|
|
256
|
+
'nonce': nonce,
|
|
257
|
+
't': t,
|
|
173
258
|
'Content-Type': 'application/json',
|
|
259
|
+
'Content-Length': body.length,
|
|
174
260
|
},
|
|
175
261
|
};
|
|
176
|
-
const req = https.request(options,
|
|
177
|
-
this.debugLog(
|
|
178
|
-
|
|
179
|
-
res.on('data',
|
|
180
|
-
|
|
181
|
-
this.debugLog(`Lock: ${this.accessory.displayName} d: ${d}`);
|
|
182
|
-
});
|
|
183
|
-
res.on('end', () => {
|
|
184
|
-
try {
|
|
185
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
186
|
-
this.debugLog(`Lock: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
187
|
-
this.lockState = this.deviceStatus.body.lockState;
|
|
188
|
-
this.doorState = this.deviceStatus.body.doorState;
|
|
189
|
-
this.parseStatus();
|
|
190
|
-
this.updateHomeKitCharacteristics();
|
|
191
|
-
} catch (e: any) {
|
|
192
|
-
this.errorLog(`Lock: ${this.accessory.displayName} error message: ${e.message}`);
|
|
193
|
-
}
|
|
262
|
+
const req = https.request(options, res => {
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
264
|
+
this.statusCode({ res });
|
|
265
|
+
res.on('data', d => {
|
|
266
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
194
267
|
});
|
|
195
268
|
});
|
|
196
269
|
req.on('error', (e: any) => {
|
|
197
|
-
this.errorLog(
|
|
270
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
198
271
|
});
|
|
272
|
+
req.write(body);
|
|
199
273
|
req.end();
|
|
200
|
-
|
|
201
|
-
this.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.apiError(e);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Pushes the requested changes to the SwitchBot API
|
|
213
|
-
* deviceType commandType Command command parameter Description
|
|
214
|
-
* Lock - "command" "lock" "default" = set to ???? state
|
|
215
|
-
* Lock - "command" "unlock" "default" = set to ???? state - LockCurrentState
|
|
216
|
-
*/
|
|
217
|
-
async pushChanges(): Promise<void> {
|
|
218
|
-
// Make Push On request to the API
|
|
219
|
-
const t = Date.now();
|
|
220
|
-
const nonce = 'requestID';
|
|
221
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
222
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
223
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
224
|
-
.digest();
|
|
225
|
-
const sign = signTerm.toString('base64');
|
|
226
|
-
this.debugLog(`Lock: ${this.accessory.displayName} sign: ${sign}`);
|
|
227
|
-
let command = '';
|
|
228
|
-
if (this.LockTargetState) {
|
|
229
|
-
command = 'lock';
|
|
274
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
275
|
+
this.accessory.context.On = this.LockTargetState;
|
|
276
|
+
interval(5000)
|
|
277
|
+
.pipe(take(1))
|
|
278
|
+
.subscribe(async () => {
|
|
279
|
+
await this.refreshStatus();
|
|
280
|
+
});
|
|
230
281
|
} else {
|
|
231
|
-
|
|
282
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
232
283
|
}
|
|
233
|
-
const body = superStringify({
|
|
234
|
-
'command': `${command}`,
|
|
235
|
-
'parameter': 'default',
|
|
236
|
-
'commandType': 'command',
|
|
237
|
-
});
|
|
238
|
-
this.infoLog(`Lock: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
239
|
-
const options = {
|
|
240
|
-
hostname: HostDomain,
|
|
241
|
-
port: 443,
|
|
242
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
243
|
-
method: 'POST',
|
|
244
|
-
headers: {
|
|
245
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
246
|
-
'sign': sign,
|
|
247
|
-
'nonce': nonce,
|
|
248
|
-
't': t,
|
|
249
|
-
'Content-Type': 'application/json',
|
|
250
|
-
'Content-Length': body.length,
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
const req = https.request(options, res => {
|
|
254
|
-
this.debugLog(`Lock: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
255
|
-
this.statusCode({ res });
|
|
256
|
-
res.on('data', d => {
|
|
257
|
-
this.debugLog(`Lock: ${this.accessory.displayName} d: ${d}`);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
req.on('error', (e: any) => {
|
|
261
|
-
this.errorLog(`Lock: ${this.accessory.displayName} error message: ${e.message}`);
|
|
262
|
-
});
|
|
263
|
-
req.write(body);
|
|
264
|
-
req.end();
|
|
265
|
-
this.debugLog(`Lock: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
266
|
-
this.accessory.context.On = this.LockTargetState;
|
|
267
|
-
interval(5000)
|
|
268
|
-
.pipe(take(1))
|
|
269
|
-
.subscribe(async () => {
|
|
270
|
-
await this.refreshStatus();
|
|
271
|
-
});
|
|
272
284
|
}
|
|
273
285
|
|
|
274
286
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
275
287
|
if (!this.device.lock?.hide_contactsensor) {
|
|
276
288
|
if (this.ContactSensorState === undefined) {
|
|
277
|
-
this.debugLog(
|
|
289
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
278
290
|
} else {
|
|
279
291
|
this.contactSensorService?.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
280
|
-
this.debugLog(
|
|
292
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
281
293
|
}
|
|
282
294
|
}
|
|
283
295
|
if (this.LockTargetState === undefined) {
|
|
284
|
-
this.debugLog(
|
|
296
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockTargetState: ${this.LockTargetState}`);
|
|
285
297
|
} else {
|
|
286
298
|
this.lockService.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.LockTargetState);
|
|
287
|
-
this.debugLog(
|
|
299
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockTargetState: ${this.LockTargetState}`);
|
|
288
300
|
}
|
|
289
301
|
if (this.LockCurrentState === undefined) {
|
|
290
|
-
this.debugLog(
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockCurrentState: ${this.LockCurrentState}`);
|
|
291
303
|
} else {
|
|
292
304
|
this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.LockCurrentState);
|
|
293
|
-
this.debugLog(
|
|
305
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockCurrentState: ${this.LockCurrentState}`);
|
|
294
306
|
}
|
|
295
307
|
}
|
|
296
308
|
|
|
@@ -306,31 +318,31 @@ export class Lock {
|
|
|
306
318
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
307
319
|
switch (res.statusCode) {
|
|
308
320
|
case 151:
|
|
309
|
-
this.errorLog(
|
|
321
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
310
322
|
break;
|
|
311
323
|
case 152:
|
|
312
|
-
this.errorLog(
|
|
324
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
313
325
|
break;
|
|
314
326
|
case 160:
|
|
315
|
-
this.errorLog(
|
|
327
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
316
328
|
break;
|
|
317
329
|
case 161:
|
|
318
|
-
this.errorLog(
|
|
330
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
319
331
|
break;
|
|
320
332
|
case 171:
|
|
321
|
-
this.errorLog(
|
|
333
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
322
334
|
break;
|
|
323
335
|
case 190:
|
|
324
336
|
this.errorLog(
|
|
325
|
-
|
|
337
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
326
338
|
` Or command: ${superStringify(res)} format is invalid`,
|
|
327
339
|
);
|
|
328
340
|
break;
|
|
329
341
|
case 100:
|
|
330
|
-
this.debugLog(
|
|
342
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
331
343
|
break;
|
|
332
344
|
default:
|
|
333
|
-
this.debugLog(
|
|
345
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
334
346
|
}
|
|
335
347
|
}
|
|
336
348
|
|
|
@@ -338,7 +350,7 @@ export class Lock {
|
|
|
338
350
|
* Handle requests to set the value of the "On" characteristic
|
|
339
351
|
*/
|
|
340
352
|
async LockTargetStateSet(value: CharacteristicValue): Promise<void> {
|
|
341
|
-
this.debugLog(
|
|
353
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
342
354
|
|
|
343
355
|
this.LockTargetState = value;
|
|
344
356
|
this.doLockUpdate.next();
|
|
@@ -352,6 +364,9 @@ export class Lock {
|
|
|
352
364
|
if (device.ble !== undefined) {
|
|
353
365
|
config['ble'] = device.ble;
|
|
354
366
|
}
|
|
367
|
+
if (device.openAPI !== undefined) {
|
|
368
|
+
config['openAPI'] = device.openAPI;
|
|
369
|
+
}
|
|
355
370
|
if (device.logging !== undefined) {
|
|
356
371
|
config['logging'] = device.logging;
|
|
357
372
|
}
|
|
@@ -362,30 +377,39 @@ export class Lock {
|
|
|
362
377
|
config['scanDuration'] = device.scanDuration;
|
|
363
378
|
}
|
|
364
379
|
if (Object.entries(config).length !== 0) {
|
|
365
|
-
this.infoLog(
|
|
380
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
366
381
|
}
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
370
385
|
if (device.refreshRate) {
|
|
371
386
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
372
|
-
this.debugLog(
|
|
387
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
373
388
|
} else if (this.platform.config.options!.refreshRate) {
|
|
374
389
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
375
|
-
this.debugLog(
|
|
390
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async openAPI() {
|
|
395
|
+
if (!this.device.openAPI) {
|
|
396
|
+
this.OpenAPI = true;
|
|
397
|
+
} else {
|
|
398
|
+
this.OpenAPI = this.device.openAPI;
|
|
376
399
|
}
|
|
400
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
377
401
|
}
|
|
378
402
|
|
|
379
403
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
380
404
|
if (device.scanDuration) {
|
|
381
405
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
382
406
|
if (device.ble) {
|
|
383
|
-
this.debugLog(
|
|
407
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
384
408
|
}
|
|
385
409
|
} else {
|
|
386
410
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
387
411
|
if (this.device.ble) {
|
|
388
|
-
this.debugLog(
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
389
413
|
}
|
|
390
414
|
}
|
|
391
415
|
}
|
|
@@ -393,24 +417,25 @@ export class Lock {
|
|
|
393
417
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
394
418
|
if (this.platform.debugMode) {
|
|
395
419
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
396
|
-
this.debugLog(
|
|
420
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
397
421
|
} else if (device.logging) {
|
|
398
422
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
399
|
-
this.debugLog(
|
|
423
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
400
424
|
} else if (this.platform.config.options?.logging) {
|
|
401
425
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
402
|
-
this.debugLog(
|
|
426
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
403
427
|
} else {
|
|
404
428
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
405
|
-
this.debugLog(
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
406
430
|
}
|
|
407
431
|
}
|
|
408
432
|
|
|
409
433
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
410
434
|
let FirmwareRevision: string;
|
|
411
|
-
this.debugLog(
|
|
412
|
-
|
|
413
|
-
this.debugLog(
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
436
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
437
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
438
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
414
439
|
if (accessory.context.FirmwareRevision) {
|
|
415
440
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
416
441
|
} else if (device.firmware) {
|