Skip to content

Commit

Permalink
[tuya] Fix device reconnect (#565)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
(cherry picked from commit a4c5f6c)
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K committed Jan 30, 2024
1 parent 761dddc commit a1e9b0a
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<CommandOption> toCommandOptionList(List<String> options) {
return options.stream().map(c -> new CommandOption(c, c)).collect(Collectors.toList());
}
Expand Down

0 comments on commit a1e9b0a

Please sign in to comment.