Search in sources :

Example 1 with DeviceImpl

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

the class DsAPIImpl method getApartmentDevices.

@Override
public List<Device> getApartmentDevices(String token) {
    String response = transport.execute(SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.APARTMENT).addFunction(FunctionKeys.GET_DEVICES).addParameter(ParameterKeys.TOKEN, token).buildRequestString());
    JsonObject responseObj = JSONResponseHandler.toJsonObject(response);
    if (JSONResponseHandler.checkResponse(responseObj) && responseObj.get(JSONApiResponseKeysEnum.RESULT.getKey()) instanceof JsonArray) {
        JsonArray array = (JsonArray) responseObj.get(JSONApiResponseKeysEnum.RESULT.getKey());
        List<Device> deviceList = new LinkedList<Device>();
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i) instanceof JsonObject) {
                deviceList.add(new DeviceImpl((JsonObject) array.get(i)));
            }
        }
        return deviceList;
    }
    return new LinkedList<Device>();
}
Also used : JsonArray(com.google.gson.JsonArray) Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) JsonObject(com.google.gson.JsonObject) DeviceImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.impl.DeviceImpl) LinkedList(java.util.LinkedList)

Aggregations

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