]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth.daikinmadoka] null annotations (#13975)
authorlsiepel <leosiepel@gmail.com>
Tue, 27 Dec 2022 16:12:58 +0000 (17:12 +0100)
committerGitHub <noreply@github.com>
Tue, 27 Dec 2022 16:12:58 +0000 (17:12 +0100)
* null annotations - sat warnings
* refactor handleResponses

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
16 files changed:
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/handler/DaikinMadokaHandler.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/DaikinMadokaConfiguration.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/DisableCleanFilterIndicatorCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetCleanFilterIndicatorCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetEyeBrightnessCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetFanspeedCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetIndoorOutoorTemperatures.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetOperationHoursCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetOperationmodeCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetPowerstateCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetSetpointCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/GetVersionCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/main/java/org/openhab/binding/bluetooth/daikinmadoka/internal/model/commands/ResetCleanFilterTimerCommand.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/test/java/org/openhab/binding/bluetooth/daikinmadoka/handler/DummyThing.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/test/java/org/openhab/binding/bluetooth/daikinmadoka/internal/MadokaMessageTest.java
bundles/org.openhab.binding.bluetooth.daikinmadoka/src/test/java/org/openhab/binding/bluetooth/daikinmadoka/internal/UartProcessorTest.java

index 4afb58c6f71b9d8b3d0a3d106436346d9b864cb8..83db79b607bef7a202d6c2e964b7c54bd37bbac4 100644 (file)
@@ -24,7 +24,6 @@ import java.util.concurrent.TimeoutException;
 import javax.measure.quantity.Temperature;
 import javax.measure.quantity.Time;
 
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.BluetoothCharacteristic;
@@ -84,7 +83,7 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
 
     private final Logger logger = LoggerFactory.getLogger(DaikinMadokaHandler.class);
 
-    private @Nullable DaikinMadokaConfiguration config;
+    private DaikinMadokaConfiguration config = new DaikinMadokaConfiguration();
 
     private @Nullable ExecutorService commandExecutor;
 
@@ -109,10 +108,10 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
 
         // Load Configuration
         config = getConfigAs(DaikinMadokaConfiguration.class);
-        DaikinMadokaConfiguration c = config;
 
-        logger.debug("[{}] Parameter value [refreshInterval]: {}", super.thing.getUID().getId(), c.refreshInterval);
-        logger.debug("[{}] Parameter value [commandTimeout]: {}", super.thing.getUID().getId(), c.commandTimeout);
+        logger.debug("[{}] Parameter value [refreshInterval]: {}", super.thing.getUID().getId(),
+                config.refreshInterval);
+        logger.debug("[{}] Parameter value [commandTimeout]: {}", super.thing.getUID().getId(), config.commandTimeout);
 
         if (getBridge() == null) {
             logger.debug("[{}] Bridge is null. Exiting.", super.thing.getUID().getId());
@@ -144,9 +143,9 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
             }
 
             submitCommand(new GetEyeBrightnessCommand());
-        }, new Random().nextInt(30), c.refreshInterval, TimeUnit.SECONDS); // We introduce a random start time, it
-                                                                           // avoids when having multiple devices to
-                                                                           // have the commands sent simultaneously.
+        }, new Random().nextInt(30), config.refreshInterval, TimeUnit.SECONDS); // We introduce a random start time, it
+        // avoids when having multiple devices to
+        // have the commands sent simultaneously.
     }
 
     private void retrieveOperationHours() throws InterruptedException {
@@ -174,7 +173,6 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
                     .getCharacteristic(DaikinMadokaBindingConstants.CHAR_NOTIF_UUID);
 
             if (charNotif != null) {
-                @NonNull
                 BluetoothCharacteristic c = charNotif;
                 this.device.disableNotifications(c);
             }
@@ -443,8 +441,8 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
                 }
             }
 
-            if (command.getState() == BRC1HCommand.State.SENT && this.config != null) {
-                if (!command.awaitStateChange(this.config.commandTimeout, TimeUnit.MILLISECONDS,
+            if (command.getState() == BRC1HCommand.State.SENT) {
+                if (!command.awaitStateChange(config.commandTimeout, TimeUnit.MILLISECONDS,
                         BRC1HCommand.State.SUCCEEDED, BRC1HCommand.State.FAILED)) {
                     logger.debug("[{}] Command {} to device {} timed out", super.thing.getUID().getId(), command,
                             device.getAddress());
@@ -825,7 +823,7 @@ public class DaikinMadokaHandler extends ConnectedBluetoothHandler implements Re
         if (indicatorStatus != null) {
             this.madokaSettings.setCleanFilterIndicator(indicatorStatus);
             updateStateIfLinked(DaikinMadokaBindingConstants.CHANNEL_ID_CLEAN_FILTER_INDICATOR,
-                    indicatorStatus == true ? OnOffType.ON : OnOffType.OFF);
+                    OnOffType.from(indicatorStatus));
         }
     }
 
index 37e962989aca117e7cacb65d67cbde260bf1a896..141dccaa5bdb8950fed1014d2d98d4d123d22829 100644 (file)
  */
 package org.openhab.binding.bluetooth.daikinmadoka.internal;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
 /**
  * The {@link DaikinMadokaConfiguration} class contains fields mapping thing configuration parameters.
  *
  * @author Benjamin Lafois - Initial contribution
  */
+@NonNullByDefault
 public class DaikinMadokaConfiguration {
 
-    public String address;
-    public Integer refreshInterval;
-    public Integer commandTimeout;
+    public String address = "";
+    public int refreshInterval;
+    public int commandTimeout;
 }
index f4536e733e307abd25226c43289f300b0e1ebeb5..42da102962f455dadb82da743dcc3cba1a359250 100644 (file)
@@ -18,8 +18,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Command used to disable the Clean Filter Indicator notification
@@ -30,8 +28,6 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class DisableCleanFilterIndicatorCommand extends BRC1HCommand {
 
-    private final Logger logger = LoggerFactory.getLogger(DisableCleanFilterIndicatorCommand.class);
-
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
index 393a0d85f3212fc986bea467d0ceb5a3e9f6fe22..66f70073716d3181ebfeffc82a0b8d091c791409 100644 (file)
@@ -18,8 +18,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 
 /**
  * Command used to get the Clean Filter Indicator status
@@ -30,15 +29,19 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class GetCleanFilterIndicatorCommand extends BRC1HCommand {
 
-    private final Logger logger = LoggerFactory.getLogger(GetCleanFilterIndicatorCommand.class);
-
     private @Nullable Boolean cleanFilterIndicator;
 
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
+        MadokaValue mValue = mm.getValues().get(0x62);
+        if (mValue == null) {
+            String message = "clean filter indicator is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
-        byte[] valueCleanFilterIndicator = mm.getValues().get(0x62).getRawValue();
+        byte[] valueCleanFilterIndicator = mValue.getRawValue();
         if (valueCleanFilterIndicator == null || valueCleanFilterIndicator.length != 1) {
             setState(State.FAILED);
             throw new MadokaParsingException("Incorrect clean filter indicator value");
@@ -51,7 +54,12 @@ public class GetCleanFilterIndicatorCommand extends BRC1HCommand {
         }
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     public @Nullable Boolean getCleanFilterIndicator() {
index a5f342f4682832655ca719b18f62a53448a5bfc0..1c8937824aba39fa4b1da697719d5fc60bfdb0ba 100644 (file)
@@ -39,24 +39,32 @@ public class GetEyeBrightnessCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        byte[] bEyeBrightness = mm.getValues().get(0x33).getRawValue();
+        MadokaValue mValue = mm.getValues().get(0x33);
+        if (mValue == null) {
+            String message = "eye brightness is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
-        if (bEyeBrightness == null || bEyeBrightness == null) {
+        byte[] bEyeBrightness = mValue.getRawValue();
+        if (bEyeBrightness == null) {
             setState(State.FAILED);
             throw new MadokaParsingException("Incorrect eye brightness value");
         }
 
         Integer iEyeBrightness = Integer.valueOf(bEyeBrightness[0]);
-
-        if (iEyeBrightness != null) {
-            // The values accepted by the device are from 0 to 19 - integers so conversion needed for Dimmer channel
-            eyeBrightness = new PercentType((int) Math.round(iEyeBrightness / 0.19));
-        }
+        // The values accepted by the device are from 0 to 19 - integers so conversion needed for Dimmer channel
+        eyeBrightness = new PercentType((int) Math.round(iEyeBrightness / 0.19));
 
         logger.debug("Eye Brightness: {}", eyeBrightness);
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     @Override
index e296049fea8d1f302861c717d2e797ca4e5cf75c..77ae2a88655c9406b7084af6980348da581ba173 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.FanSpeed;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,9 +45,16 @@ public class GetFanspeedCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
+        MadokaValue coolValue = mm.getValues().get(0x20);
+        MadokaValue heatValue = mm.getValues().get(0x21);
+        if (heatValue == null || coolValue == null) {
+            String message = "heating or cooling fan speed is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
-        byte[] valueCoolingFanSpeed = mm.getValues().get(0x20).getRawValue();
-        byte[] valueHeatingFanSpeed = mm.getValues().get(0x21).getRawValue();
+        byte[] valueCoolingFanSpeed = coolValue.getRawValue();
+        byte[] valueHeatingFanSpeed = heatValue.getRawValue();
 
         if (valueCoolingFanSpeed == null || valueHeatingFanSpeed == null) {
             setState(State.FAILED);
@@ -60,7 +68,13 @@ public class GetFanspeedCommand extends BRC1HCommand {
         logger.debug("heatingFanSpeed: {}", heatingFanSpeed);
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     @Override
index 89f6c98f47136949aebcd33e50e360d4c1b58f0c..27c70eab2cb7785e0497f2391068d3505f250ab2 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.SIUnits;
 import org.slf4j.Logger;
@@ -47,9 +48,16 @@ public class GetIndoorOutoorTemperatures extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        byte[] bIndoorTemperature = mm.getValues().get(0x40).getRawValue();
-        byte[] bOutdoorTemperature = mm.getValues().get(0x41).getRawValue();
+        MadokaValue indoorValue = mm.getValues().get(0x40);
+        MadokaValue outdoorValue = mm.getValues().get(0x41);
+        if (outdoorValue == null || indoorValue == null) {
+            String message = "indoor or outdoor value is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
+        byte[] bIndoorTemperature = indoorValue.getRawValue();
+        byte[] bOutdoorTemperature = outdoorValue.getRawValue();
         if (bIndoorTemperature == null || bOutdoorTemperature == null) {
             setState(State.FAILED);
             throw new MadokaParsingException("Incorrect indoor or outdoor temperature");
@@ -66,9 +74,7 @@ public class GetIndoorOutoorTemperatures extends BRC1HCommand {
             }
         }
 
-        if (iIndoorTemperature != null) {
-            indoorTemperature = new QuantityType<Temperature>(iIndoorTemperature, SIUnits.CELSIUS);
-        }
+        indoorTemperature = new QuantityType<Temperature>(iIndoorTemperature, SIUnits.CELSIUS);
 
         if (iOutdoorTemperature != null) {
             outdoorTemperature = new QuantityType<Temperature>(iOutdoorTemperature, SIUnits.CELSIUS);
@@ -78,7 +84,13 @@ public class GetIndoorOutoorTemperatures extends BRC1HCommand {
         logger.debug("Outdoor Temp: {}", outdoorTemperature);
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     public @Nullable QuantityType<Temperature> getIndoorTemperature() {
index 12c3420a8ee279162cce8d5ab97462944531ca7c..bb54520095b8a3698ddb26c6c1f7451710f54ec0 100644 (file)
@@ -24,7 +24,6 @@ import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingEx
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.Units;
-import org.openhab.core.util.HexUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,33 +61,34 @@ public class GetOperationHoursCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        try {
-
-            byte[] msg = mm.getRawMessage();
-            if (logger.isDebugEnabled() && msg != null) {
-                logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
-            }
+        MadokaValue opHours = mm.getValues().get(0x40);
+        MadokaValue fanHours = mm.getValues().get(0x41);
+        MadokaValue powerHours = mm.getValues().get(0x42);
+        if (opHours == null || fanHours == null || powerHours == null) {
+            String message = "indoorOperationHours, indoorFanHours or indoorPowerHours is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
-            // The specific GetOperationHours requires 2 consecutive runs for some reason.
-            // If value size is 0, then it will be for the next query!
-            if (mm.getValues().get(0x40).getSize() == 0) {
-                setState(State.SUCCEEDED);
-                return;
-            }
+        if (opHours.getSize() == 0) {
+            setState(State.SUCCEEDED);
+            return;
+        }
 
-            Integer iIndoorOperationHours = (int) (mm.getValues().get(0x40).getComputedValue(ByteOrder.LITTLE_ENDIAN));
-            Integer iIndoorFanHours = (int) (mm.getValues().get(0x41).getComputedValue(ByteOrder.LITTLE_ENDIAN));
-            Integer iIndoorPowerHours = (int) (mm.getValues().get(0x42).getComputedValue(ByteOrder.LITTLE_ENDIAN));
+        Integer iIndoorOperationHours = (int) (opHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
+        Integer iIndoorFanHours = (int) (fanHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
+        Integer iIndoorPowerHours = (int) (powerHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
 
-            this.indoorOperationHours = new QuantityType<Time>(iIndoorOperationHours, Units.HOUR);
-            this.indoorFanHours = new QuantityType<Time>(iIndoorFanHours, Units.HOUR);
-            this.indoorPowerHours = new QuantityType<Time>(iIndoorPowerHours, Units.HOUR);
+        this.indoorOperationHours = new QuantityType<Time>(iIndoorOperationHours, Units.HOUR);
+        this.indoorFanHours = new QuantityType<Time>(iIndoorFanHours, Units.HOUR);
+        this.indoorPowerHours = new QuantityType<Time>(iIndoorPowerHours, Units.HOUR);
 
-            logger.debug("indoorOperationHours: {}", indoorOperationHours);
-            logger.debug("indoorFanHours: {}", indoorFanHours);
-            logger.debug("indoorPowerHours: {}", indoorPowerHours);
+        logger.debug("indoorOperationHours: {}", indoorOperationHours);
+        logger.debug("indoorFanHours: {}", indoorFanHours);
+        logger.debug("indoorPowerHours: {}", indoorPowerHours);
 
-            setState(State.SUCCEEDED);
+        setState(State.SUCCEEDED);
+        try {
             executor.execute(() -> listener.receivedResponse(this));
         } catch (Exception e) {
             setState(State.FAILED);
index 0115bc521837ddcd8489dc5aed36831568bccd32..64440b1953e2aabea45529df6803132d00824dfe 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.OperationMode;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +44,13 @@ public class GetOperationmodeCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        byte[] bOperationMode = mm.getValues().get(0x20).getRawValue();
+        @Nullable
+        MadokaValue mode = mm.getValues().get(0x20);
+        if (mode == null) {
+            setState(State.FAILED);
+            throw new MadokaParsingException("Incorrect operation mode");
+        }
+        byte[] bOperationMode = mode.getRawValue();
         if (bOperationMode == null) {
             setState(State.FAILED);
             throw new MadokaParsingException("Incorrect operation mode");
@@ -54,7 +61,12 @@ public class GetOperationmodeCommand extends BRC1HCommand {
         logger.debug("operationMode: {}", operationMode);
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     @Override
index b1238f140497e78bfbb1fe18abdc7af56d8eaa9a..eb8620def73342ad82c18e06bc05627177bec738 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,8 +43,14 @@ public class GetPowerstateCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        byte[] powerStateValue = mm.getValues().get(0x20).getRawValue();
+        MadokaValue mValue = mm.getValues().get(0x20);
+        if (mValue == null) {
+            String message = "powerstate is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
+        byte[] powerStateValue = mValue.getRawValue();
         if (powerStateValue == null || powerStateValue.length != 1) {
             setState(State.FAILED);
             throw new MadokaParsingException("Incorrect value for PowerState");
@@ -54,7 +61,12 @@ public class GetPowerstateCommand extends BRC1HCommand {
         logger.debug("PowerState: {}", powerState);
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     @Override
index 39686536dc8e6a31916bbe79a2bc01e763ab68bc..36b1ca9b78c00d6d522ef03fbe9521b734727e40 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.SIUnits;
 import org.slf4j.Logger;
@@ -47,17 +48,25 @@ public class GetSetpointCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        try {
-            Integer iHeatingSetpoint = (int) (mm.getValues().get(0x21).getComputedValue() / 128.);
-            Integer iCoolingSetpoint = (int) (mm.getValues().get(0x20).getComputedValue() / 128.);
+        MadokaValue heatValue = mm.getValues().get(0x21);
+        MadokaValue coolValue = mm.getValues().get(0x20);
+        if (heatValue == null || coolValue == null) {
+            String message = "heatingSetpoint or coolingSetpoint is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
 
-            this.heatingSetpoint = new QuantityType<Temperature>(iHeatingSetpoint, SIUnits.CELSIUS);
-            this.coolingSetpoint = new QuantityType<Temperature>(iCoolingSetpoint, SIUnits.CELSIUS);
+        Integer iHeatingSetpoint = (int) (heatValue.getComputedValue() / 128.);
+        Integer iCoolingSetpoint = (int) (coolValue.getComputedValue() / 128.);
 
-            logger.debug("heatingSetpoint: {}", heatingSetpoint);
-            logger.debug("coolingSetpoint: {}", coolingSetpoint);
+        this.heatingSetpoint = new QuantityType<Temperature>(iHeatingSetpoint, SIUnits.CELSIUS);
+        this.coolingSetpoint = new QuantityType<Temperature>(iCoolingSetpoint, SIUnits.CELSIUS);
 
-            setState(State.SUCCEEDED);
+        logger.debug("heatingSetpoint: {}", heatingSetpoint);
+        logger.debug("coolingSetpoint: {}", coolingSetpoint);
+
+        setState(State.SUCCEEDED);
+        try {
             executor.execute(() -> listener.receivedResponse(this));
         } catch (Exception e) {
             setState(State.FAILED);
index f9d365162cbf2c4d8ae537c8fda1d94ad46eec37..efb3287fd4cc1df05005c59fa648d69e2948e1d4 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
+import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
 
 /**
  * This command returns the firmware version
@@ -39,10 +40,16 @@ public class GetVersionCommand extends BRC1HCommand {
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
-        // In this method, we intentionally do not check for null values in mv45 and mv46. In case of null pointer
-        // access, it will be catched by the global exception and be reported as a Parsing Reponse exception.
-        byte[] mv45 = mm.getValues().get(0x45).getRawValue();
-        byte[] mv46 = mm.getValues().get(0x46).getRawValue();
+        MadokaValue mValue45 = mm.getValues().get(0x45);
+        MadokaValue mValue46 = mm.getValues().get(0x46);
+        if (mValue45 == null || mValue46 == null) {
+            String message = "version value is null when handling the response";
+            setState(State.FAILED);
+            throw new MadokaParsingException(message);
+        }
+
+        byte[] mv45 = mValue45.getRawValue();
+        byte[] mv46 = mValue46.getRawValue();
 
         if (mv45 == null || mv45.length != 3 || mv46 == null || mv46.length != 2) {
             setState(State.FAILED);
@@ -60,7 +67,12 @@ public class GetVersionCommand extends BRC1HCommand {
         this.communicationControllerVersion = commControllerMajor + "." + commControllerMinor;
 
         setState(State.SUCCEEDED);
-        executor.execute(() -> listener.receivedResponse(this));
+        try {
+            executor.execute(() -> listener.receivedResponse(this));
+        } catch (Exception e) {
+            setState(State.FAILED);
+            throw new MadokaParsingException(e);
+        }
     }
 
     @Override
index 41fb2842e998835b14756e3eec38c298ceb0b583..567da7b3a974cf7e98f22a62bffe43f43c0a6b5c 100644 (file)
@@ -18,8 +18,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Command used to reset the Clean Filter Indicator timer
@@ -30,8 +28,6 @@ import org.slf4j.LoggerFactory;
 @NonNullByDefault
 public class ResetCleanFilterTimerCommand extends BRC1HCommand {
 
-    private final Logger logger = LoggerFactory.getLogger(ResetCleanFilterTimerCommand.class);
-
     @Override
     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
             throws MadokaParsingException {
index f823bba657422e1bb12e5e2182dfaefe5283c102..128f7bc76ce4efbb6eb8f05f206bc5953537191a 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.*;
 
 import java.nio.ByteOrder;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
@@ -26,9 +27,10 @@ import org.openhab.core.library.types.OnOffType;
 
 /**
  *
- * @author blafois
+ * @author blafois - Initial contribution
  *
  */
+@NonNullByDefault
 public class MadokaMessageTest {
 
     @Test
@@ -42,8 +44,7 @@ public class MadokaMessageTest {
         boolean powered = true;
         MadokaValue mv = new MadokaValue(0x20, 1, new byte[] { 1 });
         byte[][] resp = MadokaMessage.createRequest(new SetPowerstateCommand(OnOffType.ON), mv);
-        assertArrayEquals(
-                new byte[] { 0x00, 0x07, 0x00, 0x40, 0x20, 0x20, 0x01, (byte) (powered == true ? 0x01 : 0x00) },
+        assertArrayEquals(new byte[] { 0x00, 0x07, 0x00, 0x40, 0x20, 0x20, 0x01, (byte) (powered ? 0x01 : 0x00) },
                 resp[0]);
     }
 
index f51bcb742b934a8fecb1db007f313ed75a4d2f30..d833f78aaf780250a55dec06298e50923c9f113f 100644 (file)
@@ -14,7 +14,7 @@ package org.openhab.binding.bluetooth.daikinmadoka.internal;
 
 import static org.junit.jupiter.api.Assertions.*;
 
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.GetCleanFilterIndicatorCommand;
 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.GetEyeBrightnessCommand;
@@ -34,9 +34,10 @@ import org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetSet
 
 /**
  *
- * @author blafois
+ * @author blafois - Initial contribution
  *
  */
+@NonNullByDefault
 public class UartProcessorTest implements ResponseListener {
 
     private boolean completed = false;
@@ -70,63 +71,63 @@ public class UartProcessorTest implements ResponseListener {
     }
 
     @Override
-    public void receivedResponse(byte @NonNull [] bytes) {
+    public void receivedResponse(byte[] bytes) {
         this.completed = true;
     }
 
     @Override
-    public void receivedResponse(@NonNull GetVersionCommand command) {
+    public void receivedResponse(GetVersionCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetFanspeedCommand command) {
+    public void receivedResponse(GetFanspeedCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetOperationmodeCommand command) {
+    public void receivedResponse(GetOperationmodeCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetPowerstateCommand command) {
+    public void receivedResponse(GetPowerstateCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetSetpointCommand command) {
+    public void receivedResponse(GetSetpointCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetIndoorOutoorTemperatures command) {
+    public void receivedResponse(GetIndoorOutoorTemperatures command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull SetPowerstateCommand command) {
+    public void receivedResponse(SetPowerstateCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull SetSetpointCommand command) {
+    public void receivedResponse(SetSetpointCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull SetOperationmodeCommand command) {
+    public void receivedResponse(SetOperationmodeCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull SetFanspeedCommand command) {
+    public void receivedResponse(SetFanspeedCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetOperationHoursCommand command) {
+    public void receivedResponse(GetOperationHoursCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetEyeBrightnessCommand command) {
+    public void receivedResponse(GetEyeBrightnessCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull GetCleanFilterIndicatorCommand command) {
+    public void receivedResponse(GetCleanFilterIndicatorCommand command) {
     }
 
     @Override
-    public void receivedResponse(@NonNull SetEyeBrightnessCommand command) {
+    public void receivedResponse(SetEyeBrightnessCommand command) {
     }
 }