]> git.basschouten.com Git - openhab-addons.git/commitdiff
[intesis] Add configurable polling interval (#15138)
authorHans-Jörg Merk <github@hmerk.de>
Sun, 2 Jul 2023 19:10:32 +0000 (21:10 +0200)
committerGitHub <noreply@github.com>
Sun, 2 Jul 2023 19:10:32 +0000 (21:10 +0200)
Signed-off-by: hmerk <github@hmerk.de>
bundles/org.openhab.binding.intesis/README.md
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/IntesisBindingConstants.java
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/api/IntesisHomeHttpApi.java
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/config/IntesisBoxConfiguration.java
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/config/IntesisHomeConfiguration.java
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/handler/IntesisBoxHandler.java
bundles/org.openhab.binding.intesis/src/main/java/org/openhab/binding/intesis/internal/handler/IntesisHomeHandler.java
bundles/org.openhab.binding.intesis/src/main/resources/OH-INF/thing/thing-types.xml

index b591e6ddffca33e46441fa40b7c8b80096b8b3cc..648987bc71e567855048540fad5dae91fbc80358 100644 (file)
@@ -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
 
index b63017ea30ee59e3b1a12564f0570a2c8365e6f9..1ee3b1f15dde3e84d13afd4cd9d6794151a1aafa 100644 (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");
index 6f28d7d4bad8114ca71aeb3a12a255dd53e422a7..19bf1561b67227b07d8893dac1fac5bee102750c 100644 (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;
index d7ae5040553a6dc256f6903af41de545e1e59bb1..20fd281eaf03133343bd7e96f887a76c069884de 100644 (file)
@@ -23,4 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 public class IntesisBoxConfiguration {
     public String ipAddress = "";
     public int port;
+    public int pollingInterval = 45;
 }
index ed5c7f9424511fa4896b3f3bee6a7b1ea4d27c69..933efcaa4b065d0e35215add49e1feaddce444cc 100644 (file)
@@ -23,4 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 public class IntesisHomeConfiguration {
     public String ipAddress = "";
     public String password = "";
+    public int pollingInterval = 30;
 }
index 8257d47e3bef7423870de5a2ac7b25d3fe8e9760..8de6e1af2d800d0928f7a08f4cdc4e2b927b56e2 100644 (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) {
index 2e9e80dd9658f021acc522917e2c448d016f2227..f352fc2a6edbc831cab0804e95ca0a0d2c22b6c5 100644 (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);
     }
 
index 32d2cef57fb1b842fd5b885ca948aeceaa4e4617..703981bab9c633eb812c136634695a7e486b0b6b 100644 (file)
                                <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>
 
                                <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>