[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:
parent
e255dcd570
commit
4ff238d3f4
@ -166,9 +166,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
*/
|
*/
|
||||||
private void initPolling() {
|
private void initPolling() {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
pollFuture = scheduler.scheduleWithFixedDelay(() -> {
|
scheduleGetUpdates(10);
|
||||||
getTahomaUpdates();
|
|
||||||
}, 10, thingConfig.getRefresh(), TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
statusFuture = scheduler.scheduleWithFixedDelay(() -> {
|
statusFuture = scheduler.scheduleWithFixedDelay(() -> {
|
||||||
refreshTahomaStates();
|
refreshTahomaStates();
|
||||||
@ -179,6 +177,21 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
}, RECONCILIATION_TIME, RECONCILIATION_TIME, TimeUnit.SECONDS);
|
}, 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() {
|
public synchronized void login() {
|
||||||
String url;
|
String url;
|
||||||
|
|
||||||
@ -638,9 +651,9 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendCommandInternal(String io, String command, String params, 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
|
String urlParameters = "{\"label\":\"" + getThingLabelByURL(io) + " - " + value
|
||||||
+ " - OH2\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
|
+ " - openHAB\",\"actions\":[{\"deviceURL\":\"" + io + "\",\"commands\":[{\"name\":\"" + command
|
||||||
+ "\",\"parameters\":" + params + "}]}]}";
|
+ "\",\"parameters\":" + params + "}]}]}";
|
||||||
SomfyTahomaApplyResponse response = invokeCallToURL(url, urlParameters, HttpMethod.POST,
|
SomfyTahomaApplyResponse response = invokeCallToURL(url, urlParameters, HttpMethod.POST,
|
||||||
SomfyTahomaApplyResponse.class);
|
SomfyTahomaApplyResponse.class);
|
||||||
@ -648,6 +661,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
if (!response.getExecId().isEmpty()) {
|
if (!response.getExecId().isEmpty()) {
|
||||||
logger.debug("Exec id: {}", response.getExecId());
|
logger.debug("Exec id: {}", response.getExecId());
|
||||||
registerExecution(io, response.getExecId());
|
registerExecution(io, response.getExecId());
|
||||||
|
scheduleNextGetUpdates();
|
||||||
} else {
|
} else {
|
||||||
logger.debug("ExecId is empty!");
|
logger.debug("ExecId is empty!");
|
||||||
return false;
|
return false;
|
||||||
@ -689,7 +703,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
// Return label from Tahoma
|
// Return label from Tahoma
|
||||||
return th.getProperties().get(NAME_STATE).replace("\"", "");
|
return th.getProperties().get(NAME_STATE).replace("\"", "");
|
||||||
}
|
}
|
||||||
// Return label from OH2
|
// Return label from the thing
|
||||||
String label = th.getLabel();
|
String label = th.getLabel();
|
||||||
return label != null ? label.replace("\"", "") : "";
|
return label != null ? label.replace("\"", "") : "";
|
||||||
}
|
}
|
||||||
@ -717,6 +731,7 @@ public class SomfyTahomaBridgeHandler extends BaseBridgeHandler {
|
|||||||
}
|
}
|
||||||
if (execId != null) {
|
if (execId != null) {
|
||||||
registerExecution(id, execId);
|
registerExecution(id, execId);
|
||||||
|
scheduleNextGetUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user