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 <github@klug.nrw>
  • Loading branch information
J-N-K authored Jan 30, 2024
1 parent fd65f7c commit a4c5f6c
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 a4c5f6c

Please sign in to comment.