lints, cleanup
This commit is contained in:
parent
e3207405e8
commit
fc1a471412
2 changed files with 33 additions and 30 deletions
|
@ -22,7 +22,6 @@ import info.nightscout.interfaces.notifications.Notification
|
|||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
import info.nightscout.interfaces.queue.CommandQueue
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
|
@ -51,7 +50,6 @@ interface IAlarmManager {
|
|||
class AlarmManager @Inject constructor() : IAlarmManager {
|
||||
@Inject lateinit var patchManager: IPatchManager
|
||||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
@Inject lateinit var commandQueue: CommandQueue
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
|
@ -71,6 +69,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
|
|||
private var compositeDisposable: CompositeDisposable = CompositeDisposable()
|
||||
private var alarmDisposable: Disposable? = null
|
||||
|
||||
@Suppress("unused")
|
||||
@Inject
|
||||
fun onInit() {
|
||||
mAlarmProcess = AlarmProcess(patchManager, rxBus)
|
||||
|
@ -150,7 +149,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
|
|||
context.startActivity(i)
|
||||
}
|
||||
|
||||
private fun showNotification(alarmCode: AlarmCode, timeOffset: Long = 0L) {
|
||||
private fun showNotification(alarmCode: AlarmCode) {
|
||||
var alarmMsg = resourceHelper.gs(alarmCode.resId)
|
||||
if (alarmCode == B000) {
|
||||
val expireTimeValue = pm.getPatchWakeupTimestamp() + TimeUnit.HOURS.toMillis(84)
|
||||
|
@ -171,21 +170,25 @@ class AlarmManager @Inject constructor() : IAlarmManager {
|
|||
else Single.just(IAlarmProcess.ALARM_HANDLED)
|
||||
}
|
||||
.subscribe { ret ->
|
||||
if (ret == IAlarmProcess.ALARM_HANDLED) {
|
||||
if (alarmCode == B001) {
|
||||
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||
timestamp = dateUtil.now(),
|
||||
endPumpId = dateUtil.now(),
|
||||
pumpType = PumpType.EOFLOW_EOPATCH2,
|
||||
pumpSerial = patchManager.patchConfig.patchSerialNumber
|
||||
)
|
||||
when (ret) {
|
||||
IAlarmProcess.ALARM_HANDLED -> {
|
||||
if (alarmCode == B001) {
|
||||
pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||
timestamp = dateUtil.now(),
|
||||
endPumpId = dateUtil.now(),
|
||||
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){
|
||||
pm.getAlarms().needToStopBeep.add(alarmCode)
|
||||
updateState(alarmCode, AlarmState.HANDLE)
|
||||
} else {
|
||||
showNotification(alarmCode)
|
||||
|
||||
IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP -> {
|
||||
pm.getAlarms().needToStopBeep.add(alarmCode)
|
||||
updateState(alarmCode, AlarmState.HANDLE)
|
||||
}
|
||||
|
||||
else -> showNotification(alarmCode)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -63,16 +63,16 @@ interface IAlarmProcess {
|
|||
class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmProcess {
|
||||
override fun doAction(context: Context, code: AlarmCode): Single<Int> {
|
||||
return when (code) {
|
||||
B001 -> resumeBasalAction(context)
|
||||
B001 -> resumeBasalAction(context)
|
||||
A002, A003, A004, A005, A018, A019,
|
||||
A020, A022, A023, A034, A041, A042,
|
||||
A043, A044, A106, A107, A108, A116,
|
||||
A117, A118 -> patchDeactivationAction(context)
|
||||
A007 -> inappropriateTemperatureAction(context)
|
||||
A016 -> needleInsertionErrorAction(context)
|
||||
B000 -> Single.just(IAlarmProcess.ALARM_HANDLED)
|
||||
B003, B005, B006, B018 -> stopAeBeepAction(context, code)
|
||||
B012 -> Single.just(IAlarmProcess.ALARM_HANDLED)
|
||||
A117, A118 -> patchDeactivationAction(context)
|
||||
A007 -> inappropriateTemperatureAction(context)
|
||||
A016 -> needleInsertionErrorAction(context)
|
||||
B000 -> Single.just(IAlarmProcess.ALARM_HANDLED)
|
||||
B003, B005, B006, B018 -> stopAeBeepAction(code)
|
||||
B012 -> Single.just(IAlarmProcess.ALARM_HANDLED)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,20 +146,20 @@ class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmPr
|
|||
patchManager.temperature
|
||||
.map(TemperatureResponse::getTemperature)
|
||||
.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() }
|
||||
.defaultIfEmpty(IAlarmProcess.ALARM_UNHANDLED)
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopAeBeepAction(context: Context, alarm: AlarmCode): Single<Int> {
|
||||
if (patchManager.patchConnectionState.isConnected) {
|
||||
return patchManager.stopAeBeep(alarm.aeCode)
|
||||
private fun stopAeBeepAction(alarm: AlarmCode): Single<Int> {
|
||||
return if (patchManager.patchConnectionState.isConnected) {
|
||||
patchManager.stopAeBeep(alarm.aeCode)
|
||||
.map { obj: PatchBooleanResponse -> obj.isSuccess }
|
||||
.onErrorReturn { false }
|
||||
.flatMap { Single.just(it.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)) }
|
||||
}else{
|
||||
return Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)
|
||||
} else {
|
||||
Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue