[insteon] set device offline if it doesn't exist in the plm/hub database (#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 <rob.nielsen@yahoo.com>
This commit is contained in:
robnielsen 2022-06-14 16:26:08 -05:00 committed by GitHub
parent 25660991e6
commit 3349cf4945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 3 deletions

View File

@ -320,6 +320,7 @@ public class InsteonBinding {
} 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();
@ -488,6 +489,7 @@ public class InsteonBinding {
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()) {

View File

@ -26,7 +26,6 @@ import java.util.stream.Collectors;
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;
@ -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);
@ -134,6 +134,7 @@ public class InsteonDeviceHandler extends BaseThingHandler {
@Override
public void initialize() {
config = getConfigAs(InsteonDeviceConfiguration.class);
deviceLinked = true;
scheduler.execute(() -> {
final Bridge bridge = getBridge();
@ -373,7 +374,9 @@ public class InsteonDeviceHandler extends BaseThingHandler {
});
if (ThingStatus.ONLINE == bridge.getStatus()) {
updateStatus(ThingStatus.ONLINE);
if (deviceLinked) {
updateStatus(ThingStatus.ONLINE);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
@ -533,6 +536,18 @@ public class InsteonDeviceHandler extends BaseThingHandler {
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) {

View File

@ -23,6 +23,7 @@ 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.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;
@ -205,6 +206,16 @@ public class InsteonNetworkHandler extends BaseBridgeHandler {
});
}
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);
}