mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[digitalstrom] Adoptions due to API changes in DSS Update 1.19.2 (#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>
This commit is contained in:
parent
ae50e32364
commit
1ee5906fc7
@ -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}.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user