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