From a4c5f6c99cb93b047407dd56ef5a6fd27e797fc6 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Tue, 30 Jan 2024 16:45:57 +0100 Subject: [PATCH] [tuya] Fix device reconnect (#565) Signed-off-by: Jan N. Klug --- .../tuya/internal/handler/TuyaDeviceHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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()); }