* 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>
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.
*/
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}.
*
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);
}
}
}
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);
}
}
}
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);
}
}
}
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;
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));
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.
*
* @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.
*
/**
* 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}.
* @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;
}
--- /dev/null
+/**
+ * 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;
+ }
+}
public class JSONCachedMeteringValueImpl implements CachedMeteringValue {
private DSID dsid;
+ private DSUID dsuid;
private double value = 0;
private String date;
private final MeteringTypeEnum meteringType;
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();
}
}
@Override
+ public DSUID getDsuid() {
+ return dsuid;
+ }
+
+ @Override
+ @Deprecated(since = "value removed in API since dss v1.19.2")
public DSID getDsid() {
return dsid;
}
@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();
}
}