Skip to content

Commit

Permalink
[digitalstrom] Adoptions due to API changes in DSS Update 1.19.2 (ope…
Browse files Browse the repository at this point in the history
…nhab#12033)

* 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>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
  • Loading branch information
alexf2015 authored and andrasU committed Nov 12, 2022
1 parent c0e0bc3 commit e367961
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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.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.
Expand Down Expand Up @@ -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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,8 @@ public int getTotalPowerConsumption() {
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);
}
}
}
Expand Down Expand Up @@ -1216,6 +1218,8 @@ public int getTotalEnergyMeterValue() {
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);
}
}
}
Expand All @@ -1232,6 +1236,8 @@ public int getTotalEnergyMeterWsValue() {
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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -388,6 +389,11 @@ public Circuit getCircuitByDSUID(String dSUID) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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.
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@
/**
* 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class JSONCachedMeteringValueImpl implements CachedMeteringValue {

private DSID dsid;
private DSUID dsuid;
private double value = 0;
private String date;
private final MeteringTypeEnum meteringType;
Expand All @@ -60,6 +61,9 @@ public JSONCachedMeteringValueImpl(JsonObject jObject, MeteringTypeEnum metering
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();
}
Expand All @@ -69,6 +73,12 @@ public JSONCachedMeteringValueImpl(JsonObject jObject, MeteringTypeEnum metering
}

@Override
public DSUID getDsuid() {
return dsuid;
}

@Override
@Deprecated(since = "value removed in API since dss v1.19.2")
public DSID getDsid() {
return dsid;
}
Expand Down Expand Up @@ -106,7 +116,7 @@ public MeteringUnitsEnum getMeteringUnit() {

@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();
}
}

0 comments on commit e367961

Please sign in to comment.