]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lutron] Replace calls to methods deprecated in Java 11 (#8602)
authorBob A <bobadair@users.noreply.github.com>
Tue, 29 Sep 2020 17:16:54 +0000 (13:16 -0400)
committerGitHub <noreply@github.com>
Tue, 29 Sep 2020 17:16:54 +0000 (10:16 -0700)
* [lutron] Replace calls to methods deprecated in Java 11
* [lutron] Resolve comments

Signed-off-by: Bob Adair <bob.github@att.net>
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/action/DimmerActions.java
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/config/DimmerConfig.java
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/GreenModeHandler.java
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/TimeclockHandler.java
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/protocol/LutronDuration.java

index 14310ddeb2a1c0f749ce2c2c5961fbc98df38f80..b7d4f40e3eedd8b9612d5470f11de2ac5f359ebc 100644 (file)
@@ -15,6 +15,7 @@ package org.openhab.binding.lutron.action;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -90,7 +91,7 @@ public class DimmerActions implements ThingActions, IDimmerActions {
             lightLevel = 0.0;
         }
         try {
-            dimmerHandler.setLightLevel(new BigDecimal(lightLevel).setScale(2, BigDecimal.ROUND_HALF_UP),
+            dimmerHandler.setLightLevel(new BigDecimal(lightLevel).setScale(2, RoundingMode.HALF_UP),
                     new LutronDuration(fadeTime), new LutronDuration(delayTime));
         } catch (IllegalArgumentException e) {
             logger.debug("Ignoring setLevel command due to illegal argument exception: {}", e.getMessage());
index 8a1d57c571fcd7e7000c01360ff29f2ab83b283b..0be4cd2823d5845b09629484feeaa670f297fc06 100644 (file)
@@ -31,5 +31,5 @@ public class DimmerConfig {
     public BigDecimal fadeInTime = new BigDecimal(DEFAULT_FADE);
     public BigDecimal fadeOutTime = new BigDecimal(DEFAULT_FADE);
     public BigDecimal onLevel = new BigDecimal(DEFAULT_ONLEVEL);
-    public Boolean onToLast = new Boolean(DEFAULT_ONTOLAST);
+    public Boolean onToLast = DEFAULT_ONTOLAST;
 }
index 55a571299536880307767d5637e48f7e5c3527bc..62d81ba2a58860be0bb098d730e0c9601f215765 100644 (file)
@@ -113,10 +113,11 @@ public class GreenModeHandler extends LutronHandler {
     }
 
     private void stopPolling() {
+        ScheduledFuture<?> pollJob = this.pollJob;
         if (pollJob != null) {
+            this.pollJob = null;
             logger.debug("Canceling green mode polling job for integration ID {}", integrationId);
             pollJob.cancel(true);
-            pollJob = null;
         }
     }
 
@@ -140,7 +141,7 @@ public class GreenModeHandler extends LutronHandler {
             } else if (command == OnOffType.OFF) {
                 greenMode(ACTION_STEP, 1);
             } else if (command instanceof Number) {
-                Integer step = new Integer(((Number) command).intValue());
+                Integer step = ((Number) command).intValue();
                 if (step.intValue() >= GREENSTEP_MIN) {
                     greenMode(ACTION_STEP, step);
                 }
@@ -159,7 +160,7 @@ public class GreenModeHandler extends LutronHandler {
         try {
             if (type == LutronCommandType.MODE && parameters.length > 1
                     && ACTION_STEP.toString().equals(parameters[0])) {
-                Long step = new Long(parameters[1]);
+                Long step = Long.valueOf(parameters[1]);
                 if (getThing().getStatus() == ThingStatus.UNKNOWN) {
                     updateStatus(ThingStatus.ONLINE);
                     startPolling();
index ec6ab63ebb3a04d35ae7fbb0e3eaa54059b58593..6113103a716de55cfa96516e3b9ec107c5da6663 100644 (file)
@@ -102,7 +102,7 @@ public class TimeclockHandler extends LutronHandler {
 
         if (channelUID.getId().equals(CHANNEL_CLOCKMODE)) {
             if (command instanceof DecimalType) {
-                Integer mode = new Integer(((DecimalType) command).intValue());
+                Integer mode = ((DecimalType) command).intValue();
                 timeclock(ACTION_CLOCKMODE, mode);
             } else if (command instanceof RefreshType) {
                 queryTimeclock(ACTION_CLOCKMODE);
@@ -111,7 +111,7 @@ public class TimeclockHandler extends LutronHandler {
             }
         } else if (channelUID.getId().equals(CHANNEL_EXECEVENT)) {
             if (command instanceof DecimalType) {
-                Integer index = new Integer(((DecimalType) command).intValue());
+                Integer index = ((DecimalType) command).intValue();
                 timeclock(ACTION_EXECEVENT, index);
             } else {
                 logger.debug("Invalid command type for execevent channnel");
@@ -130,14 +130,14 @@ public class TimeclockHandler extends LutronHandler {
             }
         } else if (channelUID.getId().equals(CHANNEL_ENABLEEVENT)) {
             if (command instanceof DecimalType) {
-                Integer index = new Integer(((DecimalType) command).intValue());
+                Integer index = ((DecimalType) command).intValue();
                 timeclock(ACTION_SETEVENT, index, EVENT_ENABLE);
             } else {
                 logger.debug("Invalid command type for enableevent channnel");
             }
         } else if (channelUID.getId().equals(CHANNEL_DISABLEEVENT)) {
             if (command instanceof DecimalType) {
-                Integer index = new Integer(((DecimalType) command).intValue());
+                Integer index = ((DecimalType) command).intValue();
                 timeclock(ACTION_SETEVENT, index, EVENT_DISABLE);
             } else {
                 logger.debug("Invalid command type for disableevent channnel");
@@ -173,7 +173,7 @@ public class TimeclockHandler extends LutronHandler {
 
         try {
             if (parameters.length >= 2 && ACTION_CLOCKMODE.toString().equals(parameters[0])) {
-                Integer mode = new Integer(parameters[1]);
+                Integer mode = Integer.valueOf(parameters[1]);
                 if (getThing().getStatus() == ThingStatus.UNKNOWN) {
                     updateStatus(ThingStatus.ONLINE);
                 }
@@ -194,12 +194,12 @@ public class TimeclockHandler extends LutronHandler {
                 }
 
             } else if (parameters.length >= 2 && ACTION_EXECEVENT.toString().equals(parameters[0])) {
-                Integer index = new Integer(parameters[1]);
+                Integer index = Integer.valueOf(parameters[1]);
                 updateState(CHANNEL_EXECEVENT, new DecimalType(index));
 
             } else if (parameters.length >= 3 && ACTION_SETEVENT.toString().equals(parameters[0])) {
-                Integer index = new Integer(parameters[1]);
-                Integer state = new Integer(parameters[2]);
+                Integer index = Integer.valueOf(parameters[1]);
+                Integer state = Integer.valueOf(parameters[2]);
                 if (state.equals(EVENT_ENABLE)) {
                     updateState(CHANNEL_ENABLEEVENT, new DecimalType(index));
                 } else if (state.equals(EVENT_DISABLE)) {
index ef1c1aded81ca9e87065466d1c9a48c897c38522..a8b97bc7838072677e015052a6ed38583ed005e8 100644 (file)
@@ -13,6 +13,7 @@
 package org.openhab.binding.lutron.internal.protocol;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -75,7 +76,7 @@ public class LutronDuration {
      * Constructor accepting duration in seconds as a Double
      */
     public LutronDuration(Double seconds) {
-        this(new BigDecimal(seconds).setScale(2, BigDecimal.ROUND_HALF_UP));
+        this(new BigDecimal(seconds).setScale(2, RoundingMode.HALF_UP));
     }
 
     /**