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