use of org.json.simple.JsonObject in project openhab1-addons by openhab.
the class DigitalSTROMJSONImpl method getMeterList.
@Override
public List<String> getMeterList(String token) {
List<String> meterList = new LinkedList<String>();
String response = transport.execute(JSONRequestConstants.JSON_PROPERTY_QUERY + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_QUERY + JSONRequestConstants.QUERY_GET_METERLIST);
JSONObject responseObj = handler.toJSONObject(response);
if (handler.checkResponse(responseObj)) {
JSONObject obj = handler.getResultJSONObject(responseObj);
if (obj != null && obj.get(JSONApiResponseKeysEnum.DS_METER_QUERY.getKey()) instanceof JSONArray) {
JSONArray array = (JSONArray) obj.get(JSONApiResponseKeysEnum.DS_METER_QUERY.getKey());
for (int i = 0; i < array.size(); i++) {
if (array.get(i) instanceof JSONObject) {
JSONObject elem = (JSONObject) array.get(i);
@SuppressWarnings("unchecked") Collection<String> k = elem.values();
for (String s : k) {
meterList.add(s);
}
}
}
}
}
return meterList;
}
use of org.json.simple.JsonObject in project openhab1-addons by openhab.
the class DigitalSTROMJSONImpl method getResolutions.
@Override
public List<Integer> getResolutions(String token) {
String response = null;
response = transport.execute(JSONRequestConstants.JSON_METERING_GET_RESOLUTIONS + JSONRequestConstants.PARAMETER_TOKEN + token);
JSONObject responseObj = handler.toJSONObject(response);
if (handler.checkResponse(responseObj)) {
JSONObject resObj = handler.getResultJSONObject(responseObj);
if (resObj != null && resObj.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTIONS.getKey()) instanceof JSONArray) {
JSONArray array = (JSONArray) resObj.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTIONS.getKey());
List<Integer> resolutionList = new LinkedList<Integer>();
for (int i = 0; i < array.size(); i++) {
if (array.get(i) instanceof org.json.simple.JSONObject) {
JSONObject jObject = (JSONObject) array.get(i);
if (jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()) != null) {
int val = -1;
try {
val = Integer.parseInt(jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()).toString());
} catch (java.lang.NumberFormatException e) {
logger.error("NumberFormatException in getResolutions: " + jObject.get(JSONApiResponseKeysEnum.METERING_GET_RESOLUTION.getKey()).toString());
}
if (val != -1) {
resolutionList.add(val);
}
}
}
}
return resolutionList;
}
}
return null;
}
use of org.json.simple.JsonObject in project openhab1-addons by openhab.
the class DigitalSTROMJSONImpl method loginApplication.
@Override
public String loginApplication(String loginToken) {
if (loginToken != null && !loginToken.trim().equals("")) {
String response = null;
response = transport.execute(JSONRequestConstants.JSON_SYSTEM_LOGIN_APPLICATION + loginToken);
JSONObject responseObj = handler.toJSONObject(response);
if (handler.checkResponse(responseObj)) {
JSONObject obj = handler.getResultJSONObject(responseObj);
String tokenStr = null;
if (obj != null && obj.get(JSONApiResponseKeysEnum.SYSTEM_LOGIN.getKey()) != null) {
tokenStr = obj.get(JSONApiResponseKeysEnum.SYSTEM_LOGIN.getKey()).toString();
}
if (tokenStr != null) {
return tokenStr;
}
}
}
return null;
}
use of org.json.simple.JsonObject in project openhab1-addons by openhab.
the class DigitalSTROMJSONImpl method getLatest.
@Override
public List<CachedMeteringValue> getLatest(String token, MeteringTypeEnum type, String from, MeteringUnitsEnum unit) {
if (type != null && from != null) {
String response = null;
if (unit != null && type != MeteringTypeEnum.consumption) {
response = transport.execute(JSONRequestConstants.JSON_METERING_GET_LATEST + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_TYPE + type.name() + JSONRequestConstants.INFIX_PARAMETER_FROM + from + JSONRequestConstants.INFIX_PARAMETER_UNIT + unit.name());
} else {
response = transport.execute(JSONRequestConstants.JSON_METERING_GET_LATEST + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_TYPE + type.name() + JSONRequestConstants.INFIX_PARAMETER_FROM + from);
}
JSONObject responseObj = handler.toJSONObject(response);
if (handler.checkResponse(responseObj)) {
JSONObject latestObj = handler.getResultJSONObject(responseObj);
if (latestObj != null && latestObj.get(JSONApiResponseKeysEnum.METERING_GET_LATEST.getKey()) instanceof JSONArray) {
JSONArray array = (JSONArray) latestObj.get(JSONApiResponseKeysEnum.METERING_GET_LATEST.getKey());
List<CachedMeteringValue> list = new LinkedList<CachedMeteringValue>();
for (int i = 0; i < array.size(); i++) {
if (array.get(i) instanceof JSONObject) {
list.add(new JSONCachedMeteringValueImpl((JSONObject) array.get(i)));
}
}
return list;
}
}
}
return null;
}
use of org.json.simple.JsonObject in project openhab1-addons by openhab.
the class DigitalSTROMJSONImpl method getTime.
@Override
public int getTime(String token) {
String response = null;
response = transport.execute(JSONRequestConstants.JSON_SYSTEM_TIME + JSONRequestConstants.PARAMETER_TOKEN + token);
JSONObject responseObj = handler.toJSONObject(response);
if (handler.checkResponse(responseObj)) {
JSONObject obj = handler.getResultJSONObject(responseObj);
if (obj != null && obj.get(JSONApiResponseKeysEnum.SYSTEM_GET_TIME.getKey()) != null) {
int time = -1;
try {
time = Integer.parseInt(obj.get(JSONApiResponseKeysEnum.SYSTEM_GET_TIME.getKey()).toString());
} catch (java.lang.NumberFormatException e) {
logger.error("NumberFormatException by getTime: " + obj.get(JSONApiResponseKeysEnum.SYSTEM_GET_TIME.getKey()).toString());
}
return time;
}
}
return -1;
}
Aggregations