Skip to content

Commit

Permalink
[insteon] If the PLM or hub is not configured as a device, let discov…
Browse files Browse the repository at this point in the history
…ery find it (openhab#8184)

Signed-off-by: Rob Nielsen <[email protected]>
  • Loading branch information
robnielsen authored and andrewfg committed Aug 31, 2020
1 parent d6e127f commit a7f0160
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.insteon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ These have been tested and should work out of the box:
| 2450 | IO Link | 0x00001A | Bernd Pfrommer |
| 2486D | KeypadLinc Dimmer | 0x000037 | Patrick Giasson, Joe Barnum |
| 2484DWH8 | KeypadLinc Countdown Timer | 0x000041 | Rob Nielsen |
| 2413U | PowerLinc 2413U USB modem | 0x000045 | Bernd Pfrommer |
| Various | PLM or hub | 0x000045 | Bernd Pfrommer |
| 2843-222 | Wireless Open/Close Sensor | 0x000049 | Josenivaldo Benito |
| 2842-222 | Motion Sensor | 0x00004A | Bernd Pfrommer |
| 2844-222 | Motion Sensor II | F00.00.24 | Rob Nielsen |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.openhab.binding.insteon.internal.driver.ModemDBEntry;
import org.openhab.binding.insteon.internal.driver.Poller;
import org.openhab.binding.insteon.internal.driver.Port;
import org.openhab.binding.insteon.internal.handler.InsteonDeviceHandler;
import org.openhab.binding.insteon.internal.handler.InsteonNetworkHandler;
import org.openhab.binding.insteon.internal.message.FieldException;
import org.openhab.binding.insteon.internal.message.Msg;
Expand Down Expand Up @@ -254,6 +255,7 @@ public InsteonDevice makeNewDevice(InsteonAddress addr, String productKey) {
dev.setAddress(addr);
dev.setProductKey(productKey);
dev.setDriver(driver);
dev.setIsModem(productKey.equals(InsteonDeviceHandler.PLM_PRODUCT_KEY));
if (!dev.hasValidPollingInterval()) {
dev.setPollInterval(devicePollIntervalMilliseconds);
}
Expand Down Expand Up @@ -479,7 +481,7 @@ public void driverCompletelyInitialized() {
}

for (InsteonAddress k : dbes.keySet()) {
if (!addrs.contains(k) && !k.equals(dbes.get(k).getPort().getAddress())) {
if (!addrs.contains(k)) {
logger.debug("device {} found in the modem database, but is not configured as a thing and {}.",
k, getLinkInfo(dbes, k, true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void msg(Msg msg) {
}
} else if (msg.getByte("Cmd") == 0x57) {
// we got the link record response
updateModemDB(msg.getAddress("LinkAddr"), port, msg);
updateModemDB(msg.getAddress("LinkAddr"), port, msg, false);
port.writeMessage(Msg.makeMessage("GetNextALLLinkRecord"));
}
} catch (FieldException e) {
Expand Down Expand Up @@ -175,12 +175,12 @@ public static String toHex(byte b) {
return Utils.getHexString(b);
}

public void updateModemDB(InsteonAddress linkAddr, Port port, @Nullable Msg m) {
public void updateModemDB(InsteonAddress linkAddr, Port port, @Nullable Msg m, boolean isModem) {
try {
Map<InsteonAddress, @Nullable ModemDBEntry> dbes = port.getDriver().lockModemDBEntries();
ModemDBEntry dbe = dbes.get(linkAddr);
if (dbe == null) {
dbe = new ModemDBEntry(linkAddr);
dbe = new ModemDBEntry(linkAddr, isModem);
dbes.put(linkAddr, dbe);
}
dbe.setPort(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
@NonNullByDefault
public class ModemDBEntry {
private @Nullable InsteonAddress address = null;
private boolean isModem;
private @Nullable Port port = null;
private ArrayList<Msg> linkRecords = new ArrayList<>();
private ArrayList<Byte> controls = new ArrayList<>();
private ArrayList<Byte> respondsTo = new ArrayList<>();

public ModemDBEntry(InsteonAddress aAddr) {
public ModemDBEntry(InsteonAddress aAddr, boolean isModem) {
this.address = aAddr;
this.isModem = isModem;
}

public boolean isModem() {
return isModem;
}

public ArrayList<Msg> getLinkRecords() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ public void removeListener(MsgListener l) {
public void clearModemDB() {
logger.debug("clearing modem db!");
Map<InsteonAddress, @Nullable ModemDBEntry> dbes = getDriver().lockModemDBEntries();
dbes.clear();
for (InsteonAddress addr : dbes.keySet()) {
if (!dbes.get(addr).isModem()) {
dbes.remove(addr);
}
}
getDriver().unlockModemDBEntries();
}

Expand Down Expand Up @@ -521,7 +525,7 @@ public void msg(Msg msg) {
device.setDriver(driver);
device.setIsModem(true);
logger.debug("found modem {} in device_types: {}", a, device.toString());
mdbb.updateModemDB(a, Port.this, null);
mdbb.updateModemDB(a, Port.this, null, true);
}
// can unsubscribe now
removeListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ public void initialize() {
}
}

if (!channels.isEmpty()) {
updateThing(editThing().withChannels(channels).build());
if (!channels.isEmpty() || device.isModem()) {
if (!channels.isEmpty()) {
updateThing(editThing().withChannels(channels).build());
}

StringBuilder builder = new StringBuilder(thingId);
builder.append(" address = ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<option value="0x000037">2486D KeypadLinc Dimmer - 0x000037</option>
<option value="0x000039">2663-222 On/Off Outlet - 0x000039</option>
<option value="0x000041">2484DWH8 KeypadLinc Countdown Timer - 0x000041</option>
<option value="0x000045">2413U PowerLinc 2413U USB modem - 0x000045</option>
<option value="0x000045">PLM or hub - 0x000045</option>
<option value="0x000049">2843-222 Wireless Open/Close Sensor - 0x000049</option>
<option value="0x00004A">2842-222 Motion Sensor - 0x00004A</option>
<option value="0x000051">2486DWH8 KeypadLinc Dimmer - 0x000051</option>
Expand Down

0 comments on commit a7f0160

Please sign in to comment.