AAPSClient: provide info about charging state
This commit is contained in:
parent
e2d91f6203
commit
ba58fb5ff7
13 changed files with 3731 additions and 8 deletions
|
@ -48,6 +48,7 @@ interface ProcessedDeviceStatusData {
|
||||||
|
|
||||||
var clock = 0L
|
var clock = 0L
|
||||||
var battery = 0
|
var battery = 0
|
||||||
|
var isCharging: Boolean? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
val uploaderMap: HashMap<String, Uploader>
|
val uploaderMap: HashMap<String, Uploader>
|
||||||
|
|
|
@ -22,6 +22,7 @@ data class NSDeviceStatus(
|
||||||
val createdAt: String? = null, // string or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long...
|
val createdAt: String? = null, // string or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long...
|
||||||
@SerializedName("date") val date: Long?, // date as milliseconds
|
@SerializedName("date") val date: Long?, // date as milliseconds
|
||||||
@SerializedName("uploaderBattery") val uploaderBattery: Int?,// integer($int64)
|
@SerializedName("uploaderBattery") val uploaderBattery: Int?,// integer($int64)
|
||||||
|
@SerializedName("isCharging") val isCharging: Boolean?,
|
||||||
@SerializedName("device") val device: String?, // "openaps://samsung SM-G970F"
|
@SerializedName("device") val device: String?, // "openaps://samsung SM-G970F"
|
||||||
|
|
||||||
@SerializedName("uploader") val uploader: Uploader?,
|
@SerializedName("uploader") val uploader: Uploader?,
|
||||||
|
@ -57,7 +58,7 @@ data class NSDeviceStatus(
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable data class Uploader(
|
@Serializable data class Uploader(
|
||||||
@SerializedName("battery") val battery: Int?,
|
@SerializedName("battery") val battery: Int?
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable data class Configuration(
|
@Serializable data class Configuration(
|
||||||
|
|
|
@ -17,6 +17,7 @@ internal fun RemoteDeviceStatus.toNSDeviceStatus(): NSDeviceStatus =
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
date = date,
|
date = date,
|
||||||
uploaderBattery = uploaderBattery,
|
uploaderBattery = uploaderBattery,
|
||||||
|
isCharging = isCharging,
|
||||||
device = device,
|
device = device,
|
||||||
uploader = NSDeviceStatus.Uploader(uploader?.battery),
|
uploader = NSDeviceStatus.Uploader(uploader?.battery),
|
||||||
pump = pump?.toNSDeviceStatusPump(),
|
pump = pump?.toNSDeviceStatusPump(),
|
||||||
|
@ -33,6 +34,7 @@ internal fun NSDeviceStatus.toRemoteDeviceStatus(): RemoteDeviceStatus =
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
date = date,
|
date = date,
|
||||||
uploaderBattery = uploaderBattery,
|
uploaderBattery = uploaderBattery,
|
||||||
|
isCharging = isCharging,
|
||||||
device = device,
|
device = device,
|
||||||
uploader = RemoteDeviceStatus.Uploader(uploader?.battery),
|
uploader = RemoteDeviceStatus.Uploader(uploader?.battery),
|
||||||
pump = pump?.toRemoteDeviceStatusPump(),
|
pump = pump?.toRemoteDeviceStatusPump(),
|
||||||
|
|
|
@ -22,6 +22,7 @@ internal data class RemoteDeviceStatus(
|
||||||
val createdAt: String? = null, // string or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long...
|
val createdAt: String? = null, // string or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long...
|
||||||
@SerializedName("date") val date: Long?, // date as milliseconds
|
@SerializedName("date") val date: Long?, // date as milliseconds
|
||||||
@SerializedName("uploaderBattery") val uploaderBattery: Int?,// integer($int64)
|
@SerializedName("uploaderBattery") val uploaderBattery: Int?,// integer($int64)
|
||||||
|
@SerializedName("isCharging") val isCharging: Boolean?,
|
||||||
@SerializedName("device") val device: String?, // "openaps://samsung SM-G970F"
|
@SerializedName("device") val device: String?, // "openaps://samsung SM-G970F"
|
||||||
|
|
||||||
@SerializedName("uploader") val uploader: Uploader?,
|
@SerializedName("uploader") val uploader: Uploader?,
|
||||||
|
@ -57,7 +58,7 @@ internal data class RemoteDeviceStatus(
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable data class Uploader(
|
@Serializable data class Uploader(
|
||||||
@SerializedName("battery") val battery: Int?,
|
@SerializedName("battery") val battery: Int?
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable data class Configuration(
|
@Serializable data class Configuration(
|
||||||
|
|
|
@ -27,7 +27,8 @@ data class DeviceStatus(
|
||||||
var enacted: String? = null,
|
var enacted: String? = null,
|
||||||
var suggested: String? = null,
|
var suggested: String? = null,
|
||||||
var iob: String? = null,
|
var iob: String? = null,
|
||||||
var uploaderBattery: Int = 0,
|
var uploaderBattery: Int,
|
||||||
|
var isCharging: Boolean?,
|
||||||
var configuration: String? = null
|
var configuration: String? = null
|
||||||
|
|
||||||
) : DBEntryWithTime {
|
) : DBEntryWithTime {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -44,7 +44,7 @@ import info.nightscout.database.entities.TotalDailyDose
|
||||||
import info.nightscout.database.entities.UserEntry
|
import info.nightscout.database.entities.UserEntry
|
||||||
import info.nightscout.database.entities.VersionChange
|
import info.nightscout.database.entities.VersionChange
|
||||||
|
|
||||||
const val DATABASE_VERSION = 22
|
const val DATABASE_VERSION = 23
|
||||||
|
|
||||||
@Database(version = DATABASE_VERSION,
|
@Database(version = DATABASE_VERSION,
|
||||||
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,
|
||||||
|
|
|
@ -28,6 +28,7 @@ open class DatabaseModule {
|
||||||
// .addMigrations(migration11to12)
|
// .addMigrations(migration11to12)
|
||||||
.addMigrations(migration20to21)
|
.addMigrations(migration20to21)
|
||||||
.addMigrations(migration21to22)
|
.addMigrations(migration21to22)
|
||||||
|
.addMigrations(migration22to23)
|
||||||
.addCallback(object : Callback() {
|
.addCallback(object : Callback() {
|
||||||
override fun onOpen(db: SupportSQLiteDatabase) {
|
override fun onOpen(db: SupportSQLiteDatabase) {
|
||||||
super.onOpen(db)
|
super.onOpen(db)
|
||||||
|
@ -80,4 +81,12 @@ open class DatabaseModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val migration22to23 = object : Migration(22,23) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("ALTER TABLE `deviceStatus` ADD COLUMN `isCharging` INTEGER")
|
||||||
|
// Custom indexes must be dropped on migration to pass room schema checking after upgrade
|
||||||
|
dropCustomIndexes(database)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -780,6 +780,7 @@ class LoopPlugin @Inject constructor(
|
||||||
device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL,
|
device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL,
|
||||||
pump = pump.getJSONStatus(profile, profileName, version).toString(),
|
pump = pump.getJSONStatus(profile, profileName, version).toString(),
|
||||||
uploaderBattery = receiverStatusStore.batteryLevel,
|
uploaderBattery = receiverStatusStore.batteryLevel,
|
||||||
|
isCharging = receiverStatusStore.isCharging,
|
||||||
configuration = runningConfiguration.configuration().toString()
|
configuration = runningConfiguration.configuration().toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,10 +155,11 @@ class NSDeviceStatusHandler @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUploaderData(NSDeviceStatus: NSDeviceStatus) {
|
private fun updateUploaderData(nsDeviceStatus: NSDeviceStatus) {
|
||||||
val clock = NSDeviceStatus.createdAt?.let { dateUtil.fromISODateString(it) } ?: return
|
val clock = nsDeviceStatus.createdAt?.let { dateUtil.fromISODateString(it) } ?: return
|
||||||
val device = NSDeviceStatus.device ?: return
|
val device = nsDeviceStatus.device ?: return
|
||||||
val battery = NSDeviceStatus.uploaderBattery ?: NSDeviceStatus.uploader?.battery ?: return
|
val battery = nsDeviceStatus.uploaderBattery ?: nsDeviceStatus.uploader?.battery ?: return
|
||||||
|
val isCharging = nsDeviceStatus.isCharging
|
||||||
|
|
||||||
var uploader = processedDeviceStatusData.uploaderMap[device]
|
var uploader = processedDeviceStatusData.uploaderMap[device]
|
||||||
// check if this is new data
|
// check if this is new data
|
||||||
|
@ -166,6 +167,7 @@ class NSDeviceStatusHandler @Inject constructor(
|
||||||
if (uploader == null) uploader = ProcessedDeviceStatusData.Uploader()
|
if (uploader == null) uploader = ProcessedDeviceStatusData.Uploader()
|
||||||
uploader.battery = battery
|
uploader.battery = battery
|
||||||
uploader.clock = clock
|
uploader.clock = clock
|
||||||
|
uploader.isCharging = isCharging
|
||||||
processedDeviceStatusData.uploaderMap[device] = uploader
|
processedDeviceStatusData.uploaderMap[device] = uploader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,7 @@ class ProcessedDeviceStatusDataImpl @Inject constructor(
|
||||||
|
|
||||||
override val uploaderStatusSpanned: Spanned
|
override val uploaderStatusSpanned: Spanned
|
||||||
get() {
|
get() {
|
||||||
|
var isCharging = false
|
||||||
val string = StringBuilder()
|
val string = StringBuilder()
|
||||||
string.append("<span style=\"color:${rh.gac(info.nightscout.core.ui.R.attr.nsTitleColor)}\">")
|
string.append("<span style=\"color:${rh.gac(info.nightscout.core.ui.R.attr.nsTitleColor)}\">")
|
||||||
string.append(rh.gs(R.string.uploader_short))
|
string.append(rh.gs(R.string.uploader_short))
|
||||||
|
@ -145,10 +146,12 @@ class ProcessedDeviceStatusDataImpl @Inject constructor(
|
||||||
val uploader = pair.value as ProcessedDeviceStatusData.Uploader
|
val uploader = pair.value as ProcessedDeviceStatusData.Uploader
|
||||||
if (minBattery >= uploader.battery) {
|
if (minBattery >= uploader.battery) {
|
||||||
minBattery = uploader.battery
|
minBattery = uploader.battery
|
||||||
|
isCharging = uploader.isCharging ?: false
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
|
if (isCharging) string.append("ᴪ ")
|
||||||
string.append(minBattery)
|
string.append(minBattery)
|
||||||
string.append("%")
|
string.append("%")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ fun DeviceStatus.toJson(dateUtil: DateUtil): JSONObject =
|
||||||
iob?.let { iob -> openaps.put("iob", JSONObject(iob)) }
|
iob?.let { iob -> openaps.put("iob", JSONObject(iob)) }
|
||||||
})
|
})
|
||||||
if (uploaderBattery != 0) it.put("uploaderBattery", uploaderBattery)
|
if (uploaderBattery != 0) it.put("uploaderBattery", uploaderBattery)
|
||||||
|
if (isCharging != null) it.put("isCharging", isCharging)
|
||||||
configuration?.let { configuration -> it.put("configuration", JSONObject(configuration)) }
|
configuration?.let { configuration -> it.put("configuration", JSONObject(configuration)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ fun DeviceStatus.toNSDeviceStatus(): NSDeviceStatus {
|
||||||
pump = pump,
|
pump = pump,
|
||||||
openaps = openAps,
|
openaps = openAps,
|
||||||
uploaderBattery = if (uploaderBattery != 0) uploaderBattery else null,
|
uploaderBattery = if (uploaderBattery != 0) uploaderBattery else null,
|
||||||
|
isCharging = isCharging,
|
||||||
configuration = gson.fromJson(configuration, NSDeviceStatus.Configuration::class.java),
|
configuration = gson.fromJson(configuration, NSDeviceStatus.Configuration::class.java),
|
||||||
uploader = null
|
uploader = null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue