|
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;
|
@@ -460,9 +461,9 @@ private void listMissingLinks(Console console, String thingId) {
|
460 | 461 | console.println("The modem database is not loaded yet.");
|
461 | 462 | } else {
|
462 | 463 | List<String> deviceLinks = device.getMissingDeviceLinks().entrySet().stream()
|
463 |
| - .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue().getRecord())).toList(); |
| 464 | + .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue())).toList(); |
464 | 465 | List<String> modemLinks = device.getMissingModemLinks().entrySet().stream()
|
465 |
| - .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue().getRecord())).toList(); |
| 466 | + .map(entry -> String.format("%s: %s", entry.getKey(), entry.getValue())).toList(); |
466 | 467 | if (deviceLinks.isEmpty() && modemLinks.isEmpty()) {
|
467 | 468 | console.println("There are no missing links for device " + device.getAddress() + ".");
|
468 | 469 | } else {
|
@@ -494,33 +495,33 @@ private void addMissingLinks(Console console, String thingId) {
|
494 | 495 | console.println("The device " + thingId + " is not configured or enabled!");
|
495 | 496 | } else if (!device.getLinkDB().isComplete()) {
|
496 | 497 | console.println("The link database for device " + thingId + " is not loaded yet.");
|
497 |
| - } else if (!device.getLinkDB().getChanges().isEmpty()) { |
498 |
| - console.println("The link database for device " + thingId + " has pending changes."); |
499 | 498 | } else if (!getModem().getDB().isComplete()) {
|
500 | 499 | console.println("The modem database is not loaded yet.");
|
501 |
| - } else if (!getModem().getDB().getChanges().isEmpty()) { |
502 |
| - console.println("The modem database has pending changes."); |
503 | 500 | } else {
|
504 |
| - int deviceLinkCount = device.getMissingDeviceLinks().size(); |
505 |
| - int modemLinkCount = device.getMissingModemLinks().size(); |
506 |
| - if (deviceLinkCount == 0 && modemLinkCount == 0) { |
| 501 | + List<LinkDBRecord> deviceLinks = device.getMissingDeviceLinks().values().stream().toList(); |
| 502 | + List<ModemDBRecord> modemLinks = device.getMissingModemLinks().values().stream().toList(); |
| 503 | + if (deviceLinks.isEmpty() && modemLinks.isEmpty()) { |
507 | 504 | console.println("There are no missing links for device " + device.getAddress() + ".");
|
508 | 505 | } else {
|
509 |
| - if (deviceLinkCount > 0) { |
| 506 | + if (!deviceLinks.isEmpty()) { |
510 | 507 | if (!device.isAwake() || !device.isResponding()) {
|
511 |
| - console.println("Scheduling " + deviceLinkCount + " missing links for device " |
| 508 | + console.println("Scheduling " + deviceLinks.size() + " missing links for device " |
512 | 509 | + device.getAddress() + " to be added to its link database the next time it is "
|
513 | 510 | + (device.isBatteryPowered() ? "awake" : "responding") + ".");
|
514 | 511 | } else {
|
515 |
| - console.println("Adding " + deviceLinkCount + " missing links for device " + device.getAddress() |
516 |
| - + " to its link database..."); |
| 512 | + console.println("Adding " + deviceLinks.size() + " missing links for device " |
| 513 | + + device.getAddress() + " to its link database..."); |
517 | 514 | }
|
518 |
| - device.addMissingDeviceLinks(); |
| 515 | + deviceLinks.forEach(record -> device.getLinkDB().markRecordForAddOrModify(record.getAddress(), |
| 516 | + record.getGroup(), record.isController(), record.getData())); |
| 517 | + device.getLinkDB().update(); |
519 | 518 | }
|
520 |
| - if (modemLinkCount > 0) { |
521 |
| - console.println("Adding " + modemLinkCount + " missing links for device " + device.getAddress() |
| 519 | + if (!modemLinks.isEmpty()) { |
| 520 | + console.println("Adding " + modemLinks.size() + " missing links for device " + device.getAddress() |
522 | 521 | + " to the modem database...");
|
523 |
| - device.addMissingModemLinks(); |
| 522 | + modemLinks.forEach(record -> getModem().getDB().markRecordForAddOrModify(record.getAddress(), |
| 523 | + record.getGroup(), record.isController(), record.getData())); |
| 524 | + getModem().getDB().update(); |
524 | 525 | }
|
525 | 526 | }
|
526 | 527 | }
|
|
0 commit comments