[intesis] Add configurable polling interval (#15138)

Signed-off-by: hmerk <github@hmerk.de>
This commit is contained in:
Hans-Jörg Merk 2023-07-02 21:10:32 +02:00 committed by GitHub
parent 676f53b55a
commit ea7eb9ff57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 15 deletions

View File

@ -20,10 +20,11 @@ Intesis devices do not support auto discovery.
The binding uses the following configuration parameters.
| Parameter | Valid for ThingType | Description |
|-----------|---------------------|----------------------------------------------------------------|
|------------------|---------------------|----------------------------------------------------------------|
| ipAddress | Both | IP-Address of the device |
| password | IntesisHome | Password to login to the local webserver of IntesisHome device |
| port | IntesisBox | TCP port to connect to IntesisBox device, defaults to 3310 |
| pollingInterval | Both | Interval to retrieve updates from the connected devices |
## Channels

View File

@ -27,7 +27,6 @@ public class IntesisBindingConstants {
public static final String BINDING_ID = "intesis";
public static final int INTESIS_HTTP_API_TIMEOUT_MS = 5000;
public static final int INTESIS_REFRESH_INTERVAL_SEC = 30;
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_INTESISHOME = new ThingTypeUID(BINDING_ID, "intesisHome");

View File

@ -63,7 +63,7 @@ public class IntesisHomeHttpApi {
String response = contentResponse.getContentAsString().replace("\t", "").replace("\r\n", "").trim();
if (response != null && !response.isEmpty()) {
if (!response.isEmpty()) {
return response;
} else {
return null;

View File

@ -23,4 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
public class IntesisBoxConfiguration {
public String ipAddress = "";
public int port;
public int pollingInterval = 45;
}

View File

@ -23,4 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
public class IntesisHomeConfiguration {
public String ipAddress = "";
public String password = "";
public int pollingInterval = 30;
}

View File

@ -93,7 +93,6 @@ public class IntesisBoxHandler extends BaseThingHandler implements IntesisBoxCha
config = getConfigAs(IntesisBoxConfiguration.class);
if (!config.ipAddress.isEmpty()) {
updateStatus(ThingStatus.UNKNOWN);
scheduler.submit(() -> {
@ -107,14 +106,13 @@ public class IntesisBoxHandler extends BaseThingHandler implements IntesisBoxCha
intesisLocalApi.sendId();
intesisLocalApi.sendLimitsQuery();
intesisLocalApi.sendAlive();
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
return;
}
updateStatus(ThingStatus.ONLINE);
});
pollingTask = scheduler.scheduleWithFixedDelay(this::polling, 3, 45, TimeUnit.SECONDS);
pollingTask = scheduler.scheduleWithFixedDelay(this::polling, 3, config.pollingInterval, TimeUnit.SECONDS);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No IP address specified)");
}
@ -237,7 +235,7 @@ public class IntesisBoxHandler extends BaseThingHandler implements IntesisBoxCha
break;
case "SETPTEMP":
if (value.equals("32768")) {
if ("32768".equals(value)) {
value = "0";
}
updateState(CHANNEL_TYPE_TARGETTEMP,
@ -277,7 +275,7 @@ public class IntesisBoxHandler extends BaseThingHandler implements IntesisBoxCha
private void handleMessage(String data) {
logger.debug("handleMessage(): Message received - {}", data);
if (data.equals("ACK") || data.equals("")) {
if ("ACK".equals(data) || "".equals(data)) {
return;
}
if (data.startsWith(ID + ':')) {
@ -295,7 +293,7 @@ public class IntesisBoxHandler extends BaseThingHandler implements IntesisBoxCha
case LIMITS:
logger.debug("handleMessage(): Limits received - {}", data);
String function = message.getFunction();
if (function.equals("SETPTEMP")) {
if ("SETPTEMP".equals(function)) {
List<Double> limits = message.getLimitsValue().stream().map(l -> Double.valueOf(l) / 10.0d)
.collect(Collectors.toList());
if (limits.size() == 2) {

View File

@ -137,7 +137,7 @@ public class IntesisHomeHandler extends BaseThingHandler {
int value = 0;
String channelId = channelUID.getId();
if (command instanceof RefreshType) {
// Refresh command is not supported as the binding polls all values every 30 seconds
getAllUidValues();
} else {
switch (channelId) {
case CHANNEL_TYPE_POWER:
@ -466,7 +466,7 @@ public class IntesisHomeHandler extends BaseThingHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
logger.trace("Start Refresh Job");
refreshJob = scheduler.scheduleWithFixedDelay(this::getAllUidValues, 0, INTESIS_REFRESH_INTERVAL_SEC,
refreshJob = scheduler.scheduleWithFixedDelay(this::getAllUidValues, 0, config.pollingInterval,
TimeUnit.SECONDS);
}

View File

@ -22,6 +22,15 @@
<description>@text/thing-type.config.intesisHome.password.description</description>
<context>password</context>
</parameter>
<parameter name="pollingInterval" type="decimal" min="30" unit="s">
<label>Polling Interval</label>
<description>
Defines the time in seconds to pull the
state of the connected devices. The minimum is 30
seconds.
</description>
<default>30</default>
</parameter>
</config-description>
</thing-type>
@ -46,6 +55,15 @@
<description>The TCP port to the IntesisBox.</description>
<default>3310</default>
</parameter>
<parameter name="pollingInterval" type="decimal" min="45" unit="s">
<label>Polling Interval</label>
<description>
Defines the time in seconds to pull the
state of the connected devices. The minimum is 45
seconds.
</description>
<default>45</default>
</parameter>
</config-description>
</thing-type>