Skip to content

Commit

Permalink
[insteon] set device offline if it doesn't exist in the plm/hub datab…
Browse files Browse the repository at this point in the history
…ase (openhab#12904)

* [insteon] set device offline if it doesn't exist in the plm/hub database
* [insteon] use a flag to indicate if a device is linked or not
* [insteon] set config to @NonNullByDefault({}) instead of @nullable
* [insteon] cleanup

Signed-off-by: Rob Nielsen <[email protected]>
  • Loading branch information
robnielsen authored and psmedley committed Feb 23, 2023
1 parent 4e2d004 commit 8aef0ee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ private int checkIfInModemDatabase(InsteonDevice dev) {
} else {
if (driver.isModemDBComplete() && !addr.isX10()) {
logger.warn("device {} not found in the modem database. Did you forget to link?", addr);
handler.deviceNotLinked(addr);
}
}
return dbes.size();
Expand Down Expand Up @@ -488,6 +489,7 @@ public void driverCompletelyInitialized() {
if (!dbes.containsKey(a)) {
if (!a.isX10()) {
logger.warn("device {} not found in the modem database. Did you forget to link?", a);
handler.deviceNotLinked(a);
}
} else {
if (!dev.hasModemDBEntry()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.insteon.internal.InsteonBinding;
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
import org.openhab.binding.insteon.internal.config.InsteonChannelConfiguration;
Expand Down Expand Up @@ -125,7 +124,8 @@ public class InsteonDeviceHandler extends BaseThingHandler {

private final Logger logger = LoggerFactory.getLogger(InsteonDeviceHandler.class);

private @Nullable InsteonDeviceConfiguration config;
private @NonNullByDefault({}) InsteonDeviceConfiguration config;
private boolean deviceLinked = true;

public InsteonDeviceHandler(Thing thing) {
super(thing);
Expand All @@ -134,6 +134,7 @@ public InsteonDeviceHandler(Thing thing) {
@Override
public void initialize() {
config = getConfigAs(InsteonDeviceConfiguration.class);
deviceLinked = true;

scheduler.execute(() -> {
final Bridge bridge = getBridge();
Expand Down Expand Up @@ -373,7 +374,9 @@ public void initialize() {
});

if (ThingStatus.ONLINE == bridge.getStatus()) {
updateStatus(ThingStatus.ONLINE);
if (deviceLinked) {
updateStatus(ThingStatus.ONLINE);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
Expand Down Expand Up @@ -533,6 +536,18 @@ public void channelUnlinked(ChannelUID channelUID) {
logger.debug("channel {} unlinked ", channelUID.getAsString());
}

public InsteonAddress getInsteonAddress() {
return new InsteonAddress(config.getAddress());
}

public void deviceNotLinked() {
String msg = "device with the address '" + config.getAddress()
+ "' was not found in the modem database. Did you forget to link?";
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);

deviceLinked = false;
}

private InsteonNetworkHandler getInsteonNetworkHandler() {
Bridge bridge = getBridge();
if (bridge == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.insteon.internal.InsteonBinding;
import org.openhab.binding.insteon.internal.config.InsteonNetworkConfiguration;
import org.openhab.binding.insteon.internal.device.InsteonAddress;
import org.openhab.binding.insteon.internal.discovery.InsteonDeviceDiscoveryService;
import org.openhab.core.io.console.Console;
import org.openhab.core.io.transport.serial.SerialPortManager;
Expand Down Expand Up @@ -205,6 +206,16 @@ public void addMissingDevices(List<String> missing) {
});
}

public void deviceNotLinked(InsteonAddress addr) {
getThing().getThings().stream().forEach((thing) -> {
InsteonDeviceHandler handler = (InsteonDeviceHandler) thing.getHandler();
if (handler != null && addr.equals(handler.getInsteonAddress())) {
handler.deviceNotLinked();
return;
}
});
}

public void displayDevices(Console console) {
display(console, deviceInfo);
}
Expand Down

0 comments on commit 8aef0ee

Please sign in to comment.