uploader battery in device status

This commit is contained in:
Milos Kozak 2017-02-20 08:32:10 +01:00
parent d030427b0f
commit d84632a8a4
3 changed files with 39 additions and 0 deletions

View file

@ -56,6 +56,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BatteryLevel;
import info.nightscout.utils.DateUtil;
/**
@ -976,6 +977,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
deviceStatus.pump = getJSONStatus();
}
}
int batteryLevel = BatteryLevel.getBatteryLevel();
if (batteryLevel != BatteryLevel.lastUploadedLevel) {
JSONObject uploaderBattery = new JSONObject();
uploaderBattery.put("uploaderBattery", batteryLevel);
deviceStatus.uploaderBattery = uploaderBattery;
BatteryLevel.lastUploadedLevel = batteryLevel;
}
deviceStatus.created_at = DateUtil.toISOString(new Date());
deviceStatus.sendToNSClient();
} catch (JSONException e) {

View file

@ -378,6 +378,7 @@ public class DeviceStatus {
public JSONObject enacted = null;
public JSONObject suggested = null;
public JSONObject iob = null;
public JSONObject uploaderBattery = null;
public String created_at = null;
public JSONObject mongoRecord () {
@ -391,6 +392,7 @@ public class DeviceStatus {
if (enacted != null) openaps.put("enacted", enacted);
if (suggested != null) openaps.put("suggested", suggested);
if (iob != null) openaps.put("iob", iob);
if (uploaderBattery != null) openaps.put("uploaderBattery", uploaderBattery);
record.put("openaps", openaps);
}
if (created_at != null) record.put("created_at" , created_at);

View file

@ -0,0 +1,28 @@
package info.nightscout.utils;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import info.nightscout.androidaps.MainApp;
/**
* Created by mike on 20.02.2017.
*/
public class BatteryLevel {
static public int lastUploadedLevel = 0;
static public int getBatteryLevel() {
Intent batteryIntent = MainApp.instance().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (batteryIntent != null) {
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (level == -1 || scale == -1) {
return 50;
}
return (int) (((float) level / (float) scale) * 100.0f);
} else return 50;
}
}