diff --git a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java index 89581d79fe..1dff20a348 100644 --- a/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java +++ b/bundles/org.smarthomej.binding.tuya/src/main/java/org/smarthomej/binding/tuya/internal/handler/TuyaDeviceHandler.java @@ -248,7 +248,7 @@ public void connectionStatus(boolean status) { // only re-connect if a device is present, we are not disposing the thing and either the reconnectFuture is // empty or already done if (tuyaDevice != null && !disposing && (reconnectFuture == null || reconnectFuture.isDone())) { - this.reconnectFuture = scheduler.schedule(tuyaDevice::connect, 5000, TimeUnit.MILLISECONDS); + this.reconnectFuture = scheduler.schedule(this::connectDevice, 5000, TimeUnit.MILLISECONDS); } irStopLearning(); } @@ -564,6 +564,17 @@ private void configureChannel(Channel channel) { } } + private void connectDevice() { + TuyaDevice tuyaDevice = this.tuyaDevice; + if (tuyaDevice == null) { + logger.warn("Cannot connect {} because the device is not set.", thing.getUID()); + return; + } + // clear the future here because timing issues can prevent the next attempt if we fail again + reconnectFuture = null; + tuyaDevice.connect(); + } + private List toCommandOptionList(List options) { return options.stream().map(c -> new CommandOption(c, c)).collect(Collectors.toList()); }