]> git.basschouten.com Git - openhab-addons.git/commitdiff
[digitalstrom] Adoptions due to API changes in DSS Update 1.19.2 (#12033)
authoralexf2015 <alexf2015@users.noreply.github.com>
Fri, 14 Jan 2022 07:38:20 +0000 (08:38 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Jan 2022 07:38:20 +0000 (08:38 +0100)
* added support for DSUID in DSS response data while being compatible to removed DSID which might still be in use due to older firmware versions.
* fixed a NPE and also fixed json parameter naming.
* applied improvements from DSUID class
* fixed variable name, made dsid member final, added author

Signed-off-by: Alexander Friese <af944580@googlemail.com>
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/StructureManager.java
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/DeviceStatusManagerImpl.java
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/manager/impl/StructureManagerImpl.java
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/CachedMeteringValue.java
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSID.java
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java [new file with mode: 0644]
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/JSONCachedMeteringValueImpl.java

index cb469f52639fd7ced2b0e1f4aa6facb61f0a2c9a..1408621467d37912345a76967a0e2899eb0bf79e 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Circuit;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
+import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSUID;
 
 /**
  * The {@link StructureManager} builds the internal model of the digitalSTROM-System.
@@ -226,6 +227,14 @@ public interface StructureManager {
      */
     Circuit getCircuitByDSID(String dSID);
 
+    /**
+     * Returns the {@link Circuit} with the given dSUID as {@link DSUID}.
+     *
+     * @param dSUID of the {@link Circuit} to get
+     * @return the {@link Circuit} with the given {@link DSUID}
+     */
+    Circuit getCircuitByDSUID(DSUID dSUID);
+
     /**
      * Returns the {@link Circuit} with the given dSUID as {@link String}.
      *
index 3048dd56bb7e19adad20a2613a30a313db9dda36..d9b64c9fa72f1df1d99bff0dc7629914a2330a06 100644 (file)
@@ -1189,6 +1189,8 @@ public class DeviceStatusManagerImpl implements DeviceStatusManager {
                 tempConsumption += value.getValue();
                 if (strucMan.getCircuitByDSID(value.getDsid()) != null) {
                     strucMan.getCircuitByDSID(value.getDsid()).addMeteringValue(value);
+                } else if (strucMan.getCircuitByDSUID(value.getDsuid()) != null) {
+                    strucMan.getCircuitByDSUID(value.getDsuid()).addMeteringValue(value);
                 }
             }
         }
@@ -1216,6 +1218,8 @@ public class DeviceStatusManagerImpl implements DeviceStatusManager {
                 tempEnergyMeter += value.getValue();
                 if (strucMan.getCircuitByDSID(value.getDsid()) != null) {
                     strucMan.getCircuitByDSID(value.getDsid()).addMeteringValue(value);
+                } else if (strucMan.getCircuitByDSUID(value.getDsuid()) != null) {
+                    strucMan.getCircuitByDSUID(value.getDsuid()).addMeteringValue(value);
                 }
             }
         }
@@ -1232,6 +1236,8 @@ public class DeviceStatusManagerImpl implements DeviceStatusManager {
                 tempEnergyMeterWs += value.getValue();
                 if (strucMan.getCircuitByDSID(value.getDsid()) != null) {
                     strucMan.getCircuitByDSID(value.getDsid()).addMeteringValue(value);
+                } else if (strucMan.getCircuitByDSUID(value.getDsuid()) != null) {
+                    strucMan.getCircuitByDSUID(value.getDsuid()).addMeteringValue(value);
                 }
             }
         }
index efa23b75fbb3c99241d3e7f3d90e5e2055a7c4c1..d7ecd12f5fec70c743be3fb2c85e99f89fee12ad 100644 (file)
@@ -27,6 +27,7 @@ import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Circuit;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.CachedMeteringValue;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
+import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSUID;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
@@ -388,6 +389,11 @@ public class StructureManagerImpl implements StructureManager {
         return tmp != null ? getCircuitByDSID(tmp) : null;
     }
 
+    @Override
+    public Circuit getCircuitByDSUID(DSUID dSUID) {
+        return dSUID != null ? getCircuitByDSUID(dSUID.getValue()) : null;
+    }
+
     @Override
     public Circuit getCircuitByDSID(String dSID) {
         return getCircuitByDSID(new DSID(dSID));
index a31d6ad8d429311727f4b9a82117ca055c6eae0a..15b406a22b67abb91fb457e57ce28ebba5e8cd2c 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Date;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringUnitsEnum;
 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
+import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSUID;
 
 /**
  * The {@link CachedMeteringValue} saves the metering value of an digitalSTROM-Circuit.
@@ -32,8 +33,16 @@ public interface CachedMeteringValue {
      *
      * @return dSID of circuit
      */
+    @Deprecated(since = "value removed in API since dss v1.19.2")
     DSID getDsid();
 
+    /**
+     * Returns the {@link DSUID} of the digitalSTROM-Circuit.
+     *
+     * @return dSUID of circuit
+     */
+    DSUID getDsuid();
+
     /**
      * Returns the saved sensor value.
      *
index 119dfa51a547ea158efb8d5ba7f097d1a555baba..5b3b186a933d067b702901c62b97db208d3123e0 100644 (file)
@@ -15,13 +15,15 @@ package org.openhab.binding.digitalstrom.internal.lib.structure.devices.devicepa
 /**
  * The {@link DSID} represents the digitalSTROM-Device identifier.
  *
- * @author Alexander Betker - initial contributer
+ * @author Alexander Betker - initial contributor
+ * @author Alexander Friese - simplified constructor
  */
 public class DSID {
 
-    private String dsid;
+    private final String dsid;
     private final String DEFAULT_DSID = "3504175fe000000000000001";
     private final String PRE = "3504175fe0000000";
+    private final String ALL = "ALL";
 
     /**
      * Creates a new {@link DSID}.
@@ -29,17 +31,13 @@ public class DSID {
      * @param dsid to create
      */
     public DSID(String dsid) {
-        this.dsid = dsid;
-        if (dsid != null && !dsid.trim().equals("")) {
-            if (dsid.trim().length() == 24) {
-                this.dsid = dsid;
-            } else if (dsid.trim().length() == 8) {
-                this.dsid = this.PRE + dsid;
-            } else if (dsid.trim().toUpperCase().equals("ALL")) {
-                this.dsid = "ALL";
-            } else {
-                this.dsid = DEFAULT_DSID;
-            }
+        var trimmedDsid = dsid != null ? dsid.trim() : "";
+        if (trimmedDsid.length() == 24) {
+            this.dsid = trimmedDsid;
+        } else if (trimmedDsid.length() == 8) {
+            this.dsid = this.PRE + trimmedDsid;
+        } else if (trimmedDsid.toUpperCase().equals(ALL)) {
+            this.dsid = ALL;
         } else {
             this.dsid = DEFAULT_DSID;
         }
diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/lib/structure/devices/deviceparameters/impl/DSUID.java
new file mode 100644 (file)
index 0000000..272ef18
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2010-2022 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl;
+
+/**
+ * The {@link DSUID} represents the digitalSTROM-Device unique identifier.
+ *
+ * @author Alexander Friese - initial contributor
+ */
+public class DSUID {
+
+    private final String dsuid;
+    private final String DEFAULT_DSUID = "3504175fe0000000000000000000000001";
+
+    /**
+     * Creates a new {@link DSUID}.
+     *
+     * @param dsuid to create
+     */
+    public DSUID(String dsuid) {
+        var trimmedDsuid = dsuid != null ? dsuid.trim() : "";
+        if (trimmedDsuid.length() == 34) {
+            this.dsuid = trimmedDsuid;
+        } else {
+            this.dsuid = DEFAULT_DSUID;
+        }
+    }
+
+    /**
+     * Returns the dSUID as {@link String}.
+     *
+     * @return dsuid
+     */
+    public String getValue() {
+        return dsuid;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof DSUID) {
+            return ((DSUID) obj).getValue().equals(this.getValue());
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return dsuid.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return dsuid;
+    }
+}
index c1f6b6ccb001c535f23da4cebaeb0af5876204d3..8c2b8a55de9177de27211653d9dc1d28a51b744b 100644 (file)
@@ -36,6 +36,7 @@ import com.google.gson.JsonObject;
 public class JSONCachedMeteringValueImpl implements CachedMeteringValue {
 
     private DSID dsid;
+    private DSUID dsuid;
     private double value = 0;
     private String date;
     private final MeteringTypeEnum meteringType;
@@ -60,6 +61,9 @@ public class JSONCachedMeteringValueImpl implements CachedMeteringValue {
         if (jObject.get(JSONApiResponseKeysEnum.DSID_LOWER_CASE.getKey()) != null) {
             this.dsid = new DSID(jObject.get(JSONApiResponseKeysEnum.DSID_LOWER_CASE.getKey()).getAsString());
         }
+        if (jObject.get(JSONApiResponseKeysEnum.DSUID.getKey()) != null) {
+            this.dsuid = new DSUID(jObject.get(JSONApiResponseKeysEnum.DSUID.getKey()).getAsString());
+        }
         if (jObject.get(JSONApiResponseKeysEnum.VALUE.getKey()) != null) {
             this.value = jObject.get(JSONApiResponseKeysEnum.VALUE.getKey()).getAsDouble();
         }
@@ -69,6 +73,12 @@ public class JSONCachedMeteringValueImpl implements CachedMeteringValue {
     }
 
     @Override
+    public DSUID getDsuid() {
+        return dsuid;
+    }
+
+    @Override
+    @Deprecated(since = "value removed in API since dss v1.19.2")
     public DSID getDsid() {
         return dsid;
     }
@@ -106,7 +116,7 @@ public class JSONCachedMeteringValueImpl implements CachedMeteringValue {
 
     @Override
     public String toString() {
-        return "dSID: " + this.getDsid() + ", metering-type " + meteringType.toString() + ", metering-unit "
-                + meteringUnit + ", date: " + this.getDate() + ", value: " + this.getValue();
+        return "dSUID: " + this.getDsuid() + ", dSID: " + this.getDsid() + ", metering-type " + meteringType.toString()
+                + ", metering-unit " + meteringUnit + ", date: " + this.getDate() + ", value: " + this.getValue();
     }
 }