@switchbot/homebridge-switchbot 4.3.2-beta.9 → 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +328 -0
- package/.github/scripts/npm-version-script-esm-auto.js +207 -0
- package/.github/workflows/beta-release.yml +8 -12
- package/.github/workflows/release.yml +54 -22
- package/CHANGELOG.md +11 -1
- package/README.md +13 -10
- package/config.schema.json +248 -5
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +15847 -0
- package/coverage/coverage-final.json +42 -0
- package/coverage/docs/assets/dmt/dmt-component-data.js.html +85 -0
- package/coverage/docs/assets/dmt/dmt-components.js.html +286 -0
- package/coverage/docs/assets/dmt/index.html +131 -0
- package/coverage/docs/assets/hierarchy.js.html +85 -0
- package/coverage/docs/assets/icons.js.html +136 -0
- package/coverage/docs/assets/index.html +146 -0
- package/coverage/docs/assets/main.js.html +265 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +191 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/device/blindtilt.ts.html +3238 -0
- package/coverage/src/device/bot.ts.html +2803 -0
- package/coverage/src/device/ceilinglight.ts.html +2338 -0
- package/coverage/src/device/colorbulb.ts.html +2824 -0
- package/coverage/src/device/contact.ts.html +1465 -0
- package/coverage/src/device/curtain.ts.html +2869 -0
- package/coverage/src/device/device.ts.html +2500 -0
- package/coverage/src/device/fan.ts.html +2242 -0
- package/coverage/src/device/hub.ts.html +1408 -0
- package/coverage/src/device/humidifier.ts.html +2116 -0
- package/coverage/src/device/index.html +416 -0
- package/coverage/src/device/iosensor.ts.html +1375 -0
- package/coverage/src/device/lightstrip.ts.html +2617 -0
- package/coverage/src/device/lock.ts.html +1963 -0
- package/coverage/src/device/meter.ts.html +1372 -0
- package/coverage/src/device/meterplus.ts.html +1384 -0
- package/coverage/src/device/meterpro.ts.html +1618 -0
- package/coverage/src/device/motion.ts.html +1264 -0
- package/coverage/src/device/plug.ts.html +1372 -0
- package/coverage/src/device/relayswitch.ts.html +2284 -0
- package/coverage/src/device/robotvacuumcleaner.ts.html +1810 -0
- package/coverage/src/device/waterdetector.ts.html +1294 -0
- package/coverage/src/homebridge-ui/index.html +116 -0
- package/coverage/src/homebridge-ui/server.ts.html +229 -0
- package/coverage/src/index.html +161 -0
- package/coverage/src/index.ts.html +124 -0
- package/coverage/src/irdevice/airconditioner.ts.html +1687 -0
- package/coverage/src/irdevice/airpurifier.ts.html +844 -0
- package/coverage/src/irdevice/camera.ts.html +475 -0
- package/coverage/src/irdevice/fan.ts.html +766 -0
- package/coverage/src/irdevice/index.html +251 -0
- package/coverage/src/irdevice/irdevice.ts.html +1117 -0
- package/coverage/src/irdevice/light.ts.html +826 -0
- package/coverage/src/irdevice/other.ts.html +2458 -0
- package/coverage/src/irdevice/tv.ts.html +1222 -0
- package/coverage/src/irdevice/vacuumcleaner.ts.html +466 -0
- package/coverage/src/irdevice/waterheater.ts.html +469 -0
- package/coverage/src/platform.ts.html +8776 -0
- package/coverage/src/settings.ts.html +934 -0
- package/coverage/src/utils.ts.html +2092 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +12 -4
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +12 -4
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +18 -7
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +18 -7
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +6 -2
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +12 -4
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +5 -7
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +11 -5
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +16 -6
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +2 -2
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +8 -3
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +16 -6
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +6 -2
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +16 -6
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +12 -4
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +6 -2
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +6 -2
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.d.ts.map +1 -1
- package/dist/device/meterpro.js +7 -4
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +6 -2
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +12 -4
- package/dist/device/plug.js.map +1 -1
- package/dist/device/presence.d.ts +42 -0
- package/dist/device/presence.d.ts.map +1 -0
- package/dist/device/presence.js +349 -0
- package/dist/device/presence.js.map +1 -0
- package/dist/device/relayswitch.d.ts.map +1 -1
- package/dist/device/relayswitch.js +12 -4
- package/dist/device/relayswitch.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +14 -5
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +6 -2
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +6 -5
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +2 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +2 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +2 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +2 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +2 -2
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +77 -78
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +6 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -0
- package/dist/settings.js.map +1 -1
- package/docs/index.html +20 -11
- package/docs/variables/default.html +1 -1
- package/eslint.config.js +0 -1
- package/package.json +9 -10
- package/src/device/blindtilt.ts +10 -4
- package/src/device/bot.ts +10 -4
- package/src/device/ceilinglight.ts +16 -7
- package/src/device/colorbulb.ts +16 -7
- package/src/device/contact.ts +5 -2
- package/src/device/curtain.ts +12 -6
- package/src/device/device.ts +14 -8
- package/src/device/fan.ts +14 -6
- package/src/device/hub.ts +10 -6
- package/src/device/humidifier.ts +14 -6
- package/src/device/iosensor.ts +5 -2
- package/src/device/lightstrip.ts +14 -6
- package/src/device/lock.ts +10 -4
- package/src/device/meter.ts +6 -3
- package/src/device/meterplus.ts +5 -2
- package/src/device/meterpro.ts +7 -5
- package/src/device/motion.ts +5 -2
- package/src/device/plug.ts +10 -4
- package/src/device/presence.ts +393 -0
- package/src/device/relayswitch.ts +10 -4
- package/src/device/robotvacuumcleaner.ts +12 -5
- package/src/device/waterdetector.ts +5 -2
- package/src/homebridge-ui/public/index.html +1 -1
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +6 -5
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +2 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +80 -88
- package/src/settings.ts +7 -0
- package/.github/npm-version-script-esm.js +0 -97
- package/.github/workflows/build.yml +0 -18
- package/.github/workflows/changerelease.yml +0 -11
- package/.github/workflows/labeler.yml +0 -16
- package/.github/workflows/release-drafter.yml +0 -14
- package/dist/device/airpurifier.d.ts +0 -54
- package/dist/device/airpurifier.d.ts.map +0 -1
- package/dist/device/airpurifier.js +0 -527
- package/dist/device/airpurifier.js.map +0 -1
- package/src/device/airpurifier.ts +0 -563
package/dist/platform.js
CHANGED
|
@@ -5,7 +5,6 @@ import fakegato from 'fakegato-history';
|
|
|
5
5
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
6
6
|
import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot';
|
|
7
7
|
import { queueScheduler } from 'rxjs';
|
|
8
|
-
import { AirPurifier } from './device/airpurifier.js';
|
|
9
8
|
import { BlindTilt } from './device/blindtilt.js';
|
|
10
9
|
import { Bot } from './device/bot.js';
|
|
11
10
|
import { CeilingLight } from './device/ceilinglight.js';
|
|
@@ -23,11 +22,12 @@ import { MeterPlus } from './device/meterplus.js';
|
|
|
23
22
|
import { MeterPro } from './device/meterpro.js';
|
|
24
23
|
import { Motion } from './device/motion.js';
|
|
25
24
|
import { Plug } from './device/plug.js';
|
|
25
|
+
import { Presence } from './device/presence.js';
|
|
26
26
|
import { RelaySwitch } from './device/relayswitch.js';
|
|
27
27
|
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
|
|
28
28
|
import { WaterDetector } from './device/waterdetector.js';
|
|
29
29
|
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
30
|
-
import {
|
|
30
|
+
import { AirPurifier } from './irdevice/airpurifier.js';
|
|
31
31
|
import { Camera } from './irdevice/camera.js';
|
|
32
32
|
import { IRFan } from './irdevice/fan.js';
|
|
33
33
|
import { Light } from './irdevice/light.js';
|
|
@@ -202,7 +202,7 @@ export class SwitchBotPlatform {
|
|
|
202
202
|
this.webhookEventHandler[context.deviceMac]?.(context);
|
|
203
203
|
}
|
|
204
204
|
catch (e) {
|
|
205
|
-
this.errorLog(`Failed to handle webhook event. Error
|
|
205
|
+
this.errorLog(`Failed to handle webhook event. Error: ${e.message ?? e}`);
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}
|
|
@@ -230,14 +230,14 @@ export class SwitchBotPlatform {
|
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
232
|
catch (e) {
|
|
233
|
-
this.errorLog(`Failed to setup webhook. Error
|
|
233
|
+
this.errorLog(`Failed to setup webhook. Error: ${e.message ?? e}`);
|
|
234
234
|
}
|
|
235
235
|
this.api.on('shutdown', async () => {
|
|
236
236
|
try {
|
|
237
237
|
this.switchBotAPI.deleteWebhook(url);
|
|
238
238
|
}
|
|
239
239
|
catch (e) {
|
|
240
|
-
this.errorLog(`Failed to delete webhook. Error
|
|
240
|
+
this.errorLog(`Failed to delete webhook. Error: ${e.message ?? e}`);
|
|
241
241
|
}
|
|
242
242
|
});
|
|
243
243
|
}
|
|
@@ -289,7 +289,7 @@ export class SwitchBotPlatform {
|
|
|
289
289
|
await this.switchBotBLE.startScan();
|
|
290
290
|
}
|
|
291
291
|
catch (e) {
|
|
292
|
-
this.errorLog(`Failed to start BLE scanning. Error
|
|
292
|
+
this.errorLog(`Failed to start BLE scanning. Error: ${e.message ?? e}`);
|
|
293
293
|
}
|
|
294
294
|
// Set an event handler to monitor advertisement packets
|
|
295
295
|
this.switchBotBLE.onadvertisement = async (ad) => {
|
|
@@ -297,7 +297,7 @@ export class SwitchBotPlatform {
|
|
|
297
297
|
this.bleEventHandler[ad.address]?.(ad.serviceData);
|
|
298
298
|
}
|
|
299
299
|
catch (e) {
|
|
300
|
-
this.errorLog(`Failed to handle BLE event. Error
|
|
300
|
+
this.errorLog(`Failed to handle BLE event. Error: ${e.message ?? e}`);
|
|
301
301
|
}
|
|
302
302
|
};
|
|
303
303
|
})();
|
|
@@ -307,7 +307,7 @@ export class SwitchBotPlatform {
|
|
|
307
307
|
this.infoLog('Stopped BLE scanning to close listening.');
|
|
308
308
|
}
|
|
309
309
|
catch (e) {
|
|
310
|
-
this.errorLog(`Failed to stop Platform BLE scanning. Error
|
|
310
|
+
this.errorLog(`Failed to stop Platform BLE scanning. Error: ${e.message ?? e}`);
|
|
311
311
|
}
|
|
312
312
|
});
|
|
313
313
|
}
|
|
@@ -536,17 +536,19 @@ export class SwitchBotPlatform {
|
|
|
536
536
|
'Humidifier': this.createHumidifier.bind(this),
|
|
537
537
|
'Humidifier2': this.createHumidifier.bind(this),
|
|
538
538
|
'Hub 2': this.createHub2.bind(this),
|
|
539
|
+
'Hub 3': this.createHub2.bind(this),
|
|
539
540
|
'Bot': this.createBot.bind(this),
|
|
540
541
|
'Relay Switch 1': this.createRelaySwitch.bind(this),
|
|
541
542
|
'Relay Switch 1PM': this.createRelaySwitch.bind(this),
|
|
542
543
|
'Meter': this.createMeter.bind(this),
|
|
543
544
|
'MeterPlus': this.createMeterPlus.bind(this),
|
|
544
545
|
'Meter Plus (JP)': this.createMeterPlus.bind(this),
|
|
545
|
-
'
|
|
546
|
+
'Meter Pro': this.createMeterPro.bind(this),
|
|
546
547
|
'MeterPro(CO2)': this.createMeterPro.bind(this),
|
|
547
548
|
'WoIOSensor': this.createIOSensor.bind(this),
|
|
548
549
|
'Water Detector': this.createWaterDetector.bind(this),
|
|
549
550
|
'Motion Sensor': this.createMotion.bind(this),
|
|
551
|
+
'Presence Sensor': this.createPresence.bind(this),
|
|
550
552
|
'Contact Sensor': this.createContact.bind(this),
|
|
551
553
|
'Curtain': this.createCurtain.bind(this),
|
|
552
554
|
'Curtain3': this.createCurtain.bind(this),
|
|
@@ -570,10 +572,6 @@ export class SwitchBotPlatform {
|
|
|
570
572
|
'Ceiling Light Pro': this.createCeilingLight.bind(this),
|
|
571
573
|
'Strip Light': this.createStripLight.bind(this),
|
|
572
574
|
'Battery Circulator Fan': this.createFan.bind(this),
|
|
573
|
-
'Air Purifier PM2.5': this.createAirPurifier.bind(this),
|
|
574
|
-
'Air Purifier Table PM2.5': this.createAirPurifier.bind(this),
|
|
575
|
-
'Air Purifier VOC': this.createAirPurifier.bind(this),
|
|
576
|
-
'Air Purifier Table VOC': this.createAirPurifier.bind(this),
|
|
577
575
|
};
|
|
578
576
|
if (deviceTypeHandlers[device.deviceType]) {
|
|
579
577
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
@@ -607,8 +605,8 @@ export class SwitchBotPlatform {
|
|
|
607
605
|
'DIY Air Conditioner': this.createAirConditioner.bind(this),
|
|
608
606
|
'Light': this.createLight.bind(this),
|
|
609
607
|
'DIY Light': this.createLight.bind(this),
|
|
610
|
-
'Air Purifier': this.
|
|
611
|
-
'DIY Air Purifier': this.
|
|
608
|
+
'Air Purifier': this.createAirPurifier.bind(this),
|
|
609
|
+
'DIY Air Purifier': this.createAirPurifier.bind(this),
|
|
612
610
|
'Water Heater': this.createWaterHeater.bind(this),
|
|
613
611
|
'DIY Water Heater': this.createWaterHeater.bind(this),
|
|
614
612
|
'Vacuum Cleaner': this.createVacuumCleaner.bind(this),
|
|
@@ -1232,6 +1230,66 @@ export class SwitchBotPlatform {
|
|
|
1232
1230
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1233
1231
|
}
|
|
1234
1232
|
}
|
|
1233
|
+
async createPresence(device) {
|
|
1234
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1235
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
1236
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
1237
|
+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1238
|
+
if (existingAccessory) {
|
|
1239
|
+
// the accessory already exists
|
|
1240
|
+
if (await this.registerDevice(device)) {
|
|
1241
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1242
|
+
existingAccessory.context.device = device;
|
|
1243
|
+
existingAccessory.context.deviceId = device.deviceId;
|
|
1244
|
+
existingAccessory.context.deviceType = device.deviceType;
|
|
1245
|
+
existingAccessory.context.model = SwitchBotModel.PresenceSensor;
|
|
1246
|
+
existingAccessory.displayName = device.configDeviceName
|
|
1247
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1248
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1249
|
+
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1250
|
+
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1251
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1252
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1253
|
+
// create the accessory handler for the restored accessory
|
|
1254
|
+
// this is imported from `platformAccessory.ts`
|
|
1255
|
+
new Presence(this, existingAccessory, device);
|
|
1256
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1257
|
+
}
|
|
1258
|
+
else {
|
|
1259
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
else if (await this.registerDevice(device)) {
|
|
1263
|
+
// create a new accessory
|
|
1264
|
+
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1265
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1266
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1267
|
+
// store a copy of the device object in the `accessory.context`
|
|
1268
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
1269
|
+
accessory.context.device = device;
|
|
1270
|
+
accessory.context.deviceId = device.deviceId;
|
|
1271
|
+
accessory.context.deviceType = device.deviceType;
|
|
1272
|
+
accessory.context.model = SwitchBotModel.PresenceSensor;
|
|
1273
|
+
accessory.displayName = device.configDeviceName
|
|
1274
|
+
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1275
|
+
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1276
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1277
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1278
|
+
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1279
|
+
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1280
|
+
this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1281
|
+
// create the accessory handler for the newly create accessory
|
|
1282
|
+
// this is imported from `platformAccessory.ts`
|
|
1283
|
+
new Presence(this, accessory, device);
|
|
1284
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1285
|
+
// publish device externally or link the accessory to your platform
|
|
1286
|
+
this.externalOrPlatform(device, accessory);
|
|
1287
|
+
this.accessories.push(accessory);
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1235
1293
|
async createContact(device) {
|
|
1236
1294
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1237
1295
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
@@ -1808,66 +1866,6 @@ export class SwitchBotPlatform {
|
|
|
1808
1866
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1809
1867
|
}
|
|
1810
1868
|
}
|
|
1811
|
-
async createAirPurifier(device) {
|
|
1812
|
-
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1813
|
-
// see if an accessory with the same uuid has already been registered and restored from
|
|
1814
|
-
// the cached devices we stored in the `configureAccessory` method above
|
|
1815
|
-
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
1816
|
-
if (existingAccessory) {
|
|
1817
|
-
// the accessory already exists
|
|
1818
|
-
if (await this.registerDevice(device)) {
|
|
1819
|
-
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1820
|
-
existingAccessory.context.device = device;
|
|
1821
|
-
existingAccessory.context.deviceId = device.deviceId;
|
|
1822
|
-
existingAccessory.context.deviceType = device.deviceType;
|
|
1823
|
-
existingAccessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1824
|
-
existingAccessory.displayName = device.configDeviceName
|
|
1825
|
-
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1826
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1827
|
-
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1828
|
-
existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1829
|
-
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`);
|
|
1830
|
-
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1831
|
-
// create the accessory handler for the restored accessory
|
|
1832
|
-
// this is imported from `platformAccessory.ts`
|
|
1833
|
-
new AirPurifier(this, existingAccessory, device);
|
|
1834
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1835
|
-
}
|
|
1836
|
-
else {
|
|
1837
|
-
this.unregisterPlatformAccessories(existingAccessory);
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
else if (await this.registerDevice(device)) {
|
|
1841
|
-
// create a new accessory
|
|
1842
|
-
const accessory = new this.api.platformAccessory(device.configDeviceName
|
|
1843
|
-
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1844
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid);
|
|
1845
|
-
// store a copy of the device object in the `accessory.context`
|
|
1846
|
-
// the `context` property can be used to store any data about the accessory you may need
|
|
1847
|
-
accessory.context.device = device;
|
|
1848
|
-
accessory.context.deviceId = device.deviceId;
|
|
1849
|
-
accessory.context.deviceType = device.deviceType;
|
|
1850
|
-
accessory.context.model = SwitchBotModel.BatteryCirculatorFan;
|
|
1851
|
-
accessory.displayName = device.configDeviceName
|
|
1852
|
-
? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
|
|
1853
|
-
: await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName);
|
|
1854
|
-
accessory.context.connectionType = await this.connectionType(device);
|
|
1855
|
-
accessory.context.connectionType = await this.connectionType(device);
|
|
1856
|
-
accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0';
|
|
1857
|
-
const newOrExternal = !device.external ? 'Adding new' : 'Loading external';
|
|
1858
|
-
this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
1859
|
-
// create the accessory handler for the newly create accessory
|
|
1860
|
-
// this is imported from `platformAccessory.ts`
|
|
1861
|
-
new AirPurifier(this, accessory, device);
|
|
1862
|
-
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1863
|
-
// publish device externally or link the accessory to your platform
|
|
1864
|
-
this.externalOrPlatform(device, accessory);
|
|
1865
|
-
this.accessories.push(accessory);
|
|
1866
|
-
}
|
|
1867
|
-
else {
|
|
1868
|
-
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`);
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
1869
|
async createRobotVacuumCleaner(device) {
|
|
1872
1870
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1873
1871
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
@@ -2173,7 +2171,7 @@ export class SwitchBotPlatform {
|
|
|
2173
2171
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} deviceId: ${device.deviceId}`);
|
|
2174
2172
|
}
|
|
2175
2173
|
}
|
|
2176
|
-
async
|
|
2174
|
+
async createAirPurifier(device) {
|
|
2177
2175
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
2178
2176
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
2179
2177
|
// the cached devices we stored in the `configureAccessory` method above
|
|
@@ -2194,7 +2192,7 @@ export class SwitchBotPlatform {
|
|
|
2194
2192
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
2195
2193
|
// create the accessory handler for the restored accessory
|
|
2196
2194
|
// this is imported from `platformAccessory.ts`
|
|
2197
|
-
new
|
|
2195
|
+
new AirPurifier(this, existingAccessory, device);
|
|
2198
2196
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
2199
2197
|
}
|
|
2200
2198
|
else {
|
|
@@ -2221,7 +2219,7 @@ export class SwitchBotPlatform {
|
|
|
2221
2219
|
this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`);
|
|
2222
2220
|
// create the accessory handler for the newly create accessory
|
|
2223
2221
|
// this is imported from `platformAccessory.ts`
|
|
2224
|
-
new
|
|
2222
|
+
new AirPurifier(this, accessory, device);
|
|
2225
2223
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
2226
2224
|
// publish device externally or link the accessory to your platform
|
|
2227
2225
|
this.externalOrPlatform(device, accessory);
|
|
@@ -2636,6 +2634,7 @@ export class SwitchBotPlatform {
|
|
|
2636
2634
|
hubDeviceId: '',
|
|
2637
2635
|
version: 0,
|
|
2638
2636
|
deviceName: '',
|
|
2637
|
+
enableCloudService: false,
|
|
2639
2638
|
}, statusCode: 500 };
|
|
2640
2639
|
}
|
|
2641
2640
|
async retryCommand(device, bodyChange, deviceMaxRetries, deviceDelayBetweenRetries) {
|