@switchbot/homebridge-switchbot 3.5.2-beta.0 → 3.5.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/device/bot.ts CHANGED
@@ -1162,92 +1162,132 @@ export class Bot extends deviceBase {
1162
1162
 
1163
1163
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
1164
1164
  // If outletService still present, then remove first
1165
- if (this.Outlet?.Service) {
1166
- this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
1167
- await this.warnLog('Removing Leftover Outlet Service');
1168
- accessory.removeService(this.Outlet.Service);
1169
- }
1165
+ accessory.context.Outlet = accessory.context.Outlet ?? {};
1166
+ this.Outlet = {
1167
+ Name: accessory.context.Outlet.Name ?? accessory.displayName,
1168
+ Service: accessory.getService(this.hap.Service.Outlet) as Service,
1169
+ On: accessory.context.On ?? false,
1170
+ };
1171
+ accessory.context.Outlet = this.Outlet as object;
1172
+ await this.warnLog('Removing any leftover Outlet Service');
1173
+ accessory.removeService(this.Outlet.Service);
1170
1174
  }
1171
1175
 
1172
1176
  async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
1173
1177
  // If garageDoorService still present, then remove first
1174
- if (this.GarageDoor?.Service) {
1175
- this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
1176
- await this.warnLog('Removing Leftover Garage Door Service');
1177
- accessory.removeService(this.GarageDoor.Service);
1178
- }
1178
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
1179
+ this.GarageDoor = {
1180
+ Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
1181
+ Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
1182
+ On: accessory.context.On ?? false,
1183
+ };
1184
+ accessory.context.GarageDoor = this.GarageDoor as object;
1185
+ await this.warnLog('Removing any leftover Garage Door Service');
1186
+ accessory.removeService(this.GarageDoor.Service);
1179
1187
  }
1180
1188
 
1181
1189
  async removeDoorService(accessory: PlatformAccessory): Promise<void> {
1182
1190
  // If doorService still present, then remove first
1183
- if (this.Door?.Service) {
1184
- this.Door.Service = this.accessory.getService(this.hap.Service.Door) as Service;
1185
- await this.warnLog('Removing Leftover Door Service');
1186
- accessory.removeService(this.Door.Service);
1187
- }
1191
+ accessory.context.Door = accessory.context.Door ?? {};
1192
+ this.Door = {
1193
+ Name: accessory.context.Door.Name ?? accessory.displayName,
1194
+ Service: accessory.getService(this.hap.Service.Door) as Service,
1195
+ On: accessory.context.On ?? false,
1196
+ };
1197
+ accessory.context.Door = this.Door as object;
1198
+ await this.warnLog('Removing any leftover Door Service');
1199
+ accessory.removeService(this.Door.Service);
1188
1200
  }
1189
1201
 
1190
1202
  async removeLockService(accessory: PlatformAccessory): Promise<void> {
1191
1203
  // If lockService still present, then remove first
1192
- if (this.LockMechanism?.Service) {
1193
- this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
1194
- this.warnLog('Removing Leftover Lock Service');
1195
- accessory.removeService(this.LockMechanism.Service);
1196
- }
1204
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
1205
+ this.LockMechanism = {
1206
+ Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
1207
+ Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
1208
+ On: accessory.context.On ?? false,
1209
+ };
1210
+ accessory.context.LockMechanism = this.LockMechanism as object;
1211
+ this.warnLog('Removing any leftover Lock Service');
1212
+ accessory.removeService(this.LockMechanism.Service);
1197
1213
  }
1198
1214
 
1199
1215
  async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
1200
1216
  // If faucetService still present, then remove first
1201
- if (this.Faucet?.Service) {
1202
- this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
1203
- await this.warnLog('Removing Leftover Faucet Service');
1204
- accessory.removeService(this.Faucet.Service);
1205
- }
1217
+ accessory.context.Faucet = accessory.context.Faucet ?? {};
1218
+ this.Faucet = {
1219
+ Name: accessory.context.Faucet.Name ?? accessory.displayName,
1220
+ Service: accessory.getService(this.hap.Service.Valve) as Service,
1221
+ On: accessory.context.On ?? false,
1222
+ };
1223
+ accessory.context.Faucet = this.Faucet as object;
1224
+ await this.warnLog('Removing any leftover Faucet Service');
1225
+ accessory.removeService(this.Faucet.Service);
1206
1226
  }
1207
1227
 
1208
1228
  async removeFanService(accessory: PlatformAccessory): Promise<void> {
1209
1229
  // If fanService still present, then remove first
1210
- if (this.Fan?.Service) {
1211
- this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2) as Service;
1212
- this.warnLog('Removing Leftover Fan Service');
1213
- accessory.removeService(this.Fan.Service);
1214
- }
1230
+ accessory.context.Fan = accessory.context.Fan ?? {};
1231
+ this.Fan = {
1232
+ Name: accessory.context.Fan.Name ?? accessory.displayName,
1233
+ Service: accessory.getService(this.hap.Service.Fan) as Service,
1234
+ On: accessory.context.On ?? false,
1235
+ };
1236
+ accessory.context.Fan = this.Fan as object;
1237
+ this.warnLog('Removing any leftover Fan Service');
1238
+ accessory.removeService(this.Fan.Service);
1215
1239
  }
1216
1240
 
1217
1241
  async removeWindowService(accessory: PlatformAccessory): Promise<void> {
1218
1242
  // If windowService still present, then remove first
1219
- if (this.Window?.Service) {
1220
- this.Window.Service = this.accessory.getService(this.hap.Service.Window) as Service;
1221
- await this.warnLog('Removing Leftover Window Service');
1222
- accessory.removeService(this.Window.Service);
1223
- }
1243
+ accessory.context.Window = accessory.context.Window ?? {};
1244
+ this.Window = {
1245
+ Name: accessory.context.Window.Name ?? accessory.displayName,
1246
+ Service: accessory.getService(this.hap.Service.Window) as Service,
1247
+ On: accessory.context.On ?? false,
1248
+ };
1249
+ accessory.context.Window = this.Window as object;
1250
+ await this.warnLog('Removing any leftover Window Service');
1251
+ accessory.removeService(this.Window.Service);
1224
1252
  }
1225
1253
 
1226
1254
  async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
1227
1255
  // If windowCoveringService still present, then remove first
1228
- if (this.WindowCovering?.Service) {
1229
- this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
1230
- await this.warnLog('Removing Leftover Window Covering Service');
1231
- accessory.removeService(this.WindowCovering.Service);
1232
- }
1256
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
1257
+ this.WindowCovering = {
1258
+ Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
1259
+ Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
1260
+ On: accessory.context.On ?? false,
1261
+ };
1262
+ accessory.context.WindowCovering = this.WindowCovering as object;
1263
+ await this.warnLog('Removing any leftover Window Covering Service');
1264
+ accessory.removeService(this.WindowCovering.Service);
1233
1265
  }
1234
1266
 
1235
1267
  async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
1236
1268
  // If statefulProgrammableSwitchService still present, then remove first
1237
- if (this.StatefulProgrammableSwitch?.Service) {
1238
- this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
1239
- await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
1240
- accessory.removeService(this.StatefulProgrammableSwitch.Service);
1241
- }
1269
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
1270
+ this.StatefulProgrammableSwitch = {
1271
+ Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
1272
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
1273
+ On: accessory.context.On ?? false,
1274
+ };
1275
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
1276
+ await this.warnLog('Removing any leftover Stateful Programmable Switch Service');
1277
+ accessory.removeService(this.StatefulProgrammableSwitch.Service);
1242
1278
  }
1243
1279
 
1244
1280
  async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
1245
1281
  // If switchService still present, then remove first
1246
- if (this.Switch?.Service) {
1247
- this.Switch.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
1248
- await this.warnLog('Removing Leftover Switch Service');
1249
- accessory.removeService(this.Switch.Service);
1250
- }
1282
+ accessory.context.Switch = accessory.context.Switch ?? {};
1283
+ this.Switch = {
1284
+ Name: accessory.context.Switch.Name ?? accessory.displayName,
1285
+ Service: accessory.getService(this.hap.Service.Switch) as Service,
1286
+ On: accessory.context.On ?? false,
1287
+ };
1288
+ accessory.context.Switch = this.Switch as object;
1289
+ await this.warnLog('Removing any leftover Switch Service');
1290
+ accessory.removeService(this.Switch.Service);
1251
1291
  }
1252
1292
 
1253
1293
  async getOn(): Promise<boolean> {
@@ -1322,63 +1362,43 @@ export class Bot extends deviceBase {
1322
1362
 
1323
1363
  async getBotConfigSettings(device: device & devicesConfig) {
1324
1364
  //Bot Device Type
1325
- if (!device.bot?.deviceType && this.accessory.context.deviceType) {
1326
- this.botDeviceType = this.accessory.context.deviceType;
1327
- await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
1328
- } else if (device.bot?.deviceType) {
1329
- this.accessory.context.deviceType = device.bot.deviceType;
1330
- await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
1331
- this.botDeviceType = this.accessory.context.deviceType;
1332
- await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
1333
- } else {
1334
- this.botDeviceType = 'outlet';
1335
- await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
1336
- await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
1337
- }
1365
+ this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
1366
+ : device.bot?.deviceType ?? 'outlet';
1367
+ const botDeviceType = this.accessory.context.botDeviceType ? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
1368
+ : device.bot?.deviceType ? `Using Device Type: ${this.botDeviceType}`
1369
+ : `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`;
1370
+ await this.debugWarnLog(botDeviceType);
1371
+ this.accessory.context.botDeviceType = this.botDeviceType;
1338
1372
  // Bot Mode
1339
- if (!device.bot?.mode) {
1340
- this.botMode = 'switch';
1341
- await this.warnLog('does not have bot mode set in the Plugin\'s SwitchBot Device Settings,');
1342
- await this.warnLog(`is defaulting to "${this.botMode}" mode, you may experience issues.`);
1343
- } else if (device.bot?.mode === 'switch') {
1344
- this.botMode = 'switch';
1345
- await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1346
- } else if (device.bot?.mode === 'press') {
1347
- this.botMode = 'press';
1348
- await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1349
- } else if (device.bot?.mode === 'multipress') {
1350
- this.botMode = 'multipress';
1351
- await this.debugLog(`Using Bot Mode: ${this.botMode}`);
1352
- } else {
1353
- throw new Error(`Bot Mode: ${this.botMode}`);
1354
- }
1355
-
1373
+ this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch';
1374
+ const botMode = this.accessory.context.botMode ? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
1375
+ : device.bot?.mode ? `Using Bot Mode: ${this.botMode}` : `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`;
1376
+ await this.debugWarnLog(botMode);
1377
+ this.accessory.context.botMode = this.botMode;
1356
1378
  // Bot Double Press
1357
- if (device.bot?.doublePress) {
1358
- this.doublePress = device.bot?.doublePress;
1359
- this.accessory.context.doublePress = this.doublePress;
1360
- } else {
1361
- this.doublePress = 1;
1362
- }
1363
-
1379
+ this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1;
1380
+ const doublePress = this.accessory.context.doublePress ? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
1381
+ : device.bot?.doublePress ? `Using Double Press: ${this.doublePress}`
1382
+ : `No Double Press Set, Using default Double Press: ${this.doublePress}`;
1383
+ await this.debugWarnLog(doublePress);
1384
+ this.accessory.context.doublePress = this.doublePress;
1364
1385
  // Bot Press PushRate
1365
- if (device?.bot?.pushRatePress) {
1366
- this.pushRatePress = device?.bot?.pushRatePress;
1367
- await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
1368
- } else {
1369
- this.pushRatePress = 15;
1370
- await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
1371
- }
1372
-
1386
+ this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15;
1387
+ const pushRatePress = this.accessory.context.pushRatePress ? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
1388
+ : device.bot?.pushRatePress ? `Using Bot Push Rate Press: ${this.pushRatePress}`
1389
+ : `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`;
1390
+ await this.debugWarnLog(pushRatePress);
1391
+ this.accessory.context.pushRatePress = this.pushRatePress;
1373
1392
  // Bot Allow Push
1374
- if (device.bot?.allowPush) {
1375
- this.allowPush = true;
1376
- } else {
1377
- this.allowPush = false;
1378
- }
1379
- await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
1393
+ this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false;
1394
+ const allowPush = this.accessory.context.allowPush ? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
1395
+ : device.bot?.allowPush ? `Using Allow Push: ${this.allowPush}`
1396
+ : `No Allow Push Set, Using default Allow Push: ${this.allowPush}`;
1397
+ await this.debugWarnLog(allowPush);
1398
+ this.accessory.context.allowPush = this.allowPush;
1380
1399
  // Bot Multi Press Count
1381
1400
  this.multiPressCount = 0;
1401
+ await this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`);
1382
1402
  }
1383
1403
 
1384
1404
  async BLEPushConnection() {
@@ -480,6 +480,7 @@ export abstract class deviceBase {
480
480
  case 'Bot':
481
481
  device.model = SwitchBotModel.Bot;
482
482
  device.bleModel = SwitchBotBLEModel.Bot;
483
+ device.bleModelName = SwitchBotBLEModelName.Bot;
483
484
  device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Bot;
484
485
  break;
485
486
  case 'Meter':
@@ -599,6 +600,7 @@ export abstract class deviceBase {
599
600
  case 'Robot Vacuum Cleaner S1':
600
601
  device.model = SwitchBotModel.RobotVacuumCleanerS1;
601
602
  device.bleModel = SwitchBotBLEModel.Unknown;
603
+ device.bleModelName = SwitchBotBLEModelName.Unknown;
602
604
  device.bleModelFriednlyName = SwitchBotBLEModelFriendlyName.Unknown;
603
605
  break;
604
606
  case 'Robot Vacuum Cleaner S1 Plus':