@switchbot/homebridge-switchbot 1.4.1-beta.1 → 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 +14 -0
- package/config.schema.json +82 -10
- package/dist/devices/bots.d.ts +12 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +140 -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 +138 -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 +101 -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 +173 -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 +156 -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 +98 -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 +86 -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 +80 -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 +9 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +264 -285
- 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 +1 -1
- package/src/devices/bots.ts +146 -89
- package/src/devices/colorbulb.ts +146 -86
- package/src/devices/contact.ts +107 -52
- package/src/devices/curtains.ts +182 -129
- package/src/devices/humidifiers.ts +162 -109
- package/src/devices/meters.ts +104 -49
- package/src/devices/motion.ts +91 -36
- package/src/devices/plugs.ts +84 -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 +267 -290
- 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/platform.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { Motion } from './devices/motion';
|
|
|
6
6
|
import { Contact } from './devices/contact';
|
|
7
7
|
import { Curtain } from './devices/curtains';
|
|
8
8
|
import { ColorBulb } from './devices/colorbulb';
|
|
9
|
-
import { IndoorCam } from './devices/indoorcam';
|
|
10
9
|
import { Humidifier } from './devices/humidifiers';
|
|
11
10
|
import { TV } from './irdevices/tvs';
|
|
12
11
|
import { Fan } from './irdevices/fans';
|
|
@@ -37,21 +36,20 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
37
36
|
responseType: 'json',
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
// debugMode!: boolean;
|
|
41
39
|
version = require('../package.json').version; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
42
40
|
deviceStatus!: deviceResponses;
|
|
43
41
|
registeringDevice!: boolean;
|
|
44
42
|
debugMode!: boolean;
|
|
43
|
+
platformLogging?: string;
|
|
45
44
|
|
|
46
45
|
constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
|
|
47
|
-
this.
|
|
46
|
+
this.logs();
|
|
47
|
+
this.debugLog('Finished initializing platform:', this.config.name);
|
|
48
48
|
// only load if configured
|
|
49
49
|
if (!this.config) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
54
|
-
|
|
55
53
|
// HOOBS notice
|
|
56
54
|
if (__dirname.includes('hoobs')) {
|
|
57
55
|
this.log.warn('This plugin has not been tested under HOOBS, it is highly recommended that ' +
|
|
@@ -61,15 +59,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
61
59
|
// verify the config
|
|
62
60
|
try {
|
|
63
61
|
this.verifyConfig();
|
|
64
|
-
this.
|
|
62
|
+
this.debugLog('Config OK');
|
|
65
63
|
} catch (e: any) {
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
64
|
+
this.errorLog(JSON.stringify(e.message));
|
|
65
|
+
if (this.platformLogging === 'debugMode') {
|
|
66
|
+
this.errorLog(JSON.stringify(e));
|
|
67
|
+
}
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
72
|
-
|
|
73
71
|
// setup axios interceptor to add headers / api key to each request
|
|
74
72
|
this.axios.interceptors.request.use((request: AxiosRequestConfig) => {
|
|
75
73
|
request.headers!.Authorization = this.config.credentials?.openToken;
|
|
@@ -82,23 +80,43 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
82
80
|
// in order to ensure they weren't added to homebridge already. This event can also be used
|
|
83
81
|
// to start discovery of new accessories.
|
|
84
82
|
this.api.on('didFinishLaunching', async () => {
|
|
85
|
-
|
|
83
|
+
this.debugLog('Executed didFinishLaunching callback');
|
|
86
84
|
// run the method to discover / register your devices as accessories
|
|
87
85
|
try {
|
|
88
86
|
this.discoverDevices();
|
|
89
87
|
} catch (e: any) {
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
88
|
+
this.errorLog('Failed to Discover Devices.', JSON.stringify(e.message));
|
|
89
|
+
if (this.platformLogging === 'debugMode') {
|
|
90
|
+
this.errorLog(JSON.stringify(e));
|
|
91
|
+
}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
logs() {
|
|
97
|
+
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
98
|
+
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
99
|
+
this.platformLogging = this.config.options!.logging;
|
|
100
|
+
if (this.debugMode) {
|
|
101
|
+
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
102
|
+
}
|
|
103
|
+
} else if (this.debugMode) {
|
|
104
|
+
if (this.debugMode) {
|
|
105
|
+
this.log.warn('Using debugMode Logging');
|
|
106
|
+
}
|
|
107
|
+
this.platformLogging = 'debugMode';
|
|
108
|
+
} else {
|
|
109
|
+
this.log.warn('Using Standard Logging');
|
|
110
|
+
this.platformLogging = 'standard';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
/**
|
|
97
115
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
98
116
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
99
117
|
*/
|
|
100
118
|
configureAccessory(accessory: PlatformAccessory) {
|
|
101
|
-
this.
|
|
119
|
+
this.infoLog(`Loading accessory from cache: ${accessory.displayName}`);
|
|
102
120
|
|
|
103
121
|
// add the restored accessory to the accessories cache so we can track if it has already been registered
|
|
104
122
|
this.accessories.push(accessory);
|
|
@@ -113,7 +131,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
113
131
|
* This will disable adding any device and will just output info.
|
|
114
132
|
*/
|
|
115
133
|
this.config.options = this.config.options || {};
|
|
116
|
-
this.config.options.debug;
|
|
117
134
|
|
|
118
135
|
if (this.config.options) {
|
|
119
136
|
|
|
@@ -129,7 +146,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
129
146
|
}
|
|
130
147
|
if (deviceConfig.bot) {
|
|
131
148
|
if (!deviceConfig.bot?.mode) {
|
|
132
|
-
this.
|
|
149
|
+
this.errorLog('You must set your Bot to Press or Switch Mode');
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
}
|
|
@@ -141,10 +158,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
141
158
|
for (const irDeviceConfig of this.config.options.irdevices) {
|
|
142
159
|
if (!irDeviceConfig.hide_device) {
|
|
143
160
|
if (!irDeviceConfig.deviceId) {
|
|
144
|
-
this.
|
|
161
|
+
this.errorLog('The devices config section is missing the *Device ID* in the config, Check Your Conifg.');
|
|
145
162
|
}
|
|
146
163
|
if (!irDeviceConfig.deviceId && !irDeviceConfig.configRemoteType) {
|
|
147
|
-
this.
|
|
164
|
+
this.errorLog('The devices config section is missing the *Device Type* in the config, Check Your Conifg.');
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
}
|
|
@@ -158,21 +175,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
158
175
|
if (!this.config.options.refreshRate) {
|
|
159
176
|
// default 120 seconds (2 minutes)
|
|
160
177
|
this.config.options!.refreshRate! = 120;
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
if (this.debugMode) {
|
|
179
|
+
this.warnLog('Using Default Refresh Rate (2 minutes).');
|
|
180
|
+
}
|
|
163
181
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
182
|
+
if (!this.config.options.pushRate) {
|
|
183
|
+
// default 100 milliseconds
|
|
184
|
+
this.config.options!.pushRate! = 0.1;
|
|
185
|
+
if (this.debugMode) {
|
|
186
|
+
this.warnLog('Using Default Push Rate.');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
169
189
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
if (!this.config.credentials) {
|
|
191
|
+
this.debugLog('Missing Credentials');
|
|
192
|
+
}
|
|
193
|
+
if (!this.config.credentials?.openToken) {
|
|
194
|
+
this.errorLog('Missing openToken');
|
|
195
|
+
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
196
|
+
}
|
|
176
197
|
}
|
|
177
198
|
}
|
|
178
199
|
|
|
@@ -184,13 +205,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
184
205
|
if (this.config.credentials?.openToken) {
|
|
185
206
|
const devicesAPI: any = (await this.axios.get(DeviceURL)).data;
|
|
186
207
|
this.deviceListInfo(devicesAPI);
|
|
187
|
-
this.
|
|
208
|
+
this.debugLog(JSON.stringify(devicesAPI));
|
|
188
209
|
|
|
189
210
|
// SwitchBot Devices
|
|
190
|
-
this.
|
|
211
|
+
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
191
212
|
const deviceLists = devicesAPI.body.deviceList;
|
|
192
213
|
if (!this.config.options?.devices) {
|
|
193
|
-
this.
|
|
214
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
194
215
|
const devices = deviceLists.map((v: any) => v);
|
|
195
216
|
for (const device of devices) {
|
|
196
217
|
if (device.deviceType) {
|
|
@@ -201,7 +222,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
201
222
|
}
|
|
202
223
|
}
|
|
203
224
|
} else if (this.config.credentials?.openToken && this.config.options.devices) {
|
|
204
|
-
this.
|
|
225
|
+
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
205
226
|
const deviceConfigs = this.config.options?.devices;
|
|
206
227
|
|
|
207
228
|
const mergeBydeviceId = (a1: { deviceId: string; }[], a2: any[]) =>
|
|
@@ -212,7 +233,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
212
233
|
}));
|
|
213
234
|
|
|
214
235
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
215
|
-
this.
|
|
236
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
216
237
|
for (const device of devices) {
|
|
217
238
|
if (device.deviceType) {
|
|
218
239
|
if (device.configDeviceName) {
|
|
@@ -222,13 +243,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
222
243
|
}
|
|
223
244
|
}
|
|
224
245
|
} else {
|
|
225
|
-
this.
|
|
246
|
+
this.errorLog('Neither SwitchBot OpenToken or Device Config are not set.');
|
|
226
247
|
}
|
|
227
248
|
// IR Devices
|
|
228
|
-
this.
|
|
249
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
229
250
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
230
251
|
if (!this.config.options?.irdevices) {
|
|
231
|
-
this.
|
|
252
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
232
253
|
const devices = irDeviceLists.map((v: any) => v);
|
|
233
254
|
for (const device of devices) {
|
|
234
255
|
if (device.remoteType) {
|
|
@@ -236,7 +257,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
236
257
|
}
|
|
237
258
|
}
|
|
238
259
|
} else {
|
|
239
|
-
this.
|
|
260
|
+
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
240
261
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
241
262
|
|
|
242
263
|
const mergeIRBydeviceId = (a1: { deviceId: string; }[], a2: any[]) =>
|
|
@@ -247,7 +268,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
247
268
|
}));
|
|
248
269
|
|
|
249
270
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
250
|
-
this.
|
|
271
|
+
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
251
272
|
for (const device of devices) {
|
|
252
273
|
if (device.remoteType) {
|
|
253
274
|
this.createIRDevice(device);
|
|
@@ -255,7 +276,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
255
276
|
}
|
|
256
277
|
}
|
|
257
278
|
} else if (!this.config.credentials?.openToken && this.config.options?.devices) {
|
|
258
|
-
this.
|
|
279
|
+
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
259
280
|
const deviceConfigs = this.config.options?.devices;
|
|
260
281
|
const devices = deviceConfigs.map((v: any) => v);
|
|
261
282
|
for (const device of devices) {
|
|
@@ -266,7 +287,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
} else {
|
|
269
|
-
this.
|
|
290
|
+
this.errorLog('Neither SwitchBot OpenToken or Device Config are not set.');
|
|
270
291
|
}
|
|
271
292
|
} catch (e: any) {
|
|
272
293
|
this.deviceError(e);
|
|
@@ -275,94 +296,96 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
275
296
|
|
|
276
297
|
deviceError(e: any) {
|
|
277
298
|
if (e.message.includes('400')) {
|
|
278
|
-
this.
|
|
279
|
-
this.
|
|
299
|
+
this.errorLog('Failed to Discover Devices: Bad Request');
|
|
300
|
+
this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
|
|
280
301
|
} else if (e.message.includes('401')) {
|
|
281
|
-
this.
|
|
282
|
-
this.
|
|
302
|
+
this.errorLog('Failed to Discover Devices: Unauthorized Request');
|
|
303
|
+
this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
|
|
283
304
|
} else if (e.message.includes('403')) {
|
|
284
|
-
this.
|
|
285
|
-
this.
|
|
305
|
+
this.errorLog('Failed to Discover Devices: Forbidden Request');
|
|
306
|
+
this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
|
|
286
307
|
} else if (e.message.includes('404')) {
|
|
287
|
-
this.
|
|
288
|
-
this.
|
|
308
|
+
this.errorLog('Failed to Discover Devices: Requst Not Found');
|
|
309
|
+
this.debugLog('Specifies the requested path does not exist.');
|
|
289
310
|
} else if (e.message.includes('406')) {
|
|
290
|
-
this.
|
|
291
|
-
this.
|
|
311
|
+
this.errorLog('Failed to Discover Devices: Request Not Acceptable');
|
|
312
|
+
this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
|
|
292
313
|
} else if (e.message.includes('415')) {
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
314
|
+
this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
|
|
315
|
+
this.debugLog('The client has defined a contentType header that is not supported by the server.');
|
|
295
316
|
} else if (e.message.includes('422')) {
|
|
296
|
-
this.
|
|
297
|
-
this.
|
|
317
|
+
this.errorLog('Failed to Discover Devices: Unprocessable Entity');
|
|
318
|
+
this.debugLog('The client has made a valid request, but the server cannot process it.'
|
|
298
319
|
+ ' This is often used for APIs for which certain limits have been exceeded.');
|
|
299
320
|
} else if (e.message.includes('429')) {
|
|
300
|
-
this.
|
|
301
|
-
this.
|
|
321
|
+
this.errorLog('Failed to Discover Devices: Too Many Requests');
|
|
322
|
+
this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
|
|
302
323
|
} else if (e.message.includes('500')) {
|
|
303
|
-
this.
|
|
304
|
-
this.
|
|
324
|
+
this.errorLog('Failed to Discover Devices: Internal Server Error');
|
|
325
|
+
this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
|
|
305
326
|
} else {
|
|
306
|
-
this.
|
|
327
|
+
this.errorLog('Failed to Discover Devices');
|
|
307
328
|
}
|
|
308
|
-
if (this.
|
|
309
|
-
this.
|
|
329
|
+
if (this.platformLogging === 'debug') {
|
|
330
|
+
this.errorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}`);
|
|
310
331
|
}
|
|
311
|
-
if (this.
|
|
312
|
-
this.
|
|
332
|
+
if (this.platformLogging === 'debugMode') {
|
|
333
|
+
this.errorLog(`Failed to Discover Devices, Error: ${JSON.stringify(e)}`);
|
|
313
334
|
}
|
|
314
335
|
}
|
|
315
336
|
|
|
316
337
|
private createDevice(device: device & devicesConfig) {
|
|
317
338
|
switch (device.deviceType!) {
|
|
318
339
|
case 'Humidifier':
|
|
319
|
-
this.
|
|
340
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
320
341
|
this.createHumidifier(device);
|
|
321
342
|
break;
|
|
322
343
|
case 'Hub Mini':
|
|
323
|
-
this.
|
|
344
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
324
345
|
break;
|
|
325
346
|
case 'Hub Plus':
|
|
326
|
-
this.
|
|
347
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
327
348
|
break;
|
|
328
349
|
case 'Bot':
|
|
329
|
-
this.
|
|
350
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
330
351
|
this.createBot(device);
|
|
331
352
|
break;
|
|
332
353
|
case 'Meter':
|
|
333
|
-
this.
|
|
354
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
334
355
|
this.createMeter(device);
|
|
335
356
|
break;
|
|
336
357
|
case 'Motion Sensor':
|
|
337
|
-
this.
|
|
358
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
338
359
|
this.createMotion(device);
|
|
339
360
|
break;
|
|
340
361
|
case 'Contact Sensor':
|
|
341
|
-
this.
|
|
362
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
342
363
|
this.createContact(device);
|
|
343
364
|
break;
|
|
344
365
|
case 'Curtain':
|
|
345
|
-
this.
|
|
366
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
346
367
|
this.createCurtain(device);
|
|
347
368
|
break;
|
|
348
369
|
case 'Plug':
|
|
349
|
-
this.
|
|
370
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
350
371
|
this.createPlug(device);
|
|
351
372
|
break;
|
|
352
373
|
case 'Color Bulb':
|
|
353
|
-
this.
|
|
374
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
354
375
|
this.createColorBulb(device);
|
|
355
376
|
break;
|
|
356
377
|
case 'Indoor Cam':
|
|
357
|
-
this.
|
|
358
|
-
this.
|
|
378
|
+
this.deviceInfo(device);
|
|
379
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
380
|
+
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
359
381
|
break;
|
|
360
382
|
case 'Remote':
|
|
361
|
-
this.
|
|
383
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
|
|
362
384
|
break;
|
|
363
385
|
default:
|
|
364
|
-
this.
|
|
365
|
-
this.
|
|
386
|
+
this.deviceInfo(device);
|
|
387
|
+
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
388
|
+
this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
|
|
366
389
|
}
|
|
367
390
|
}
|
|
368
391
|
|
|
@@ -380,67 +403,68 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
380
403
|
case 'DIY DVD':
|
|
381
404
|
case 'Speaker':
|
|
382
405
|
case 'DIY Speaker':
|
|
383
|
-
this.
|
|
406
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
384
407
|
this.createTV(device);
|
|
385
408
|
break;
|
|
386
409
|
case 'Fan':
|
|
387
410
|
case 'DIY Fan':
|
|
388
|
-
this.
|
|
411
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
389
412
|
this.createFan(device);
|
|
390
413
|
break;
|
|
391
414
|
case 'Air Conditioner':
|
|
392
415
|
case 'DIY Air Conditioner':
|
|
393
|
-
this.
|
|
416
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
394
417
|
this.createAirConditioner(device);
|
|
395
418
|
break;
|
|
396
419
|
case 'Light':
|
|
397
420
|
case 'DIY Light':
|
|
398
|
-
this.
|
|
421
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
399
422
|
this.createLight(device);
|
|
400
423
|
break;
|
|
401
424
|
case 'Air Purifier':
|
|
402
425
|
case 'DIY Air Purifier':
|
|
403
|
-
this.
|
|
426
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
404
427
|
this.createAirPurifier(device);
|
|
405
428
|
break;
|
|
406
429
|
case 'Water Heater':
|
|
407
430
|
case 'DIY Water Heater':
|
|
408
|
-
this.
|
|
431
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
409
432
|
this.createWaterHeater(device);
|
|
410
433
|
break;
|
|
411
434
|
case 'Vacuum Cleaner':
|
|
412
435
|
case 'DIY Vacuum Cleaner':
|
|
413
|
-
this.
|
|
436
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
414
437
|
this.createVacuumCleaner(device);
|
|
415
438
|
break;
|
|
416
439
|
case 'Camera':
|
|
417
440
|
case 'DIY Camera':
|
|
418
|
-
this.
|
|
441
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
419
442
|
this.createCamera(device);
|
|
420
443
|
break;
|
|
421
444
|
case 'Others':
|
|
422
|
-
this.
|
|
445
|
+
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
423
446
|
this.createOthers(device);
|
|
424
447
|
break;
|
|
425
448
|
default:
|
|
426
|
-
this.
|
|
427
|
-
this.
|
|
449
|
+
this.deviceInfo(device);
|
|
450
|
+
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.remoteType}, is currently not supported.`);
|
|
451
|
+
this.warnLog('Submit Feature Requests Here: https://git.io/JL14Z');
|
|
428
452
|
}
|
|
429
453
|
}
|
|
430
454
|
|
|
431
455
|
private registerDevice(device: device & devicesConfig) {
|
|
432
456
|
if (!device.hide_device && device.enableCloudService && device.ble) {
|
|
433
457
|
this.registeringDevice = true;
|
|
434
|
-
this.
|
|
458
|
+
this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
|
|
435
459
|
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && !device.enableCloudService) {
|
|
436
460
|
this.registeringDevice = true;
|
|
437
|
-
this.
|
|
461
|
+
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
438
462
|
} else if (!device.hide_device && device.enableCloudService && !device.ble) {
|
|
439
463
|
this.registeringDevice = true;
|
|
440
|
-
this.
|
|
464
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
441
465
|
} else {
|
|
442
466
|
this.registeringDevice = false;
|
|
443
|
-
this.
|
|
467
|
+
this.debugLog(`Device: ${device.deviceName} Neither OpenAPI and BLE Enabled`);
|
|
444
468
|
}
|
|
445
469
|
return this.registeringDevice;
|
|
446
470
|
}
|
|
@@ -455,7 +479,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
455
479
|
if (existingAccessory) {
|
|
456
480
|
// the accessory already exists
|
|
457
481
|
if (this.registerDevice(device)) {
|
|
458
|
-
this.
|
|
482
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
459
483
|
|
|
460
484
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
461
485
|
//existingAccessory.context.firmwareRevision = firmware;
|
|
@@ -469,13 +493,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
469
493
|
// create the accessory handler for the restored accessory
|
|
470
494
|
// this is imported from `platformAccessory.ts`
|
|
471
495
|
new Humidifier(this, existingAccessory, device);
|
|
472
|
-
this.
|
|
496
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
473
497
|
} else {
|
|
474
498
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
475
499
|
}
|
|
476
500
|
} else if (this.registerDevice(device)) {
|
|
477
501
|
// the accessory does not yet exist, so we need to create it
|
|
478
|
-
this.
|
|
502
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
479
503
|
|
|
480
504
|
// create a new accessory
|
|
481
505
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -491,13 +515,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
491
515
|
// create the accessory handler for the newly create accessory
|
|
492
516
|
// this is imported from `platformAccessory.ts`
|
|
493
517
|
new Humidifier(this, accessory, device);
|
|
494
|
-
this.
|
|
518
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
495
519
|
|
|
496
520
|
// link the accessory to your platform
|
|
497
521
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
498
522
|
this.accessories.push(accessory);
|
|
499
523
|
} else {
|
|
500
|
-
this.
|
|
524
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
501
525
|
}
|
|
502
526
|
}
|
|
503
527
|
|
|
@@ -511,9 +535,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
511
535
|
if (existingAccessory) {
|
|
512
536
|
// the accessory already exists
|
|
513
537
|
if (this.registerDevice(device)) {
|
|
514
|
-
this.
|
|
538
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
515
539
|
|
|
516
|
-
this.
|
|
540
|
+
this.debugLog(JSON.stringify(device.bot?.mode));
|
|
517
541
|
|
|
518
542
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
519
543
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -526,15 +550,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
526
550
|
// create the accessory handler for the restored accessory
|
|
527
551
|
// this is imported from `platformAccessory.ts`
|
|
528
552
|
new Bot(this, existingAccessory, device);
|
|
529
|
-
this.
|
|
553
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
530
554
|
} else {
|
|
531
555
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
532
556
|
}
|
|
533
557
|
} else if (this.registerDevice(device)) {
|
|
534
558
|
// the accessory does not yet exist, so we need to create it
|
|
535
|
-
this.
|
|
559
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
536
560
|
|
|
537
|
-
this.
|
|
561
|
+
this.debugLog(JSON.stringify(device.bot?.mode));
|
|
538
562
|
|
|
539
563
|
// create a new accessory
|
|
540
564
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -551,13 +575,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
551
575
|
// create the accessory handler for the newly create accessory
|
|
552
576
|
// this is imported from `platformAccessory.ts`
|
|
553
577
|
new Bot(this, accessory, device);
|
|
554
|
-
this.
|
|
578
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
555
579
|
|
|
556
580
|
// link the accessory to your platform
|
|
557
581
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
558
582
|
this.accessories.push(accessory);
|
|
559
583
|
} else {
|
|
560
|
-
this.
|
|
584
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
561
585
|
}
|
|
562
586
|
}
|
|
563
587
|
|
|
@@ -571,7 +595,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
571
595
|
if (existingAccessory) {
|
|
572
596
|
// the accessory already exists
|
|
573
597
|
if (this.registerDevice(device)) {
|
|
574
|
-
this.
|
|
598
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
575
599
|
|
|
576
600
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
577
601
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -584,13 +608,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
584
608
|
// create the accessory handler for the restored accessory
|
|
585
609
|
// this is imported from `platformAccessory.ts`
|
|
586
610
|
new Meter(this, existingAccessory, device);
|
|
587
|
-
this.
|
|
611
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
588
612
|
} else {
|
|
589
613
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
590
614
|
}
|
|
591
615
|
} else if (this.registerDevice(device)) {
|
|
592
616
|
// the accessory does not yet exist, so we need to create it
|
|
593
|
-
this.
|
|
617
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
594
618
|
|
|
595
619
|
// create a new accessory
|
|
596
620
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -606,13 +630,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
606
630
|
// create the accessory handler for the newly create accessory
|
|
607
631
|
// this is imported from `platformAccessory.ts`
|
|
608
632
|
new Meter(this, accessory, device);
|
|
609
|
-
this.
|
|
633
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
610
634
|
|
|
611
635
|
// link the accessory to your platform
|
|
612
636
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
613
637
|
this.accessories.push(accessory);
|
|
614
638
|
} else {
|
|
615
|
-
this.
|
|
639
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
616
640
|
}
|
|
617
641
|
}
|
|
618
642
|
|
|
@@ -626,7 +650,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
626
650
|
if (existingAccessory) {
|
|
627
651
|
// the accessory already exists
|
|
628
652
|
if (this.registerDevice(device)) {
|
|
629
|
-
this.
|
|
653
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
630
654
|
|
|
631
655
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
632
656
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -639,13 +663,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
639
663
|
// create the accessory handler for the restored accessory
|
|
640
664
|
// this is imported from `platformAccessory.ts`
|
|
641
665
|
new Motion(this, existingAccessory, device);
|
|
642
|
-
this.
|
|
666
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
643
667
|
} else {
|
|
644
668
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
645
669
|
}
|
|
646
670
|
} else if (this.registerDevice(device)) {
|
|
647
671
|
// the accessory does not yet exist, so we need to create it
|
|
648
|
-
this.
|
|
672
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
649
673
|
|
|
650
674
|
// create a new accessory
|
|
651
675
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -661,13 +685,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
661
685
|
// create the accessory handler for the newly create accessory
|
|
662
686
|
// this is imported from `platformAccessory.ts`
|
|
663
687
|
new Motion(this, accessory, device);
|
|
664
|
-
this.
|
|
688
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
665
689
|
|
|
666
690
|
// link the accessory to your platform
|
|
667
691
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
668
692
|
this.accessories.push(accessory);
|
|
669
693
|
} else {
|
|
670
|
-
this.
|
|
694
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
671
695
|
}
|
|
672
696
|
}
|
|
673
697
|
|
|
@@ -681,7 +705,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
681
705
|
if (existingAccessory) {
|
|
682
706
|
// the accessory already exists
|
|
683
707
|
if (this.registerDevice(device)) {
|
|
684
|
-
this.
|
|
708
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
685
709
|
|
|
686
710
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
687
711
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -694,13 +718,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
694
718
|
// create the accessory handler for the restored accessory
|
|
695
719
|
// this is imported from `platformAccessory.ts`
|
|
696
720
|
new Contact(this, existingAccessory, device);
|
|
697
|
-
this.
|
|
721
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
698
722
|
} else {
|
|
699
723
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
700
724
|
}
|
|
701
725
|
} else if (this.registerDevice(device)) {
|
|
702
726
|
// the accessory does not yet exist, so we need to create it
|
|
703
|
-
this.
|
|
727
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
704
728
|
|
|
705
729
|
// create a new accessory
|
|
706
730
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -716,13 +740,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
716
740
|
// create the accessory handler for the newly create accessory
|
|
717
741
|
// this is imported from `platformAccessory.ts`
|
|
718
742
|
new Contact(this, accessory, device);
|
|
719
|
-
this.
|
|
743
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
720
744
|
|
|
721
745
|
// link the accessory to your platform
|
|
722
746
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
723
747
|
this.accessories.push(accessory);
|
|
724
748
|
} else {
|
|
725
|
-
this.
|
|
749
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
726
750
|
}
|
|
727
751
|
}
|
|
728
752
|
|
|
@@ -736,7 +760,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
736
760
|
if (existingAccessory) {
|
|
737
761
|
// the accessory already exists
|
|
738
762
|
if (this.isCurtainGrouped(device)) {
|
|
739
|
-
this.
|
|
763
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
740
764
|
|
|
741
765
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
742
766
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -749,21 +773,22 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
749
773
|
// create the accessory handler for the restored accessory
|
|
750
774
|
// this is imported from `platformAccessory.ts`
|
|
751
775
|
new Curtain(this, existingAccessory, device);
|
|
752
|
-
this.
|
|
776
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
753
777
|
} else {
|
|
754
778
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
755
779
|
}
|
|
756
780
|
} else if (this.isCurtainGrouped(device)) {
|
|
757
781
|
// the accessory does not yet exist, so we need to create it
|
|
758
|
-
this.
|
|
782
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
783
|
+
|
|
759
784
|
if (device.group && !device.curtain?.disable_group) {
|
|
760
|
-
this.
|
|
785
|
+
this.debugLog(`Your Curtains are grouped
|
|
761
786
|
, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
762
787
|
} else {
|
|
763
788
|
if (device.master) {
|
|
764
|
-
this.
|
|
789
|
+
this.debugLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
765
790
|
} else {
|
|
766
|
-
this.
|
|
791
|
+
this.debugLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
767
792
|
}
|
|
768
793
|
}
|
|
769
794
|
|
|
@@ -781,25 +806,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
781
806
|
// create the accessory handler for the newly create accessory
|
|
782
807
|
// this is imported from `platformAccessory.ts`
|
|
783
808
|
new Curtain(this, accessory, device);
|
|
784
|
-
this.
|
|
809
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
785
810
|
|
|
786
811
|
// link the accessory to your platform
|
|
787
812
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
788
813
|
this.accessories.push(accessory);
|
|
789
814
|
} else {
|
|
790
|
-
this.
|
|
815
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
791
816
|
}
|
|
792
817
|
}
|
|
793
818
|
|
|
794
819
|
private isCurtainGrouped(device: device & devicesConfig) {
|
|
795
|
-
this.
|
|
820
|
+
this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
|
|
796
821
|
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
|
|
797
822
|
|
|
798
823
|
if (device.group && !device.curtain?.disable_group) {
|
|
799
|
-
this.
|
|
824
|
+
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
800
825
|
return device.master && this.registerDevice(device);
|
|
801
826
|
} else {
|
|
802
|
-
this.
|
|
827
|
+
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
|
|
803
828
|
return this.registerDevice(device);
|
|
804
829
|
}
|
|
805
830
|
}
|
|
@@ -814,7 +839,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
814
839
|
if (existingAccessory) {
|
|
815
840
|
// the accessory already exists
|
|
816
841
|
if (!device.hide_device && device.enableCloudService) {
|
|
817
|
-
this.
|
|
842
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
818
843
|
|
|
819
844
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
820
845
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -827,13 +852,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
827
852
|
// create the accessory handler for the restored accessory
|
|
828
853
|
// this is imported from `platformAccessory.ts`
|
|
829
854
|
new Plug(this, existingAccessory, device);
|
|
830
|
-
this.
|
|
855
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
831
856
|
} else {
|
|
832
857
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
833
858
|
}
|
|
834
859
|
} else if (!device.hide_device && device.enableCloudService) {
|
|
835
860
|
// the accessory does not yet exist, so we need to create it
|
|
836
|
-
this.
|
|
861
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
837
862
|
|
|
838
863
|
// create a new accessory
|
|
839
864
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -849,13 +874,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
849
874
|
// create the accessory handler for the newly create accessory
|
|
850
875
|
// this is imported from `platformAccessory.ts`
|
|
851
876
|
new Plug(this, accessory, device);
|
|
852
|
-
this.
|
|
877
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
853
878
|
|
|
854
879
|
// link the accessory to your platform
|
|
855
880
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
856
881
|
this.accessories.push(accessory);
|
|
857
882
|
} else {
|
|
858
|
-
this.
|
|
883
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
859
884
|
}
|
|
860
885
|
}
|
|
861
886
|
|
|
@@ -869,7 +894,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
869
894
|
if (existingAccessory) {
|
|
870
895
|
// the accessory already exists
|
|
871
896
|
if (!device.hide_device && device.enableCloudService) {
|
|
872
|
-
this.
|
|
897
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
873
898
|
|
|
874
899
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
875
900
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -882,13 +907,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
882
907
|
// create the accessory handler for the restored accessory
|
|
883
908
|
// this is imported from `platformAccessory.ts`
|
|
884
909
|
new ColorBulb(this, existingAccessory, device);
|
|
885
|
-
this.
|
|
910
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
886
911
|
} else {
|
|
887
912
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
888
913
|
}
|
|
889
914
|
} else if (!device.hide_device && device.enableCloudService) {
|
|
890
915
|
// the accessory does not yet exist, so we need to create it
|
|
891
|
-
this.
|
|
916
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
892
917
|
|
|
893
918
|
// create a new accessory
|
|
894
919
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -904,68 +929,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
904
929
|
// create the accessory handler for the newly create accessory
|
|
905
930
|
// this is imported from `platformAccessory.ts`
|
|
906
931
|
new ColorBulb(this, accessory, device);
|
|
907
|
-
this.
|
|
932
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
908
933
|
|
|
909
934
|
// link the accessory to your platform
|
|
910
935
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
911
936
|
this.accessories.push(accessory);
|
|
912
937
|
} else {
|
|
913
|
-
this.
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
private async createIndoorCam(device: device & devicesConfig) {
|
|
918
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
919
|
-
|
|
920
|
-
// see if an accessory with the same uuid has already been registered and restored from
|
|
921
|
-
// the cached devices we stored in the `configureAccessory` method above
|
|
922
|
-
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
923
|
-
|
|
924
|
-
if (existingAccessory) {
|
|
925
|
-
// the accessory already exists
|
|
926
|
-
if (!device.hide_device && device.enableCloudService) {
|
|
927
|
-
this.log.info(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
928
|
-
|
|
929
|
-
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
930
|
-
existingAccessory.context.model = device.deviceType;
|
|
931
|
-
existingAccessory.context.deviceID = device.deviceId;
|
|
932
|
-
existingAccessory.displayName = device.deviceName;
|
|
933
|
-
existingAccessory.context.firmwareRevision = this.version;
|
|
934
|
-
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
935
|
-
await this.connectionTypeExistingAccessory(device, existingAccessory);
|
|
936
|
-
this.api.updatePlatformAccessories([existingAccessory]);
|
|
937
|
-
// create the accessory handler for the restored accessory
|
|
938
|
-
// this is imported from `platformAccessory.ts`
|
|
939
|
-
new IndoorCam(this, existingAccessory, device);
|
|
940
|
-
this.debug(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
941
|
-
} else {
|
|
942
|
-
this.unregisterPlatformAccessories(existingAccessory);
|
|
943
|
-
}
|
|
944
|
-
} else if (!device.hide_device && device.enableCloudService) {
|
|
945
|
-
// the accessory does not yet exist, so we need to create it
|
|
946
|
-
this.log.info(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
947
|
-
|
|
948
|
-
// create a new accessory
|
|
949
|
-
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
950
|
-
|
|
951
|
-
// store a copy of the device object in the `accessory.context`
|
|
952
|
-
// the `context` property can be used to store any data about the accessory you may need
|
|
953
|
-
accessory.context.device = device;
|
|
954
|
-
accessory.context.model = device.deviceType;
|
|
955
|
-
accessory.context.deviceID = device.deviceId;
|
|
956
|
-
accessory.context.firmwareRevision = this.version;
|
|
957
|
-
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
958
|
-
await this.connectionTypeNewAccessory(device, accessory);
|
|
959
|
-
// create the accessory handler for the newly create accessory
|
|
960
|
-
// this is imported from `platformAccessory.ts`
|
|
961
|
-
new IndoorCam(this, accessory, device);
|
|
962
|
-
this.debug(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
963
|
-
|
|
964
|
-
// link the accessory to your platform
|
|
965
|
-
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
966
|
-
this.accessories.push(accessory);
|
|
967
|
-
} else {
|
|
968
|
-
this.device(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
938
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
969
939
|
}
|
|
970
940
|
}
|
|
971
941
|
|
|
@@ -977,7 +947,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
977
947
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
978
948
|
|
|
979
949
|
if (!device.hide_device && existingAccessory) {
|
|
980
|
-
this.
|
|
950
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
981
951
|
|
|
982
952
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
983
953
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -985,15 +955,15 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
985
955
|
existingAccessory.displayName = device.deviceName;
|
|
986
956
|
existingAccessory.context.firmwareRevision = this.version;
|
|
987
957
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
988
|
-
await this.connectionTypeExistingIRAccessory(
|
|
958
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
989
959
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
990
960
|
// create the accessory handler for the restored accessory
|
|
991
961
|
// this is imported from `platformAccessory.ts`
|
|
992
962
|
new TV(this, existingAccessory, device);
|
|
993
|
-
this.
|
|
963
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
994
964
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
995
965
|
// the accessory does not yet exist, so we need to create it
|
|
996
|
-
this.
|
|
966
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
997
967
|
|
|
998
968
|
// create a new accessory
|
|
999
969
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1005,11 +975,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1005
975
|
accessory.context.deviceID = device.deviceId;
|
|
1006
976
|
accessory.context.firmwareRevision = this.version;
|
|
1007
977
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1008
|
-
await this.connectionTypeNewIRAccessory(
|
|
978
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1009
979
|
// create the accessory handler for the newly create accessory
|
|
1010
980
|
// this is imported from `platformAccessory.ts`
|
|
1011
981
|
new TV(this, accessory, device);
|
|
1012
|
-
this.
|
|
982
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1013
983
|
|
|
1014
984
|
/**
|
|
1015
985
|
* Publish as external accessory
|
|
@@ -1019,7 +989,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1019
989
|
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
|
|
1020
990
|
this.accessories.push(accessory);
|
|
1021
991
|
} else {
|
|
1022
|
-
this.
|
|
992
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1023
993
|
}
|
|
1024
994
|
}
|
|
1025
995
|
|
|
@@ -1033,7 +1003,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1033
1003
|
if (existingAccessory) {
|
|
1034
1004
|
// the accessory already exists
|
|
1035
1005
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1036
|
-
this.
|
|
1006
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1037
1007
|
|
|
1038
1008
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1039
1009
|
|
|
@@ -1042,18 +1012,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1042
1012
|
existingAccessory.displayName = device.deviceName;
|
|
1043
1013
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1044
1014
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1045
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1015
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1046
1016
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1047
1017
|
// create the accessory handler for the restored accessory
|
|
1048
1018
|
// this is imported from `platformAccessory.ts`
|
|
1049
1019
|
new Fan(this, existingAccessory, device);
|
|
1050
|
-
this.
|
|
1020
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1051
1021
|
} else {
|
|
1052
1022
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1053
1023
|
}
|
|
1054
1024
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1055
1025
|
// the accessory does not yet exist, so we need to create it
|
|
1056
|
-
this.
|
|
1026
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1057
1027
|
|
|
1058
1028
|
// create a new accessory
|
|
1059
1029
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1065,17 +1035,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1065
1035
|
accessory.context.deviceID = device.deviceId;
|
|
1066
1036
|
accessory.context.firmwareRevision = this.version;
|
|
1067
1037
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1068
|
-
await this.connectionTypeNewIRAccessory(
|
|
1038
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1069
1039
|
// create the accessory handler for the newly create accessory
|
|
1070
1040
|
// this is imported from `platformAccessory.ts`
|
|
1071
1041
|
new Fan(this, accessory, device);
|
|
1072
|
-
this.
|
|
1042
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1073
1043
|
|
|
1074
1044
|
// link the accessory to your platform
|
|
1075
1045
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1076
1046
|
this.accessories.push(accessory);
|
|
1077
1047
|
} else {
|
|
1078
|
-
this.
|
|
1048
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1079
1049
|
}
|
|
1080
1050
|
}
|
|
1081
1051
|
|
|
@@ -1089,7 +1059,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1089
1059
|
if (existingAccessory) {
|
|
1090
1060
|
// the accessory already exists
|
|
1091
1061
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1092
|
-
this.
|
|
1062
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1093
1063
|
|
|
1094
1064
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1095
1065
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1097,18 +1067,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1097
1067
|
existingAccessory.displayName = device.deviceName;
|
|
1098
1068
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1099
1069
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1100
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1070
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1101
1071
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1102
1072
|
// create the accessory handler for the restored accessory
|
|
1103
1073
|
// this is imported from `platformAccessory.ts`
|
|
1104
1074
|
new Light(this, existingAccessory, device);
|
|
1105
|
-
this.
|
|
1075
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1106
1076
|
} else {
|
|
1107
1077
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1108
1078
|
}
|
|
1109
1079
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1110
1080
|
// the accessory does not yet exist, so we need to create it
|
|
1111
|
-
this.
|
|
1081
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1112
1082
|
|
|
1113
1083
|
// create a new accessory
|
|
1114
1084
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1120,17 +1090,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1120
1090
|
accessory.context.deviceID = device.deviceId;
|
|
1121
1091
|
accessory.context.firmwareRevision = this.version;
|
|
1122
1092
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1123
|
-
await this.connectionTypeNewIRAccessory(
|
|
1093
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1124
1094
|
// create the accessory handler for the newly create accessory
|
|
1125
1095
|
// this is imported from `platformAccessory.ts`
|
|
1126
1096
|
new Light(this, accessory, device);
|
|
1127
|
-
this.
|
|
1097
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1128
1098
|
|
|
1129
1099
|
// link the accessory to your platform
|
|
1130
1100
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1131
1101
|
this.accessories.push(accessory);
|
|
1132
1102
|
} else {
|
|
1133
|
-
this.
|
|
1103
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1134
1104
|
}
|
|
1135
1105
|
}
|
|
1136
1106
|
|
|
@@ -1144,7 +1114,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1144
1114
|
if (existingAccessory) {
|
|
1145
1115
|
// the accessory already exists
|
|
1146
1116
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1147
|
-
this.
|
|
1117
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1148
1118
|
|
|
1149
1119
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1150
1120
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1152,18 +1122,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1152
1122
|
existingAccessory.displayName = device.deviceName;
|
|
1153
1123
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1154
1124
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1155
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1125
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1156
1126
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1157
1127
|
// create the accessory handler for the restored accessory
|
|
1158
1128
|
// this is imported from `platformAccessory.ts`
|
|
1159
1129
|
new AirConditioner(this, existingAccessory, device);
|
|
1160
|
-
this.
|
|
1130
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1161
1131
|
} else {
|
|
1162
1132
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1163
1133
|
}
|
|
1164
1134
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1165
1135
|
// the accessory does not yet exist, so we need to create it
|
|
1166
|
-
this.
|
|
1136
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1167
1137
|
|
|
1168
1138
|
// create a new accessory
|
|
1169
1139
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1175,17 +1145,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1175
1145
|
accessory.context.deviceID = device.deviceId;
|
|
1176
1146
|
accessory.context.firmwareRevision = this.version;
|
|
1177
1147
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1178
|
-
await this.connectionTypeNewIRAccessory(
|
|
1148
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1179
1149
|
// create the accessory handler for the newly create accessory
|
|
1180
1150
|
// this is imported from `platformAccessory.ts`
|
|
1181
1151
|
new AirConditioner(this, accessory, device);
|
|
1182
|
-
this.
|
|
1152
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1183
1153
|
|
|
1184
1154
|
// link the accessory to your platform
|
|
1185
1155
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1186
1156
|
this.accessories.push(accessory);
|
|
1187
1157
|
} else {
|
|
1188
|
-
this.
|
|
1158
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1189
1159
|
}
|
|
1190
1160
|
}
|
|
1191
1161
|
|
|
@@ -1199,7 +1169,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1199
1169
|
if (existingAccessory) {
|
|
1200
1170
|
// the accessory already exists
|
|
1201
1171
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1202
|
-
this.
|
|
1172
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1203
1173
|
|
|
1204
1174
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1205
1175
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1207,18 +1177,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1207
1177
|
existingAccessory.displayName = device.deviceName;
|
|
1208
1178
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1209
1179
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1210
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1180
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1211
1181
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1212
1182
|
// create the accessory handler for the restored accessory
|
|
1213
1183
|
// this is imported from `platformAccessory.ts`
|
|
1214
1184
|
new AirPurifier(this, existingAccessory, device);
|
|
1215
|
-
this.
|
|
1185
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1216
1186
|
} else {
|
|
1217
1187
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1218
1188
|
}
|
|
1219
1189
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1220
1190
|
// the accessory does not yet exist, so we need to create it
|
|
1221
|
-
this.
|
|
1191
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1222
1192
|
|
|
1223
1193
|
// create a new accessory
|
|
1224
1194
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1230,17 +1200,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1230
1200
|
accessory.context.deviceID = device.deviceId;
|
|
1231
1201
|
accessory.context.firmwareRevision = this.version;
|
|
1232
1202
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1233
|
-
await this.connectionTypeNewIRAccessory(
|
|
1203
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1234
1204
|
// create the accessory handler for the newly create accessory
|
|
1235
1205
|
// this is imported from `platformAccessory.ts`
|
|
1236
1206
|
new AirPurifier(this, accessory, device);
|
|
1237
|
-
this.
|
|
1207
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1238
1208
|
|
|
1239
1209
|
// link the accessory to your platform
|
|
1240
1210
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1241
1211
|
this.accessories.push(accessory);
|
|
1242
1212
|
} else {
|
|
1243
|
-
this.
|
|
1213
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1244
1214
|
}
|
|
1245
1215
|
}
|
|
1246
1216
|
|
|
@@ -1254,7 +1224,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1254
1224
|
if (existingAccessory) {
|
|
1255
1225
|
// the accessory already exists
|
|
1256
1226
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1257
|
-
this.
|
|
1227
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1258
1228
|
|
|
1259
1229
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1260
1230
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1262,18 +1232,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1262
1232
|
existingAccessory.displayName = device.deviceName;
|
|
1263
1233
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1264
1234
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1265
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1235
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1266
1236
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1267
1237
|
// create the accessory handler for the restored accessory
|
|
1268
1238
|
// this is imported from `platformAccessory.ts`
|
|
1269
1239
|
new WaterHeater(this, existingAccessory, device);
|
|
1270
|
-
this.
|
|
1240
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1271
1241
|
} else {
|
|
1272
1242
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1273
1243
|
}
|
|
1274
1244
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1275
1245
|
// the accessory does not yet exist, so we need to create it
|
|
1276
|
-
this.
|
|
1246
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1277
1247
|
|
|
1278
1248
|
// create a new accessory
|
|
1279
1249
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1285,17 +1255,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1285
1255
|
accessory.context.deviceID = device.deviceId;
|
|
1286
1256
|
accessory.context.firmwareRevision = this.version;
|
|
1287
1257
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1288
|
-
await this.connectionTypeNewIRAccessory(
|
|
1258
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1289
1259
|
// create the accessory handler for the newly create accessory
|
|
1290
1260
|
// this is imported from `platformAccessory.ts`
|
|
1291
1261
|
new WaterHeater(this, accessory, device);
|
|
1292
|
-
this.
|
|
1262
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1293
1263
|
|
|
1294
1264
|
// link the accessory to your platform
|
|
1295
1265
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1296
1266
|
this.accessories.push(accessory);
|
|
1297
1267
|
} else {
|
|
1298
|
-
this.
|
|
1268
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1299
1269
|
}
|
|
1300
1270
|
}
|
|
1301
1271
|
|
|
@@ -1309,7 +1279,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1309
1279
|
if (existingAccessory) {
|
|
1310
1280
|
// the accessory already exists
|
|
1311
1281
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1312
|
-
this.
|
|
1282
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1313
1283
|
|
|
1314
1284
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1315
1285
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1317,18 +1287,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1317
1287
|
existingAccessory.displayName = device.deviceName;
|
|
1318
1288
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1319
1289
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1320
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1290
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1321
1291
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1322
1292
|
// create the accessory handler for the restored accessory
|
|
1323
1293
|
// this is imported from `platformAccessory.ts`
|
|
1324
1294
|
new VacuumCleaner(this, existingAccessory, device);
|
|
1325
|
-
this.
|
|
1295
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1326
1296
|
} else {
|
|
1327
1297
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1328
1298
|
}
|
|
1329
1299
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1330
1300
|
// the accessory does not yet exist, so we need to create it
|
|
1331
|
-
this.
|
|
1301
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1332
1302
|
|
|
1333
1303
|
// create a new accessory
|
|
1334
1304
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1340,17 +1310,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1340
1310
|
accessory.context.deviceID = device.deviceId;
|
|
1341
1311
|
accessory.context.firmwareRevision = this.version;
|
|
1342
1312
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1343
|
-
await this.connectionTypeNewIRAccessory(
|
|
1313
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1344
1314
|
// create the accessory handler for the newly create accessory
|
|
1345
1315
|
// this is imported from `platformAccessory.ts`
|
|
1346
1316
|
new VacuumCleaner(this, accessory, device);
|
|
1347
|
-
this.
|
|
1317
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1348
1318
|
|
|
1349
1319
|
// link the accessory to your platform
|
|
1350
1320
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1351
1321
|
this.accessories.push(accessory);
|
|
1352
1322
|
} else {
|
|
1353
|
-
this.
|
|
1323
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1354
1324
|
}
|
|
1355
1325
|
}
|
|
1356
1326
|
|
|
@@ -1364,7 +1334,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1364
1334
|
if (existingAccessory) {
|
|
1365
1335
|
// the accessory already exists
|
|
1366
1336
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1367
|
-
this.
|
|
1337
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1368
1338
|
|
|
1369
1339
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1370
1340
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1372,18 +1342,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1372
1342
|
existingAccessory.displayName = device.deviceName;
|
|
1373
1343
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1374
1344
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1375
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1345
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1376
1346
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1377
1347
|
// create the accessory handler for the restored accessory
|
|
1378
1348
|
// this is imported from `platformAccessory.ts`
|
|
1379
1349
|
new Camera(this, existingAccessory, device);
|
|
1380
|
-
this.
|
|
1350
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1381
1351
|
} else {
|
|
1382
1352
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1383
1353
|
}
|
|
1384
1354
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1385
1355
|
// the accessory does not yet exist, so we need to create it
|
|
1386
|
-
this.
|
|
1356
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1387
1357
|
|
|
1388
1358
|
// create a new accessory
|
|
1389
1359
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1395,17 +1365,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1395
1365
|
accessory.context.deviceID = device.deviceId;
|
|
1396
1366
|
accessory.context.firmwareRevision = this.version;
|
|
1397
1367
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1398
|
-
await this.connectionTypeNewIRAccessory(
|
|
1368
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1399
1369
|
// create the accessory handler for the newly create accessory
|
|
1400
1370
|
// this is imported from `platformAccessory.ts`
|
|
1401
1371
|
new Camera(this, accessory, device);
|
|
1402
|
-
this.
|
|
1372
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1403
1373
|
|
|
1404
1374
|
// link the accessory to your platform
|
|
1405
1375
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1406
1376
|
this.accessories.push(accessory);
|
|
1407
1377
|
} else {
|
|
1408
|
-
this.
|
|
1378
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1409
1379
|
}
|
|
1410
1380
|
}
|
|
1411
1381
|
|
|
@@ -1419,7 +1389,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1419
1389
|
if (existingAccessory) {
|
|
1420
1390
|
// the accessory already exists
|
|
1421
1391
|
if (!device.hide_device && device.hubDeviceId) {
|
|
1422
|
-
this.
|
|
1392
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1423
1393
|
|
|
1424
1394
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1425
1395
|
existingAccessory.context.model = device.remoteType;
|
|
@@ -1427,18 +1397,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1427
1397
|
existingAccessory.displayName = device.deviceName;
|
|
1428
1398
|
existingAccessory.context.firmwareRevision = this.version;
|
|
1429
1399
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1430
|
-
await this.connectionTypeExistingIRAccessory(
|
|
1400
|
+
await this.connectionTypeExistingIRAccessory(existingAccessory);
|
|
1431
1401
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1432
1402
|
// create the accessory handler for the restored accessory
|
|
1433
1403
|
// this is imported from `platformAccessory.ts`
|
|
1434
1404
|
new Others(this, existingAccessory, device);
|
|
1435
|
-
this.
|
|
1405
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1436
1406
|
} else {
|
|
1437
1407
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
1438
1408
|
}
|
|
1439
1409
|
} else if (!device.hide_device && device.hubDeviceId) {
|
|
1440
1410
|
// the accessory does not yet exist, so we need to create it
|
|
1441
|
-
this.
|
|
1411
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1442
1412
|
|
|
1443
1413
|
// create a new accessory
|
|
1444
1414
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1450,17 +1420,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1450
1420
|
accessory.context.deviceID = device.deviceId;
|
|
1451
1421
|
accessory.context.firmwareRevision = this.version;
|
|
1452
1422
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1453
|
-
await this.connectionTypeNewIRAccessory(
|
|
1423
|
+
await this.connectionTypeNewIRAccessory(accessory);
|
|
1454
1424
|
// create the accessory handler for the newly create accessory
|
|
1455
1425
|
// this is imported from `platformAccessory.ts`
|
|
1456
1426
|
new Others(this, accessory, device);
|
|
1457
|
-
this.
|
|
1427
|
+
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1458
1428
|
|
|
1459
1429
|
// link the accessory to your platform
|
|
1460
1430
|
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1461
1431
|
this.accessories.push(accessory);
|
|
1462
1432
|
} else {
|
|
1463
|
-
this.
|
|
1433
|
+
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1464
1434
|
}
|
|
1465
1435
|
}
|
|
1466
1436
|
|
|
@@ -1486,13 +1456,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1486
1456
|
}
|
|
1487
1457
|
|
|
1488
1458
|
public async connectionTypeNewIRAccessory(
|
|
1489
|
-
device: irdevice & devicesConfig,
|
|
1490
1459
|
accessory: PlatformAccessory) {
|
|
1491
1460
|
accessory.context.connectionType = 'IR wirth OpenAPI';
|
|
1492
1461
|
}
|
|
1493
1462
|
|
|
1494
1463
|
public async connectionTypeExistingIRAccessory(
|
|
1495
|
-
device: irdevice & devicesConfig,
|
|
1496
1464
|
existingAccessory: PlatformAccessory,
|
|
1497
1465
|
) {
|
|
1498
1466
|
existingAccessory.context.connectionType = 'IR with OpenAPI';
|
|
@@ -1501,52 +1469,61 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1501
1469
|
public unregisterPlatformAccessories(existingAccessory: PlatformAccessory) {
|
|
1502
1470
|
// remove platform accessories when no longer present
|
|
1503
1471
|
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
|
|
1504
|
-
this.
|
|
1472
|
+
this.infoLog('Removing existing accessory from cache:', existingAccessory.displayName);
|
|
1505
1473
|
}
|
|
1506
1474
|
|
|
1507
1475
|
public deviceListInfo(devices: deviceResponses) {
|
|
1508
|
-
if (this.
|
|
1509
|
-
this.
|
|
1476
|
+
if (this.platformLogging === 'debug') {
|
|
1477
|
+
this.warnLog(`deviceListInfoStatus: ${JSON.stringify(devices)}`);
|
|
1510
1478
|
}
|
|
1511
1479
|
}
|
|
1512
1480
|
|
|
1513
1481
|
public async deviceInfo(device: irdevice & devicesConfig | device & devicesConfig) {
|
|
1514
|
-
if (this.
|
|
1515
|
-
this.
|
|
1482
|
+
if (this.platformLogging === 'debug') {
|
|
1483
|
+
this.warnLog(JSON.stringify(device));
|
|
1516
1484
|
this.deviceStatus = (await this.axios.get(`${DeviceURL}/${device.deviceId}/status`)).data;
|
|
1517
1485
|
if (this.deviceStatus.message === 'success') {
|
|
1518
|
-
this.
|
|
1486
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
1519
1487
|
} else {
|
|
1520
|
-
this.
|
|
1521
|
-
this.
|
|
1488
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${JSON.stringify(this.deviceStatus.message)}`);
|
|
1489
|
+
this.warnLog('Unable to retreive deviceInfoStatus.');
|
|
1522
1490
|
}
|
|
1523
1491
|
}
|
|
1524
1492
|
}
|
|
1525
1493
|
|
|
1526
1494
|
/**
|
|
1527
|
-
* If
|
|
1495
|
+
* If device level logging is turned on, log to log.warn
|
|
1528
1496
|
* Otherwise send debug logs to log.debug
|
|
1529
|
-
* this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
1530
1497
|
*/
|
|
1531
|
-
|
|
1532
|
-
if (this.
|
|
1533
|
-
this.log.info(
|
|
1534
|
-
} else {
|
|
1535
|
-
this.log.debug(String(...log));
|
|
1498
|
+
infoLog(...log: any[]) {
|
|
1499
|
+
if (this.enablingPlatfromLogging()) {
|
|
1500
|
+
this.log.info(String(...log));
|
|
1536
1501
|
}
|
|
1537
1502
|
}
|
|
1538
1503
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
this.log.
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1504
|
+
warnLog(...log: any[]) {
|
|
1505
|
+
if (this.enablingPlatfromLogging()) {
|
|
1506
|
+
this.log.warn(String(...log));
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
errorLog(...log: any[]) {
|
|
1511
|
+
if (this.enablingPlatfromLogging()) {
|
|
1512
|
+
this.log.error(String(...log));
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
debugLog(...log: any[]) {
|
|
1517
|
+
if (this.enablingPlatfromLogging()) {
|
|
1518
|
+
if (this.platformLogging === 'debugMode') {
|
|
1519
|
+
this.log.debug(String(...log));
|
|
1520
|
+
} else if (this.platformLogging === 'debug') {
|
|
1521
|
+
this.log.info('[DEBUG]', String(...log));
|
|
1522
|
+
}
|
|
1550
1523
|
}
|
|
1551
1524
|
}
|
|
1525
|
+
|
|
1526
|
+
enablingPlatfromLogging(): boolean {
|
|
1527
|
+
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
|
|
1528
|
+
}
|
|
1552
1529
|
}
|