Search in sources :

Example 1 with CircuitImpl

use of org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.CircuitImpl in project smarthome by eclipse.

the class DsAPIImpl method getApartmentCircuits.

@Override
public List<Circuit> getApartmentCircuits(String sessionToken) {
    String response = transport.execute(SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.APARTMENT).addFunction(FunctionKeys.GET_CIRCUITS).addParameter(ParameterKeys.TOKEN, sessionToken).buildRequestString());
    JsonObject responseObj = JSONResponseHandler.toJsonObject(response);
    if (JSONResponseHandler.checkResponse(responseObj)) {
        responseObj = JSONResponseHandler.getResultJsonObject(responseObj);
        if (responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).isJsonArray()) {
            JsonArray array = responseObj.get(JSONApiResponseKeysEnum.CIRCUITS.getKey()).getAsJsonArray();
            List<Circuit> circuitList = new LinkedList<Circuit>();
            for (int i = 0; i < array.size(); i++) {
                if (array.get(i).isJsonObject()) {
                    circuitList.add(new CircuitImpl(array.get(i).getAsJsonObject()));
                }
            }
            return circuitList;
        }
    }
    return new LinkedList<Circuit>();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit) CircuitImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.CircuitImpl) LinkedList(java.util.LinkedList)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 LinkedList (java.util.LinkedList)1 Circuit (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)1 CircuitImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.CircuitImpl)1