[somfytahoma] Faster feedback for commands initiated by the binding (#10409)

Also fix references to OH2

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2021-04-02 22:31:35 +02:00 committed by GitHub
parent e255dcd570
commit 4ff238d3f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,9 +166,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
*/
private void initPolling() {
stopPolling();
pollFuture = scheduler.scheduleWithFixedDelay(() -> {
getTahomaUpdates();
}, 10, thingConfig.getRefresh(), TimeUnit.SECONDS);
scheduleGetUpdates(10);
statusFuture = scheduler.scheduleWithFixedDelay(() -> {
refreshTahomaStates();
@ -179,6 +177,21 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
}, 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;
@ -638,9 +651,9 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
}
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);
@ -648,6 +661,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
if (!response.getExecId().isEmpty()) {
logger.debug("Exec id: {}", response.getExecId());
registerExecution(io, response.getExecId());
scheduleNextGetUpdates();
} else {
logger.debug("ExecId is empty!");
return false;
@ -689,7 +703,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
// 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("\"", "") : "";
}
@ -717,6 +731,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
}
if (execId != null) {
registerExecution(id, execId);
scheduleNextGetUpdates();
}
}