DynISF: add notification on SMB fallback

This commit is contained in:
Milos Kozak 2023-11-08 11:11:19 +01:00
parent 04bd666a3f
commit 50b7263acd
8 changed files with 29 additions and 19 deletions

View file

@ -190,7 +190,7 @@ class UiInteractionImpl @Inject constructor(
rxBus.send(EventNewNotification(Notification(id, System.currentTimeMillis(), text, level, validTo))) rxBus.send(EventNewNotification(Notification(id, System.currentTimeMillis(), text, level, validTo)))
} }
override fun addNotificationWithAction(injector: HasAndroidInjector, nsAlarm: NSAlarm) { override fun addNotificationWithAction(nsAlarm: NSAlarm) {
rxBus.send(EventNewNotification(NotificationWithAction(injector, nsAlarm))) rxBus.send(EventNewNotification(NotificationWithAction(injector, nsAlarm)))
} }

View file

@ -140,6 +140,7 @@ open class Notification {
const val BLUETOOTH_NOT_SUPPORTED = 86 const val BLUETOOTH_NOT_SUPPORTED = 86
const val PUMP_WARNING = 87 const val PUMP_WARNING = 87
const val PUMP_SYNC_ERROR = 88 const val PUMP_SYNC_ERROR = 88
const val SMB_FALLBACK = 89
const val USER_MESSAGE = 1000 const val USER_MESSAGE = 1000

View file

@ -5,7 +5,6 @@ import androidx.annotation.RawRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import app.aaps.core.interfaces.nsclient.NSAlarm import app.aaps.core.interfaces.nsclient.NSAlarm
import dagger.android.HasAndroidInjector
/** /**
* Interface to use activities located in different modules * Interface to use activities located in different modules
@ -73,7 +72,7 @@ interface UiInteraction {
fun addNotificationValidFor(id: Int, text: String, level: Int, validMinutes: Int) fun addNotificationValidFor(id: Int, text: String, level: Int, validMinutes: Int)
fun addNotificationWithSound(id: Int, text: String, level: Int, @RawRes soundId: Int?) fun addNotificationWithSound(id: Int, text: String, level: Int, @RawRes soundId: Int?)
fun addNotificationValidTo(id: Int, date: Long, text: String, level: Int, validTo: Long) fun addNotificationValidTo(id: Int, date: Long, text: String, level: Int, validTo: Long)
fun addNotificationWithAction(injector: HasAndroidInjector, nsAlarm: NSAlarm) fun addNotificationWithAction(nsAlarm: NSAlarm)
fun addNotificationWithAction(id: Int, text: String, level: Int, buttonText: Int, action: Runnable, @RawRes soundId: Int? = null, date: Long = System.currentTimeMillis()) fun addNotificationWithAction(id: Int, text: String, level: Int, buttonText: Int, action: Runnable, @RawRes soundId: Int? = null, date: Long = System.currentTimeMillis())
fun showToastAndNotification(ctx: Context?, string: String?, @RawRes soundID: Int) fun showToastAndNotification(ctx: Context?, string: String?, @RawRes soundID: Int)

View file

@ -58,7 +58,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
private val hardLimits: HardLimits, private val hardLimits: HardLimits,
private val profiler: Profiler, private val profiler: Profiler,
private val sp: SP, private val sp: SP,
private val dateUtil: DateUtil, protected val dateUtil: DateUtil,
private val repository: AppRepository, private val repository: AppRepository,
private val glucoseStatusProvider: GlucoseStatusProvider, private val glucoseStatusProvider: GlucoseStatusProvider,
private val bgQualityCheck: BgQualityCheck, private val bgQualityCheck: BgQualityCheck,

View file

@ -9,6 +9,7 @@ import app.aaps.core.interfaces.constraints.ConstraintsChecker
import app.aaps.core.interfaces.iob.GlucoseStatusProvider import app.aaps.core.interfaces.iob.GlucoseStatusProvider
import app.aaps.core.interfaces.iob.IobCobCalculator import app.aaps.core.interfaces.iob.IobCobCalculator
import app.aaps.core.interfaces.logging.AAPSLogger import app.aaps.core.interfaces.logging.AAPSLogger
import app.aaps.core.interfaces.notifications.Notification
import app.aaps.core.interfaces.plugin.ActivePlugin import app.aaps.core.interfaces.plugin.ActivePlugin
import app.aaps.core.interfaces.profile.ProfileFunction import app.aaps.core.interfaces.profile.ProfileFunction
import app.aaps.core.interfaces.profiling.Profiler import app.aaps.core.interfaces.profiling.Profiler
@ -16,8 +17,10 @@ import app.aaps.core.interfaces.resources.ResourceHelper
import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.rx.bus.RxBus
import app.aaps.core.interfaces.sharedPreferences.SP import app.aaps.core.interfaces.sharedPreferences.SP
import app.aaps.core.interfaces.stats.TddCalculator import app.aaps.core.interfaces.stats.TddCalculator
import app.aaps.core.interfaces.ui.UiInteraction
import app.aaps.core.interfaces.utils.DateUtil import app.aaps.core.interfaces.utils.DateUtil
import app.aaps.core.interfaces.utils.HardLimits import app.aaps.core.interfaces.utils.HardLimits
import app.aaps.core.interfaces.utils.T
import app.aaps.database.impl.AppRepository import app.aaps.database.impl.AppRepository
import app.aaps.plugins.aps.R import app.aaps.plugins.aps.R
import app.aaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS import app.aaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
@ -46,7 +49,8 @@ class OpenAPSSMBDynamicISFPlugin @Inject constructor(
repository: AppRepository, repository: AppRepository,
glucoseStatusProvider: GlucoseStatusProvider, glucoseStatusProvider: GlucoseStatusProvider,
bgQualityCheck: BgQualityCheck, bgQualityCheck: BgQualityCheck,
tddCalculator: TddCalculator tddCalculator: TddCalculator,
private val uiInteraction: UiInteraction
) : OpenAPSSMBPlugin( ) : OpenAPSSMBPlugin(
injector, injector,
aapsLogger, aapsLogger,
@ -78,9 +82,16 @@ class OpenAPSSMBDynamicISFPlugin @Inject constructor(
// If there is no TDD data fallback to SMB as ISF calculation may be really off // If there is no TDD data fallback to SMB as ISF calculation may be really off
override fun provideDetermineBasalAdapter(): DetermineBasalAdapter = override fun provideDetermineBasalAdapter(): DetermineBasalAdapter =
if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null || !dynIsfEnabled.value()) if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null || !dynIsfEnabled.value()) {
uiInteraction.addNotificationValidTo(
Notification.SMB_FALLBACK, dateUtil.now(),
rh.gs(R.string.fallback_smb_no_tdd), Notification.INFO, dateUtil.now() + T.mins(1).msecs()
)
DetermineBasalAdapterSMBJS(ScriptReader(context), injector) DetermineBasalAdapterSMBJS(ScriptReader(context), injector)
else DetermineBasalAdapterSMBDynamicISFJS(ScriptReader(context), injector) } else {
uiInteraction.dismissNotification(Notification.SMB_FALLBACK)
DetermineBasalAdapterSMBDynamicISFJS(ScriptReader(context), injector)
}
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
value.set(false, rh.gs(R.string.autosens_disabled_in_dyn_isf), this) value.set(false, rh.gs(R.string.autosens_disabled_in_dyn_isf), this)

View file

@ -188,7 +188,8 @@ class ConstraintsCheckerImplTest : TestBaseWithProfile() {
repository, repository,
glucoseStatusProvider, glucoseStatusProvider,
bgQualityCheck, bgQualityCheck,
tddCalculator tddCalculator,
uiInteraction
) )
openAPSAMAPlugin = openAPSAMAPlugin =
OpenAPSAMAPlugin( OpenAPSAMAPlugin(

View file

@ -642,7 +642,7 @@ class NSClientService : DaggerService() {
val defaultVal = config.NSCLIENT val defaultVal = config.NSCLIENT
if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_announcements, defaultVal)) { if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_announcements, defaultVal)) {
val nsAlarm = NSAlarmObject(announcement) val nsAlarm = NSAlarmObject(announcement)
uiInteraction.addNotificationWithAction(injector, nsAlarm) uiInteraction.addNotificationWithAction(nsAlarm)
rxBus.send(EventNSClientNewLog("◄ ANNOUNCEMENT", safeGetString(announcement, "message", "received"))) rxBus.send(EventNSClientNewLog("◄ ANNOUNCEMENT", safeGetString(announcement, "message", "received")))
aapsLogger.debug(LTag.NSCLIENT, announcement.toString()) aapsLogger.debug(LTag.NSCLIENT, announcement.toString())
} }
@ -654,7 +654,7 @@ class NSClientService : DaggerService() {
val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + alarm.optString("level"), 0L) val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + alarm.optString("level"), 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
val nsAlarm = NSAlarmObject(alarm) val nsAlarm = NSAlarmObject(alarm)
uiInteraction.addNotificationWithAction(injector, nsAlarm) uiInteraction.addNotificationWithAction(nsAlarm)
} }
rxBus.send(EventNSClientNewLog("◄ ALARM", safeGetString(alarm, "message", "received"))) rxBus.send(EventNSClientNewLog("◄ ALARM", safeGetString(alarm, "message", "received")))
aapsLogger.debug(LTag.NSCLIENT, alarm.toString()) aapsLogger.debug(LTag.NSCLIENT, alarm.toString())
@ -667,7 +667,7 @@ class NSClientService : DaggerService() {
val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + alarm.optString("level"), 0L) val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + alarm.optString("level"), 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
val nsAlarm = NSAlarmObject(alarm) val nsAlarm = NSAlarmObject(alarm)
uiInteraction.addNotificationWithAction(injector, nsAlarm) uiInteraction.addNotificationWithAction(nsAlarm)
} }
rxBus.send(EventNSClientNewLog("◄ URGENTALARM", safeGetString(alarm, "message", "received"))) rxBus.send(EventNSClientNewLog("◄ URGENTALARM", safeGetString(alarm, "message", "received")))
aapsLogger.debug(LTag.NSCLIENT, alarm.toString()) aapsLogger.debug(LTag.NSCLIENT, alarm.toString())

View file

@ -4,8 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Binder import android.os.Binder
import android.os.Handler
import android.os.HandlerThread
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import app.aaps.core.interfaces.configuration.Config import app.aaps.core.interfaces.configuration.Config
@ -63,7 +61,6 @@ class NSClientV3Service : DaggerService() {
private var wakeLock: PowerManager.WakeLock? = null private var wakeLock: PowerManager.WakeLock? = null
private val binder: IBinder = LocalBinder() private val binder: IBinder = LocalBinder()
private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
override fun onCreate() { override fun onCreate() {
@ -94,7 +91,7 @@ class NSClientV3Service : DaggerService() {
private var alarmSocket: Socket? = null private var alarmSocket: Socket? = null
internal var wsConnected = false internal var wsConnected = false
internal fun shutdownWebsockets() { private fun shutdownWebsockets() {
storageSocket?.on(Socket.EVENT_CONNECT, onConnectStorage) storageSocket?.on(Socket.EVENT_CONNECT, onConnectStorage)
storageSocket?.on(Socket.EVENT_DISCONNECT, onDisconnectStorage) storageSocket?.on(Socket.EVENT_DISCONNECT, onDisconnectStorage)
storageSocket?.on("create", onDataCreateUpdate) storageSocket?.on("create", onDataCreateUpdate)
@ -113,7 +110,8 @@ class NSClientV3Service : DaggerService() {
alarmSocket = null alarmSocket = null
} }
internal fun initializeWebSockets(reason: String) { @Suppress("SameParameterValue")
private fun initializeWebSockets(reason: String) {
if (sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").isEmpty()) return if (sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").isEmpty()) return
val urlStorage = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace(Regex("/$"), "") + "/storage" val urlStorage = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace(Regex("/$"), "") + "/storage"
val urlAlarm = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace(Regex("/$"), "") + "/alarm" val urlAlarm = sp.getString(app.aaps.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace(Regex("/$"), "") + "/alarm"
@ -277,7 +275,7 @@ class NSClientV3Service : DaggerService() {
rxBus.send(EventNSClientNewLog("◄ ANNOUNCEMENT", data.optString("message"))) rxBus.send(EventNSClientNewLog("◄ ANNOUNCEMENT", data.optString("message")))
aapsLogger.debug(LTag.NSCLIENT, data.toString()) aapsLogger.debug(LTag.NSCLIENT, data.toString())
if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_announcements, config.NSCLIENT)) if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_announcements, config.NSCLIENT))
uiInteraction.addNotificationWithAction(injector, NSAlarmObject(data)) uiInteraction.addNotificationWithAction(NSAlarmObject(data))
} }
private val onAlarm = Emitter.Listener { args -> private val onAlarm = Emitter.Listener { args ->
@ -300,7 +298,7 @@ class NSClientV3Service : DaggerService() {
if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_alarms, config.NSCLIENT)) { if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_alarms, config.NSCLIENT)) {
val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + data.optString("level"), 0L) val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + data.optString("level"), 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo)
uiInteraction.addNotificationWithAction(injector, NSAlarmObject(data)) uiInteraction.addNotificationWithAction(NSAlarmObject(data))
} }
} }
@ -311,7 +309,7 @@ class NSClientV3Service : DaggerService() {
if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_alarms, config.NSCLIENT)) { if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_alarms, config.NSCLIENT)) {
val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + data.optString("level"), 0L) val snoozedTo = sp.getLong(rh.gs(app.aaps.core.utils.R.string.key_snoozed_to) + data.optString("level"), 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo)
uiInteraction.addNotificationWithAction(injector, NSAlarmObject(data)) uiInteraction.addNotificationWithAction(NSAlarmObject(data))
} }
} }