[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:
parent
25660991e6
commit
3349cf4945
|
@ -320,6 +320,7 @@ public class InsteonBinding {
|
||||||
} else {
|
} else {
|
||||||
if (driver.isModemDBComplete() && !addr.isX10()) {
|
if (driver.isModemDBComplete() && !addr.isX10()) {
|
||||||
logger.warn("device {} not found in the modem database. Did you forget to link?", addr);
|
logger.warn("device {} not found in the modem database. Did you forget to link?", addr);
|
||||||
|
handler.deviceNotLinked(addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dbes.size();
|
return dbes.size();
|
||||||
|
@ -488,6 +489,7 @@ public class InsteonBinding {
|
||||||
if (!dbes.containsKey(a)) {
|
if (!dbes.containsKey(a)) {
|
||||||
if (!a.isX10()) {
|
if (!a.isX10()) {
|
||||||
logger.warn("device {} not found in the modem database. Did you forget to link?", a);
|
logger.warn("device {} not found in the modem database. Did you forget to link?", a);
|
||||||
|
handler.deviceNotLinked(a);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!dev.hasModemDBEntry()) {
|
if (!dev.hasModemDBEntry()) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
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.InsteonBinding;
|
||||||
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
|
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
|
||||||
import org.openhab.binding.insteon.internal.config.InsteonChannelConfiguration;
|
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 final Logger logger = LoggerFactory.getLogger(InsteonDeviceHandler.class);
|
||||||
|
|
||||||
private @Nullable InsteonDeviceConfiguration config;
|
private @NonNullByDefault({}) InsteonDeviceConfiguration config;
|
||||||
|
private boolean deviceLinked = true;
|
||||||
|
|
||||||
public InsteonDeviceHandler(Thing thing) {
|
public InsteonDeviceHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
|
@ -134,6 +134,7 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
config = getConfigAs(InsteonDeviceConfiguration.class);
|
config = getConfigAs(InsteonDeviceConfiguration.class);
|
||||||
|
deviceLinked = true;
|
||||||
|
|
||||||
scheduler.execute(() -> {
|
scheduler.execute(() -> {
|
||||||
final Bridge bridge = getBridge();
|
final Bridge bridge = getBridge();
|
||||||
|
@ -373,7 +374,9 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ThingStatus.ONLINE == bridge.getStatus()) {
|
if (ThingStatus.ONLINE == bridge.getStatus()) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
if (deviceLinked) {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
}
|
}
|
||||||
|
@ -533,6 +536,18 @@ public class InsteonDeviceHandler extends BaseThingHandler {
|
||||||
logger.debug("channel {} unlinked ", channelUID.getAsString());
|
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() {
|
private InsteonNetworkHandler getInsteonNetworkHandler() {
|
||||||
Bridge bridge = getBridge();
|
Bridge bridge = getBridge();
|
||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.insteon.internal.InsteonBinding;
|
import org.openhab.binding.insteon.internal.InsteonBinding;
|
||||||
import org.openhab.binding.insteon.internal.config.InsteonNetworkConfiguration;
|
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.binding.insteon.internal.discovery.InsteonDeviceDiscoveryService;
|
||||||
import org.openhab.core.io.console.Console;
|
import org.openhab.core.io.console.Console;
|
||||||
import org.openhab.core.io.transport.serial.SerialPortManager;
|
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) {
|
public void displayDevices(Console console) {
|
||||||
display(console, deviceInfo);
|
display(console, deviceInfo);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue