|
28 | 28 | import org.openhab.binding.insteon.internal.device.InsteonDevice;
|
29 | 29 | import org.openhab.binding.insteon.internal.device.ProductData;
|
30 | 30 | import org.openhab.binding.insteon.internal.device.database.LinkDBRecord;
|
| 31 | +import org.openhab.binding.insteon.internal.device.database.ModemDBRecord; |
31 | 32 | import org.openhab.binding.insteon.internal.device.feature.FeatureEnums.KeypadButtonToggleMode;
|
32 | 33 | import org.openhab.binding.insteon.internal.handler.InsteonDeviceHandler;
|
33 | 34 | import org.openhab.binding.insteon.internal.handler.InsteonThingHandler;
|
@@ -465,9 +466,9 @@ private void listMissingLinks(Console console, String thingId) {
|
465 | 466 | console.println("The modem database is not loaded yet.");
|
466 | 467 | } else {
|
467 | 468 | List<String> deviceLinks = device.getMissingDeviceLinks().entrySet().stream()
|
468 |
| - .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue().getRecord())).toList(); |
| 469 | + .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue())).toList(); |
469 | 470 | List<String> modemLinks = device.getMissingModemLinks().entrySet().stream()
|
470 |
| - .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue().getRecord())).toList(); |
| 471 | + .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue())).toList(); |
471 | 472 | if (deviceLinks.isEmpty() && modemLinks.isEmpty()) {
|
472 | 473 | console.println("There are no missing links for device " + device.getAddress() + ".");
|
473 | 474 | } else {
|
@@ -499,33 +500,33 @@ private void addMissingLinks(Console console, String thingId) {
|
499 | 500 | console.println("The device " + thingId + " is not configured or enabled!");
|
500 | 501 | } else if (!device.getLinkDB().isComplete()) {
|
501 | 502 | console.println("The link database for device " + thingId + " is not loaded yet.");
|
502 |
| - } else if (!device.getLinkDB().getChanges().isEmpty()) { |
503 |
| - console.println("The link database for device " + thingId + " has pending changes."); |
504 | 503 | } else if (!getModem().getDB().isComplete()) {
|
505 | 504 | console.println("The modem database is not loaded yet.");
|
506 |
| - } else if (!getModem().getDB().getChanges().isEmpty()) { |
507 |
| - console.println("The modem database has pending changes."); |
508 | 505 | } else {
|
509 |
| - int deviceLinkCount = device.getMissingDeviceLinks().size(); |
510 |
| - int modemLinkCount = device.getMissingModemLinks().size(); |
511 |
| - if (deviceLinkCount == 0 && modemLinkCount == 0) { |
| 506 | + List<LinkDBRecord> deviceLinks = device.getMissingDeviceLinks().values().stream().toList(); |
| 507 | + List<ModemDBRecord> modemLinks = device.getMissingModemLinks().values().stream().toList(); |
| 508 | + if (deviceLinks.isEmpty() && modemLinks.isEmpty()) { |
512 | 509 | console.println("There are no missing links for device " + device.getAddress() + ".");
|
513 | 510 | } else {
|
514 |
| - if (deviceLinkCount > 0) { |
| 511 | + if (!deviceLinks.isEmpty()) { |
515 | 512 | if (!device.isAwake() || !device.isResponding()) {
|
516 |
| - console.println("Scheduling " + deviceLinkCount + " missing links for device " |
| 513 | + console.println("Scheduling " + deviceLinks.size() + " missing links for device " |
517 | 514 | + device.getAddress() + " to be added to its link database the next time it is "
|
518 | 515 | + (device.isBatteryPowered() ? "awake" : "online") + ".");
|
519 | 516 | } else {
|
520 |
| - console.println("Adding " + deviceLinkCount + " missing links for device " + device.getAddress() |
521 |
| - + " to its link database..."); |
| 517 | + console.println("Adding " + deviceLinks.size() + " missing links for device " |
| 518 | + + device.getAddress() + " to its link database..."); |
522 | 519 | }
|
523 |
| - device.addMissingDeviceLinks(); |
| 520 | + deviceLinks.forEach(record -> device.getLinkDB().markRecordForAddOrModify(record.getAddress(), |
| 521 | + record.getGroup(), record.isController(), record.getData())); |
| 522 | + device.getLinkDB().update(); |
524 | 523 | }
|
525 |
| - if (modemLinkCount > 0) { |
526 |
| - console.println("Adding " + modemLinkCount + " missing links for device " + device.getAddress() |
| 524 | + if (!modemLinks.isEmpty()) { |
| 525 | + console.println("Adding " + modemLinks.size() + " missing links for device " + device.getAddress() |
527 | 526 | + " to the modem database...");
|
528 |
| - device.addMissingModemLinks(); |
| 527 | + modemLinks.forEach(record -> getModem().getDB().markRecordForAddOrModify(record.getAddress(), |
| 528 | + record.getGroup(), record.isController(), record.getData())); |
| 529 | + getModem().getDB().update(); |
529 | 530 | }
|
530 | 531 | }
|
531 | 532 | }
|
|
0 commit comments