report AAPS version to NSClient log

This commit is contained in:
Milos Kozak 2021-10-29 18:41:25 +02:00
parent 414e57cc63
commit 8fe7e7ce2b
3 changed files with 8 additions and 4 deletions

View file

@ -89,7 +89,7 @@ class NSDeviceStatus @Inject constructor(
fun handleNewData(deviceStatuses: JSONArray) {
aapsLogger.debug(LTag.NSCLIENT, "Got NS deviceStatus: \$deviceStatuses")
try {
for (i in 0 until deviceStatuses.length()) {
for (i in deviceStatuses.length() -1 downTo 0) {
val devicestatusJson = deviceStatuses.getJSONObject(i)
if (devicestatusJson != null) {
setData(devicestatusJson)
@ -100,6 +100,7 @@ class NSDeviceStatus @Inject constructor(
if (devicestatusJson.has("configuration") && config.NSCLIENT) {
// copy configuration of Insulin and Sensitivity from main AAPS
runningConfiguration.apply(devicestatusJson.getJSONObject("configuration"))
break
}
}
}

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
@ -28,7 +29,7 @@ class RunningConfiguration @Inject constructor(
) {
private var counter = 0
private val every = 20 // Send only every 20 device status to save traffic
private val every = 12 // Send only every 12 device status to save traffic
// called in AAPS mode only
fun configuration(): JSONObject {
@ -58,8 +59,10 @@ class RunningConfiguration @Inject constructor(
// called in NSClient mode only
fun apply(configuration: JSONObject) {
if (configuration.has("version")) {
if (config.VERSION_NAME.startsWith(configuration.getString("version")).not())
rxBus.send(EventNSClientNewLog("VERSION", "Received AndroidAPS version ${configuration.getString("version")}"))
if (config.VERSION_NAME.startsWith(configuration.getString("version")).not()) {
rxBus.send(EventNewNotification(Notification(Notification.NSCLIENT_VERSION_DOES_NOT_MATCH, resourceHelper.gs(R.string.nsclient_version_does_not_match), Notification.NORMAL)))
}
}
if (configuration.has("insulin")) {
val insulin = Insulin.InsulinType.fromInt(JsonHelper.safeGetInt(configuration, "insulin", Insulin.InsulinType.UNKNOWN.value))