Skip to content

Commit

Permalink
[intesis] Add configurable polling interval (#15138)
Browse files Browse the repository at this point in the history
Signed-off-by: hmerk <github@hmerk.de>
  • Loading branch information
hmerk authored Jul 2, 2023
1 parent 676f53b commit ea7eb9f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
11 changes: 6 additions & 5 deletions bundles/org.openhab.binding.intesis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ 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 |
| 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String postRequest(String ipAddress, String contentString) {

String response = contentResponse.getContentAsString().replace("\t", "").replace("\r\n", "").trim();

if (response != null && !response.isEmpty()) {
if (!response.isEmpty()) {
return response;
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
public class IntesisBoxConfiguration {
public String ipAddress = "";
public int port;
public int pollingInterval = 45;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
public class IntesisHomeConfiguration {
public String ipAddress = "";
public String password = "";
public int pollingInterval = 30;
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public void initialize() {
config = getConfigAs(IntesisBoxConfiguration.class);

if (!config.ipAddress.isEmpty()) {

updateStatus(ThingStatus.UNKNOWN);
scheduler.submit(() -> {

Expand All @@ -107,14 +106,13 @@ public void initialize() {
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)");
}
Expand Down Expand Up @@ -237,7 +235,7 @@ private void receivedUpdate(String function, String receivedValue) {
break;

case "SETPTEMP":
if (value.equals("32768")) {
if ("32768".equals(value)) {
value = "0";
}
updateState(CHANNEL_TYPE_TARGETTEMP,
Expand Down Expand Up @@ -277,7 +275,7 @@ private void receivedUpdate(String function, String receivedValue) {

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 + ':')) {
Expand All @@ -295,7 +293,7 @@ private void handleMessage(String data) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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:
Expand Down Expand Up @@ -466,7 +466,7 @@ private void handleDataPointsResponse(Response response) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>

Expand Down

0 comments on commit ea7eb9f

Please sign in to comment.