From bc1ecd5932f5e5043aa4918356305fce4ae32459 Mon Sep 17 00:00:00 2001 From: "Jan N. Klug" Date: Tue, 30 Jan 2024 17:27:49 +0100 Subject: [PATCH] [tuya] Fix device reconnect (#565) Signed-off-by: Jan N. Klug (cherry picked from commit a4c5f6c99cb93b047407dd56ef5a6fd27e797fc6) 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 781f8c7bca..c1bbad332f 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 @@ -247,7 +247,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(); } @@ -563,6 +563,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()); }