lints, cleanup

This commit is contained in:
Milos Kozak 2023-07-15 11:21:29 +02:00
parent e3207405e8
commit fc1a471412
2 changed files with 33 additions and 30 deletions

View file

@ -22,7 +22,6 @@ import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
@ -51,7 +50,6 @@ interface IAlarmManager {
class AlarmManager @Inject constructor() : IAlarmManager { class AlarmManager @Inject constructor() : IAlarmManager {
@Inject lateinit var patchManager: IPatchManager @Inject lateinit var patchManager: IPatchManager
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var commandQueue: CommandQueue
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@ -71,6 +69,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
private var compositeDisposable: CompositeDisposable = CompositeDisposable() private var compositeDisposable: CompositeDisposable = CompositeDisposable()
private var alarmDisposable: Disposable? = null private var alarmDisposable: Disposable? = null
@Suppress("unused")
@Inject @Inject
fun onInit() { fun onInit() {
mAlarmProcess = AlarmProcess(patchManager, rxBus) mAlarmProcess = AlarmProcess(patchManager, rxBus)
@ -150,7 +149,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
context.startActivity(i) context.startActivity(i)
} }
private fun showNotification(alarmCode: AlarmCode, timeOffset: Long = 0L) { private fun showNotification(alarmCode: AlarmCode) {
var alarmMsg = resourceHelper.gs(alarmCode.resId) var alarmMsg = resourceHelper.gs(alarmCode.resId)
if (alarmCode == B000) { if (alarmCode == B000) {
val expireTimeValue = pm.getPatchWakeupTimestamp() + TimeUnit.HOURS.toMillis(84) val expireTimeValue = pm.getPatchWakeupTimestamp() + TimeUnit.HOURS.toMillis(84)
@ -171,21 +170,25 @@ class AlarmManager @Inject constructor() : IAlarmManager {
else Single.just(IAlarmProcess.ALARM_HANDLED) else Single.just(IAlarmProcess.ALARM_HANDLED)
} }
.subscribe { ret -> .subscribe { ret ->
if (ret == IAlarmProcess.ALARM_HANDLED) { when (ret) {
if (alarmCode == B001) { IAlarmProcess.ALARM_HANDLED -> {
pumpSync.syncStopTemporaryBasalWithPumpId( if (alarmCode == B001) {
timestamp = dateUtil.now(), pumpSync.syncStopTemporaryBasalWithPumpId(
endPumpId = dateUtil.now(), timestamp = dateUtil.now(),
pumpType = PumpType.EOFLOW_EOPATCH2, endPumpId = dateUtil.now(),
pumpSerial = patchManager.patchConfig.patchSerialNumber pumpType = PumpType.EOFLOW_EOPATCH2,
) pumpSerial = patchManager.patchConfig.patchSerialNumber
)
}
updateState(alarmCode, AlarmState.HANDLE)
} }
updateState(alarmCode, AlarmState.HANDLE)
}else if(ret == IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP){ IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP -> {
pm.getAlarms().needToStopBeep.add(alarmCode) pm.getAlarms().needToStopBeep.add(alarmCode)
updateState(alarmCode, AlarmState.HANDLE) updateState(alarmCode, AlarmState.HANDLE)
} else { }
showNotification(alarmCode)
else -> showNotification(alarmCode)
} }
} }
) )

View file

@ -63,16 +63,16 @@ interface IAlarmProcess {
class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmProcess { class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmProcess {
override fun doAction(context: Context, code: AlarmCode): Single<Int> { override fun doAction(context: Context, code: AlarmCode): Single<Int> {
return when (code) { return when (code) {
B001 -> resumeBasalAction(context) B001 -> resumeBasalAction(context)
A002, A003, A004, A005, A018, A019, A002, A003, A004, A005, A018, A019,
A020, A022, A023, A034, A041, A042, A020, A022, A023, A034, A041, A042,
A043, A044, A106, A107, A108, A116, A043, A044, A106, A107, A108, A116,
A117, A118 -> patchDeactivationAction(context) A117, A118 -> patchDeactivationAction(context)
A007 -> inappropriateTemperatureAction(context) A007 -> inappropriateTemperatureAction(context)
A016 -> needleInsertionErrorAction(context) A016 -> needleInsertionErrorAction(context)
B000 -> Single.just(IAlarmProcess.ALARM_HANDLED) B000 -> Single.just(IAlarmProcess.ALARM_HANDLED)
B003, B005, B006, B018 -> stopAeBeepAction(context, code) B003, B005, B006, B018 -> stopAeBeepAction(code)
B012 -> Single.just(IAlarmProcess.ALARM_HANDLED) B012 -> Single.just(IAlarmProcess.ALARM_HANDLED)
} }
} }
@ -146,20 +146,20 @@ class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmPr
patchManager.temperature patchManager.temperature
.map(TemperatureResponse::getTemperature) .map(TemperatureResponse::getTemperature)
.map { temp -> (temp >= EopatchActivity.NORMAL_TEMPERATURE_MIN && temp <= EopatchActivity.NORMAL_TEMPERATURE_MAX) } .map { temp -> (temp >= EopatchActivity.NORMAL_TEMPERATURE_MIN && temp <= EopatchActivity.NORMAL_TEMPERATURE_MAX) }
.filter{ok -> ok} .filter { ok -> ok }
.flatMap { patchManager.resumeBasal().map { it.isSuccess.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_UNHANDLED) }.toMaybe() } .flatMap { patchManager.resumeBasal().map { it.isSuccess.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_UNHANDLED) }.toMaybe() }
.defaultIfEmpty(IAlarmProcess.ALARM_UNHANDLED) .defaultIfEmpty(IAlarmProcess.ALARM_UNHANDLED)
} }
} }
private fun stopAeBeepAction(context: Context, alarm: AlarmCode): Single<Int> { private fun stopAeBeepAction(alarm: AlarmCode): Single<Int> {
if (patchManager.patchConnectionState.isConnected) { return if (patchManager.patchConnectionState.isConnected) {
return patchManager.stopAeBeep(alarm.aeCode) patchManager.stopAeBeep(alarm.aeCode)
.map { obj: PatchBooleanResponse -> obj.isSuccess } .map { obj: PatchBooleanResponse -> obj.isSuccess }
.onErrorReturn { false } .onErrorReturn { false }
.flatMap { Single.just(it.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)) } .flatMap { Single.just(it.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)) }
}else{ } else {
return Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP) Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)
} }
} }
} }