Search in sources :

Example 1 with JSONDeviceImpl

use of org.openhab.binding.digitalstrom.internal.client.entity.impl.JSONDeviceImpl in project openhab1-addons by openhab.

the class DigitalSTROMJSONImpl method getApartmentDevices.

@Override
public List<Device> getApartmentDevices(String token, boolean unassigned) {
    String response = null;
    if (unassigned) {
        response = transport.execute(JSONRequestConstants.JSON_APARTMENT_GET_DEVICES + JSONRequestConstants.PARAMETER_TOKEN + token + JSONRequestConstants.INFIX_PARAMETER_UNASSIGNED_TRUE);
    } else {
        response = transport.execute(JSONRequestConstants.JSON_APARTMENT_GET_DEVICES + JSONRequestConstants.PARAMETER_TOKEN + token);
    }
    JSONObject responseObj = handler.toJSONObject(response);
    if (handler.checkResponse(responseObj) && responseObj.get(JSONApiResponseKeysEnum.APARTMENT_GET_DEVICES.getKey()) instanceof JSONArray) {
        JSONArray array = (JSONArray) responseObj.get(JSONApiResponseKeysEnum.APARTMENT_GET_DEVICES.getKey());
        List<Device> deviceList = new LinkedList<Device>();
        for (int i = 0; i < array.size(); i++) {
            if (array.get(i) instanceof org.json.simple.JSONObject) {
                deviceList.add(new JSONDeviceImpl((JSONObject) array.get(i)));
            }
        }
        return deviceList;
    }
    return new LinkedList<Device>();
}
Also used : JSONObject(org.json.simple.JSONObject) Device(org.openhab.binding.digitalstrom.internal.client.entity.Device) JSONArray(org.json.simple.JSONArray) JSONDeviceImpl(org.openhab.binding.digitalstrom.internal.client.entity.impl.JSONDeviceImpl) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Device (org.openhab.binding.digitalstrom.internal.client.entity.Device)1 JSONDeviceImpl (org.openhab.binding.digitalstrom.internal.client.entity.impl.JSONDeviceImpl)1