Java Code Examples for com.eveningoutpost.dexdrip.Services.DexCollectionService#getBestLimitterHardwareName()

The following examples show how to use com.eveningoutpost.dexdrip.Services.DexCollectionService#getBestLimitterHardwareName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NightscoutUploader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private void postDeviceStatus(NightscoutService nightscoutService, String apiSecret) throws Exception {

        // TODO optimize based on changes avoiding stale marker issues
        final boolean always_send_battery = true; // nightscout doesn't currently display device device status if it thinks its stale
        final List<String> batteries = new ArrayList<>();
        batteries.add("Phone");
        if ((DexCollectionType.hasBattery() && (Pref.getBoolean("send_bridge_battery_to_nightscout", true)))
                || (Home.get_forced_wear() && DexCollectionType.getDexCollectionType().equals(DexCollectionType.DexcomG5))) {
            batteries.add("Bridge");
        }
        if (DexCollectionType.hasWifi()) batteries.add("Parakeet");

        for (String battery : batteries) {

            int battery_level;
            String battery_name = "";
            switch (battery) {
                case "Phone":
                    battery_level = getBatteryLevel();
                    battery_name = Build.MANUFACTURER + " " + Build.MODEL;
                    break;
                case "Bridge":
                    battery_level = Pref.getInt("bridge_battery", -1);
                    battery_name = DexCollectionService.getBestLimitterHardwareName();
                    break;
                case "Parakeet":
                    battery_level = Pref.getInt("parakeet_battery", -1);
                    battery_name = "Parakeet";
                    break;
                default:
                    battery_level = -1;
                    break;
            }
            final long last_battery_level = PersistentStore.getLong(LAST_NIGHTSCOUT_BATTERY_LEVEL);

            final JSONArray array = new JSONArray();
            final JSONObject json = new JSONObject();
            final JSONObject uploader = new JSONObject();

            if ((battery_level > 0) && (battery_level != last_battery_level || always_send_battery)) {
                PersistentStore.setLong(LAST_NIGHTSCOUT_BATTERY_LEVEL, battery_level);
                // UserError.Log.d(TAG, "Uploading battery detail: " + battery_level);
                // json.put("uploaderBattery", battery_level); // old style

                uploader.put("battery", battery_level);
                json.put("device", battery_name);
                json.put("uploader", uploader);

                array.put(json);

                // example
                //{
                //    "device": "openaps://ediscout2.local",
                //        "uploader": {
                //    "battery": 60,
                //            "batteryVoltage": 3783,
                //            "temperature": "+51.0°C"
                //}
                //}


                final RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
                Response<ResponseBody> r;
                if (apiSecret != null) {
                    r = nightscoutService.uploadDeviceStatus(apiSecret, body).execute();
                } else
                    r = nightscoutService.uploadDeviceStatus(body).execute();
                if (!r.isSuccessful()) throw new UploaderException(r.message(), r.code());
                // } else {
                //     UserError.Log.d(TAG, "Battery level is same as previous - not uploading: " + battery_level);
                checkGzipSupport(r);
            }
        }
    }
 
Example 2
Source File: NightscoutUploader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void postDeviceStatus(NightscoutService nightscoutService, String apiSecret) throws Exception {

        // TODO optimize based on changes avoiding stale marker issues
        final boolean always_send_battery = true; // nightscout doesn't currently display device device status if it thinks its stale
        final List<String> batteries = new ArrayList<>();
        batteries.add("Phone");
        if ((DexCollectionType.hasBattery() && (Pref.getBoolean("send_bridge_battery_to_nightscout", true)))
                || (Home.get_forced_wear() && DexCollectionType.getDexCollectionType().equals(DexCollectionType.DexcomG5))) {
            batteries.add("Bridge");
        }
        if (DexCollectionType.hasWifi()) batteries.add("Parakeet");

        for (String battery : batteries) {

            int battery_level;
            String battery_name = "";
            switch (battery) {
                case "Phone":
                    battery_level = getBatteryLevel();
                    battery_name = Build.MANUFACTURER + " " + Build.MODEL;
                    break;
                case "Bridge":
                    battery_level = Pref.getInt("bridge_battery", -1);
                    battery_name = DexCollectionService.getBestLimitterHardwareName();
                    break;
                case "Parakeet":
                    battery_level = Pref.getInt("parakeet_battery", -1);
                    battery_name = "Parakeet";
                    break;
                default:
                    battery_level = -1;
                    break;
            }
            final long last_battery_level = PersistentStore.getLong(LAST_NIGHTSCOUT_BATTERY_LEVEL);

            final JSONArray array = new JSONArray();
            final JSONObject json = new JSONObject();
            final JSONObject uploader = new JSONObject();

            if ((battery_level > 0) && (battery_level != last_battery_level || always_send_battery)) {
                PersistentStore.setLong(LAST_NIGHTSCOUT_BATTERY_LEVEL, battery_level);
                // UserError.Log.d(TAG, "Uploading battery detail: " + battery_level);
                // json.put("uploaderBattery", battery_level); // old style

                uploader.put("battery", battery_level);
                json.put("device", battery_name);
                json.put("uploader", uploader);

                array.put(json);

                // example
                //{
                //    "device": "openaps://ediscout2.local",
                //        "uploader": {
                //    "battery": 60,
                //            "batteryVoltage": 3783,
                //            "temperature": "+51.0°C"
                //}
                //}


                final RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
                Response<ResponseBody> r;
                if (apiSecret != null) {
                    r = nightscoutService.uploadDeviceStatus(apiSecret, body).execute();
                } else
                    r = nightscoutService.uploadDeviceStatus(body).execute();
                if (!r.isSuccessful()) throw new UploaderException(r.message(), r.code());
                // } else {
                //     UserError.Log.d(TAG, "Battery level is same as previous - not uploading: " + battery_level);
                checkGzipSupport(r);
            }
        }
    }