*/
private void initPolling() {
stopPolling();
- pollFuture = scheduler.scheduleWithFixedDelay(() -> {
- getTahomaUpdates();
- }, 10, thingConfig.getRefresh(), TimeUnit.SECONDS);
+ scheduleGetUpdates(10);
statusFuture = scheduler.scheduleWithFixedDelay(() -> {
refreshTahomaStates();
}, RECONCILIATION_TIME, RECONCILIATION_TIME, TimeUnit.SECONDS);
}
+ private void scheduleGetUpdates(long delay) {
+ pollFuture = scheduler.schedule(() -> {
+ getTahomaUpdates();
+ scheduleNextGetUpdates();
+ }, delay, TimeUnit.SECONDS);
+ }
+
+ private void scheduleNextGetUpdates() {
+ ScheduledFuture<?> localPollFuture = pollFuture;
+ if (localPollFuture != null) {
+ localPollFuture.cancel(false);
+ }
+ scheduleGetUpdates(executions.isEmpty() ? thingConfig.getRefresh() : 2);
+ }
+
public synchronized void login() {
String url;
}
private boolean sendCommandInternal(String io, String command, String params, String url) {
- String value = params.equals("[]") ? command : params.replace("\"", "");
+ String value = params.equals("[]") ? command : command + " " + params.replace("\"", "");
String urlParameters = "{\"label\":\"" + getThingLabelByURL(io) + " - " + value
- + " - OH2\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
+ + " - openHAB\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
+ "\",\"parameters\":" + params + "}]}]}";
SomfyTahomaApplyResponse response = invokeCallToURL(url, urlParameters, HttpMethod.POST,
SomfyTahomaApplyResponse.class);
if (!response.getExecId().isEmpty()) {
logger.debug("Exec id: {}", response.getExecId());
registerExecution(io, response.getExecId());
+ scheduleNextGetUpdates();
} else {
logger.debug("ExecId is empty!");
return false;
// Return label from Tahoma
return th.getProperties().get(NAME_STATE).replace("\"", "");
}
- // Return label from OH2
+ // Return label from the thing
String label = th.getLabel();
return label != null ? label.replace("\"", "") : "";
}
}
if (execId != null) {
registerExecution(id, execId);
+ scheduleNextGetUpdates();
}
}