Skip to content

Commit 6219f2a

Browse files
committed
KlapProtocol immediate relogin if protocol invalid
In case of HTTP403 response to a request, the binding now executes repeat login and then retries the request, avoiding unnecessary device-offline report. This situation typically occurs if a Tapo Hub or Tapo-App is also polling the Tapo device. (Copilot issues addressed 1.0) Closes #20316 Signed-off-by: David Henshaw <david@henshaws.me>
1 parent f6f676d commit 6219f2a

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

  • bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/protocol/klap

bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/protocol/klap/KlapProtocol.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void sendRequestRetryable(TapoBaseRequestInterface tapoRequest) throws T
143143
* (Protocol can be rejected due to polling from another device e.g. Tapo App, or Tapo H100 Hub)
144144
* For asynchronous use, call on separate thread
145145
*/
146-
final int MAX_ATTEMPTS = 3;
146+
final int maxAttempts = 3;
147147
int attemptCount = 0;
148148
String url = getUrl();
149149
String command = tapoRequest.method();
@@ -163,14 +163,14 @@ private void sendRequestRetryable(TapoBaseRequestInterface tapoRequest) throws T
163163
logger.trace("({}) sendRequestRetryable re-login successful attempt {}", uid, attemptCount);
164164
} catch (TapoErrorHandler e) {
165165
logger.trace("({}) sendRequestRetryable error1 {}", uid, e.getMessage());
166-
if (attemptCount < MAX_ATTEMPTS) {
166+
if (attemptCount < maxAttempts) {
167167
continue;
168168
}
169169
httpDelegator.handleError(e);
170170
return;
171171
} catch (Exception ex) {
172172
logger.trace("({}) sendRequestRetryable error2 {}", uid, ex.getMessage());
173-
if (attemptCount < MAX_ATTEMPTS) {
173+
if (attemptCount < maxAttempts) {
174174
continue;
175175
}
176176
httpDelegator.handleError(new TapoErrorHandler(ERR_BINDING_LOGIN, ex.getMessage()));
@@ -210,7 +210,7 @@ private void sendRequestRetryable(TapoBaseRequestInterface tapoRequest) throws T
210210
* Forbidden - likely cause Encryption no longer valid - retry with login unless we have already
211211
* retried...
212212
*/
213-
if (attemptCount < MAX_ATTEMPTS) {
213+
if (attemptCount < maxAttempts) {
214214
continue;
215215
} else {
216216
logger.debug("({}) sendRequestRetryable response error'{}'", uid, response.getStatus());
@@ -234,13 +234,8 @@ private void sendRequestRetryable(TapoBaseRequestInterface tapoRequest) throws T
234234
throw new TapoErrorHandler(e, "error sending content");
235235
} catch (Exception e) {
236236
String errorMessage = e.getMessage();
237-
if (e instanceof TimeoutException) {
238-
logger.debug("({}) sendRequestRetryable timeout'{}'", uid, errorMessage);
239-
httpDelegator.handleError(new TapoErrorHandler(ERR_BINDING_CONNECT_TIMEOUT, errorMessage));
240-
} else {
241-
logger.debug("({}) sendRequestRetryable failed'{}'", uid, errorMessage);
242-
httpDelegator.handleError(new TapoErrorHandler(new Exception(e), errorMessage));
243-
}
237+
logger.debug("({}) sendRequestRetryable failed'{}'", uid, errorMessage);
238+
httpDelegator.handleError(new TapoErrorHandler(new Exception(e), errorMessage));
244239
return;
245240
}
246241
} /* end of loop */

0 commit comments

Comments
 (0)