Merge pull request #748 from samspycher/feature/eros-history

Add History DB Table to Eros Module
This commit is contained in:
Milos Kozak 2021-10-18 09:09:52 +02:00 committed by GitHub
commit 2bb28245c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 274 additions and 67 deletions

View file

@ -43,6 +43,7 @@ import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
@ -161,6 +162,12 @@ abstract class PluginsModule {
@IntKey(156) @IntKey(156)
abstract fun bindOmnipodDashPumpPlugin(plugin: OmnipodDashPumpPlugin): PluginBase abstract fun bindOmnipodDashPumpPlugin(plugin: OmnipodDashPumpPlugin): PluginBase
@Binds
@PumpDriver
@IntoMap
@IntKey(135)
abstract fun bindOmnipodErosPumpPlugin(plugin: OmnipodErosPumpPlugin): PluginBase
@Binds @Binds
@PumpDriver @PumpDriver
@IntoMap @IntoMap

View file

@ -14,4 +14,16 @@ dependencies {
implementation project(':pump-common') implementation project(':pump-common')
implementation project(':omnipod-common') implementation project(':omnipod-common')
implementation project(':rileylink') implementation project(':rileylink')
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor("androidx.room:room-compiler:$room_version")
// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$room_version")
// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Test helpers
testImplementation("androidx.room:room-testing:$room_version")
} }

View file

@ -0,0 +1,62 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.history
import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import info.nightscout.androidaps.plugins.pump.omnipod.eros.definition.PodHistoryEntryType
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity
import org.junit.After
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ErosHistoryTest {
private lateinit var dao: ErosHistoryRecordDao
private lateinit var database: ErosHistoryDatabase
private lateinit var erosHistory: ErosHistory
@Before
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
database = Room.inMemoryDatabaseBuilder(
context,
ErosHistoryDatabase::class.java
).build()
dao = database.historyRecordDao()
erosHistory = ErosHistory(dao)
}
@Test
fun testInsertionAndRetrieval() {
var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
assert(history.isEmpty())
val type = PodHistoryEntryType.SET_BOLUS.code.toLong()
val entity = ErosHistoryRecordEntity(1000L, type)
erosHistory.create(entity)
erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong()))
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
assert(history.size == 2)
assert(type.equals(history.first().podEntryTypeCode))
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, false);
assert(history.size == 2)
assert(type.equals(history.last().podEntryTypeCode))
val returnedEntity = erosHistory.findErosHistoryRecordByPumpId(entity.pumpId)
assertNotNull(returnedEntity)
assert(type.equals(returnedEntity.podEntryTypeCode))
}
@After
fun tearDown() {
database.close()
}
}

View file

@ -20,6 +20,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -63,11 +64,11 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSilenceAlerts;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandDeactivatePod; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandDeactivatePod;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandHandleTimeChange; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandHandleTimeChange;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandPlayTestBeep; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandPlayTestBeep;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandResumeDelivery; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandResumeDelivery;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSilenceAlerts;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSuspendDelivery; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSuspendDelivery;
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandUpdateAlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandUpdateAlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.data.RLHistoryItemOmnipod; import info.nightscout.androidaps.plugins.pump.omnipod.eros.data.RLHistoryItemOmnipod;
@ -86,6 +87,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodEr
import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosTbrChanged; import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosTbrChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosUncertainTbrRecovered; import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosUncertainTbrRecovered;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager; import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandGetPodStatus; import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandGetPodStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandReadPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandReadPulseLog;
@ -126,6 +128,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
private final ErosPodStateManager podStateManager; private final ErosPodStateManager podStateManager;
private final RileyLinkServiceData rileyLinkServiceData; private final RileyLinkServiceData rileyLinkServiceData;
private final AapsOmnipodErosManager aapsOmnipodErosManager; private final AapsOmnipodErosManager aapsOmnipodErosManager;
private final ErosHistory erosHistory;
private final AapsOmnipodUtil aapsOmnipodUtil; private final AapsOmnipodUtil aapsOmnipodUtil;
private final RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final OmnipodAlertUtil omnipodAlertUtil; private final OmnipodAlertUtil omnipodAlertUtil;
@ -171,6 +174,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
ActivePlugin activePlugin, ActivePlugin activePlugin,
SP sp, SP sp,
ErosPodStateManager podStateManager, ErosPodStateManager podStateManager,
ErosHistory erosHistory,
AapsOmnipodErosManager aapsOmnipodErosManager, AapsOmnipodErosManager aapsOmnipodErosManager,
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy, FabricPrivacy fabricPrivacy,
@ -203,6 +207,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
this.podStateManager = podStateManager; this.podStateManager = podStateManager;
this.rileyLinkServiceData = rileyLinkServiceData; this.rileyLinkServiceData = rileyLinkServiceData;
this.aapsOmnipodErosManager = aapsOmnipodErosManager; this.aapsOmnipodErosManager = aapsOmnipodErosManager;
this.erosHistory = erosHistory;
this.aapsOmnipodUtil = aapsOmnipodUtil; this.aapsOmnipodUtil = aapsOmnipodUtil;
this.rileyLinkUtil = rileyLinkUtil; this.rileyLinkUtil = rileyLinkUtil;
this.omnipodAlertUtil = omnipodAlertUtil; this.omnipodAlertUtil = omnipodAlertUtil;
@ -650,12 +655,19 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
return deliverBolus(detailedBolusInfo); return deliverBolus(detailedBolusInfo);
} else { } else {
// no bolus required, carb only treatment // no bolus required, carb only treatment
// activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true); boolean result = pumpSync.syncCarbsWithTimestamp(
detailedBolusInfo.timestamp,
detailedBolusInfo.carbs,
null,
model(),
serialNumber());
// return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncCarbsWithTimestamp " +
// .carbsDelivered(detailedBolusInfo.carbs); "[date=%d, carbs=%.2f, pumpSerial=%s] - Result: %b",
// Needs refactor detailedBolusInfo.timestamp, detailedBolusInfo.carbs, serialNumber(), result));
throw new IllegalStateException("Not implemented");
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
.carbsDelivered(detailedBolusInfo.carbs);
} }
} }

View file

@ -0,0 +1,28 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.dagger
import android.content.Context
import dagger.Module
import dagger.Provides
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao
import javax.inject.Singleton
@Module
class OmnipodErosHistoryModule {
@Provides
@Singleton
internal fun provideDatabase(context: Context): ErosHistoryDatabase = ErosHistoryDatabase.build(context)
@Provides
@Singleton
internal fun provideHistoryRecordDao(erosHistoryDatabase: ErosHistoryDatabase): ErosHistoryRecordDao =
erosHistoryDatabase.historyRecordDao()
@Provides
@Singleton
internal fun provideErosHistory(dao: ErosHistoryRecordDao) =
ErosHistory(dao)
}

View file

@ -16,7 +16,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.OmnipodErosOvervi
import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.wizard.activation.ErosPodActivationWizardActivity import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.wizard.activation.ErosPodActivationWizardActivity
import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.wizard.deactivation.ErosPodDeactivationWizardActivity import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.wizard.deactivation.ErosPodDeactivationWizardActivity
@Module @Module(includes = [OmnipodErosHistoryModule::class])
@Suppress("unused") @Suppress("unused")
abstract class OmnipodErosModule { abstract class OmnipodErosModule {

View file

@ -0,0 +1,32 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.history;
import java.util.List;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordDao;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity;
public class ErosHistory
{
private ErosHistoryRecordDao dao;
public ErosHistory(ErosHistoryRecordDao dao) {
this.dao = dao;
}
public List<ErosHistoryRecordEntity> getAllErosHistoryRecordsFromTimestamp(long timeInMillis, boolean ascending) {
if (ascending){
return dao.allSinceAsc(timeInMillis);
}
else {
return dao.allSinceDesc(timeInMillis);
}
}
public ErosHistoryRecordEntity findErosHistoryRecordByPumpId(long pumpId) {
return dao.byId(pumpId);
}
public void create(ErosHistoryRecordEntity historyRecord){
dao.insert(historyRecord);
}
}

View file

@ -0,0 +1,30 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(
entities = [ErosHistoryRecordEntity::class],
exportSchema = false,
version = ErosHistoryDatabase.VERSION
)
abstract class ErosHistoryDatabase : RoomDatabase() {
abstract fun historyRecordDao(): ErosHistoryRecordDao
companion object {
const val VERSION = 1
fun build(context: Context) =
Room.databaseBuilder(
context.applicationContext,
ErosHistoryDatabase::class.java,
"omnipod_eros_history_database.db"
)
.fallbackToDestructiveMigration()
.build()
}
}

View file

@ -0,0 +1,24 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
@Dao
interface ErosHistoryRecordDao {
@Query("SELECT * from historyrecords WHERE date >= :since order by date asc")
fun allSinceAsc(since: Long): List<ErosHistoryRecordEntity>
@Query("SELECT * from historyrecords WHERE date >= :since order by date desc")
fun allSinceDesc(since: Long): List<ErosHistoryRecordEntity>
@Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1")
fun byId(id: Long): ErosHistoryRecordEntity?
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(ErosHistoryRecordEntity: ErosHistoryRecordEntity)
}

View file

@ -1,47 +1,37 @@
package info.nightscout.androidaps.db; package info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database;
import com.j256.ormlite.field.DatabaseField; import androidx.room.Entity;
import com.j256.ormlite.table.DatabaseTable; import androidx.room.Index;
import androidx.room.PrimaryKey;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
/** /**
* Created by andy on 30.11.2019. * Created by andy on 30.11.2019.
*/ */
@DatabaseTable(tableName = "PodHistory") @Entity(tableName = "historyrecords", indices = {@Index("date")})
public class OmnipodHistoryRecord implements Comparable<OmnipodHistoryRecord> { public class ErosHistoryRecordEntity implements Comparable<ErosHistoryRecordEntity> {
@DatabaseField(id = true) @PrimaryKey
public long date;
@DatabaseField
private long podEntryTypeCode;
@DatabaseField
private String data;
@DatabaseField
private boolean success;
@DatabaseField
private long pumpId; private long pumpId;
public long date;
@DatabaseField private long podEntryTypeCode;
private String data;
private boolean success;
private String podSerial; private String podSerial;
@DatabaseField
private Boolean successConfirmed; private Boolean successConfirmed;
public OmnipodHistoryRecord() { public ErosHistoryRecordEntity() {
generatePumpId(); generatePumpId();
} }
public OmnipodHistoryRecord(long dateTimeInMillis, long podEntryTypeCode) { public ErosHistoryRecordEntity(long dateTimeInMillis, long podEntryTypeCode) {
this.date = dateTimeInMillis; this.date = dateTimeInMillis;
this.podEntryTypeCode = podEntryTypeCode; this.podEntryTypeCode = podEntryTypeCode;
generatePumpId(); generatePumpId();
} }
public long getDate() { public long getDate() {
return this.date; return this.date;
} }
@ -108,7 +98,7 @@ public class OmnipodHistoryRecord implements Comparable<OmnipodHistoryRecord> {
} }
@Override @Override
public int compareTo(OmnipodHistoryRecord otherOne) { public int compareTo(ErosHistoryRecordEntity otherOne) {
return (int) (otherOne.date - this.date); return (int) (otherOne.date - this.date);
} }
} }

View file

@ -17,7 +17,6 @@ import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.activities.ErrorHelperActivity; import info.nightscout.androidaps.activities.ErrorHelperActivity;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.OmnipodHistoryRecord;
import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.extensions.PumpStateExtensionKt; import info.nightscout.androidaps.extensions.PumpStateExtensionKt;
@ -71,9 +70,11 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.Ril
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkTimeoutException; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkTimeoutException;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkUnexpectedException; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkUnexpectedException;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkUnreachableException; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.exception.RileyLinkUnreachableException;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.ErosPodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.ErosPodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.OmnipodAlertUtil; import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.OmnipodAlertUtil;
@ -87,6 +88,7 @@ import io.reactivex.subjects.SingleSubject;
public class AapsOmnipodErosManager { public class AapsOmnipodErosManager {
private final ErosPodStateManager podStateManager; private final ErosPodStateManager podStateManager;
private final ErosHistory erosHistory;
private final AapsOmnipodUtil aapsOmnipodUtil; private final AapsOmnipodUtil aapsOmnipodUtil;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final RxBus rxBus; private final RxBus rxBus;
@ -116,6 +118,7 @@ public class AapsOmnipodErosManager {
@Inject @Inject
public AapsOmnipodErosManager(OmnipodRileyLinkCommunicationManager communicationService, public AapsOmnipodErosManager(OmnipodRileyLinkCommunicationManager communicationService,
ErosPodStateManager podStateManager, ErosPodStateManager podStateManager,
ErosHistory erosHistory,
AapsOmnipodUtil aapsOmnipodUtil, AapsOmnipodUtil aapsOmnipodUtil,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers, AapsSchedulers aapsSchedulers,
@ -128,6 +131,7 @@ public class AapsOmnipodErosManager {
PumpSync pumpSync) { PumpSync pumpSync) {
this.podStateManager = podStateManager; this.podStateManager = podStateManager;
this.erosHistory = erosHistory;
this.aapsOmnipodUtil = aapsOmnipodUtil; this.aapsOmnipodUtil = aapsOmnipodUtil;
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
@ -692,19 +696,25 @@ public class AapsOmnipodErosManager {
if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.getCarbsTimestamp() != null) { if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.getCarbsTimestamp() != null) {
// split out a separate carbs record without a pumpId // split out a separate carbs record without a pumpId
DetailedBolusInfo carbInfo = new DetailedBolusInfo(); pumpSync.syncCarbsWithTimestamp(
carbInfo.setCarbsTimestamp(detailedBolusInfo.getCarbsTimestamp()); detailedBolusInfo.getCarbsTimestamp(),
carbInfo.carbs = detailedBolusInfo.carbs; detailedBolusInfo.carbs,
carbInfo.setPumpType(PumpType.USER); null,
// activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false); PumpType.USER,
// Needs refactor serialNumber());
// remove carbs from bolusInfo to not trigger any unwanted code paths in // remove carbs from bolusInfo to not trigger any unwanted code paths in
// TreatmentsPlugin.addToHistoryTreatment() method // TreatmentsPlugin.addToHistoryTreatment() method
detailedBolusInfo.carbs = 0; detailedBolusInfo.carbs = 0;
} }
// activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false); pumpSync.syncBolusWithPumpId(
// Needs refactor detailedBolusInfo.timestamp,
throw new IllegalStateException("Not implemented"); detailedBolusInfo.insulin,
detailedBolusInfo.getBolusType(),
detailedBolusInfo.getBolusPumpId(),
detailedBolusInfo.getPumpType(),
serialNumber());
} }
public synchronized void createSuspendedFakeTbrIfNotExists() { public synchronized void createSuspendedFakeTbrIfNotExists() {
@ -743,9 +753,8 @@ public class AapsOmnipodErosManager {
public boolean hasSuspendedFakeTbr() { public boolean hasSuspendedFakeTbr() {
PumpSync.PumpState pumpState = pumpSync.expectedPumpState(); PumpSync.PumpState pumpState = pumpSync.expectedPumpState();
if (pumpState.getTemporaryBasal() != null && pumpState.getTemporaryBasal().getPumpId() != null) { if (pumpState.getTemporaryBasal() != null && pumpState.getTemporaryBasal().getPumpId() != null) {
// OmnipodHistoryRecord historyRecord = databaseHelper.findOmnipodHistoryRecordByPumpId(pumpState.getTemporaryBasal().getPumpId()); ErosHistoryRecordEntity historyRecord = erosHistory.findErosHistoryRecordByPumpId(pumpState.getTemporaryBasal().getPumpId());
// return historyRecord != null && PodHistoryEntryType.getByCode(historyRecord.getPodEntryTypeCode()).equals(PodHistoryEntryType.SET_FAKE_SUSPENDED_TEMPORARY_BASAL); return historyRecord != null && PodHistoryEntryType.getByCode(historyRecord.getPodEntryTypeCode()).equals(PodHistoryEntryType.SET_FAKE_SUSPENDED_TEMPORARY_BASAL);
throw new IllegalStateException("Not implemented");
} }
return false; return false;
} }
@ -834,22 +843,21 @@ public class AapsOmnipodErosManager {
private long addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, private long addToHistory(long requestTime, PodHistoryEntryType entryType, Object data,
boolean success) { boolean success) {
OmnipodHistoryRecord omnipodHistoryRecord = new OmnipodHistoryRecord(requestTime, entryType.getCode()); ErosHistoryRecordEntity erosHistoryRecordEntity = new ErosHistoryRecordEntity(requestTime, entryType.getCode());
if (data != null) { if (data != null) {
if (data instanceof String) { if (data instanceof String) {
omnipodHistoryRecord.setData((String) data); erosHistoryRecordEntity.setData((String) data);
} else { } else {
omnipodHistoryRecord.setData(aapsOmnipodUtil.getGsonInstance().toJson(data)); erosHistoryRecordEntity.setData(aapsOmnipodUtil.getGsonInstance().toJson(data));
} }
} }
omnipodHistoryRecord.setSuccess(success); erosHistoryRecordEntity.setSuccess(success);
omnipodHistoryRecord.setPodSerial(podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None"); erosHistoryRecordEntity.setPodSerial(podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None");
// databaseHelper.createOrUpdate(omnipodHistoryRecord); erosHistory.create(erosHistoryRecordEntity);
// return omnipodHistoryRecord.getPumpId(); return erosHistoryRecordEntity.getPumpId();
throw new IllegalStateException("Not implemented");
} }
private void executeCommand(Runnable runnable) { private void executeCommand(Runnable runnable) {

View file

@ -23,7 +23,8 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.db.OmnipodHistoryRecord; import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity;
import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.interfaces.Profile;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
@ -41,6 +42,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
@Inject AAPSLogger aapsLogger; @Inject AAPSLogger aapsLogger;
@Inject AapsOmnipodUtil aapsOmnipodUtil; @Inject AapsOmnipodUtil aapsOmnipodUtil;
@Inject ResourceHelper resourceHelper; @Inject ResourceHelper resourceHelper;
@Inject ErosHistory erosHistory;
private Spinner historyTypeSpinner; private Spinner historyTypeSpinner;
private TextView statusView; private TextView statusView;
@ -48,8 +50,8 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
private LinearLayoutManager linearLayoutManager; private LinearLayoutManager linearLayoutManager;
private static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All; private static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All;
private final List<OmnipodHistoryRecord> fullHistoryList = new ArrayList<>(); private final List<ErosHistoryRecordEntity> fullHistoryList = new ArrayList<>();
private final List<OmnipodHistoryRecord> filteredHistoryList = new ArrayList<>(); private final List<ErosHistoryRecordEntity> filteredHistoryList = new ArrayList<>();
private RecyclerViewAdapter recyclerViewAdapter; private RecyclerViewAdapter recyclerViewAdapter;
private boolean manualChange = false; private boolean manualChange = false;
@ -66,9 +68,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.HOUR_OF_DAY, -24); gc.add(Calendar.HOUR_OF_DAY, -24);
// databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), false); fullHistoryList.addAll(erosHistory.getAllErosHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true));
// fullHistoryList.addAll(databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true));
throw new IllegalStateException("Not implemented");
} }
@ -81,7 +81,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
if (group == PumpHistoryEntryGroup.All) { if (group == PumpHistoryEntryGroup.All) {
this.filteredHistoryList.addAll(fullHistoryList); this.filteredHistoryList.addAll(fullHistoryList);
} else { } else {
for (OmnipodHistoryRecord pumpHistoryEntry : fullHistoryList) { for (ErosHistoryRecordEntity pumpHistoryEntry : fullHistoryList) {
if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) { if (PodHistoryEntryType.getByCode(pumpHistoryEntry.getPodEntryTypeCode()).getGroup() == group) {
this.filteredHistoryList.add(pumpHistoryEntry); this.filteredHistoryList.add(pumpHistoryEntry);
} }
@ -204,14 +204,14 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> { public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
List<OmnipodHistoryRecord> historyList; List<ErosHistoryRecordEntity> historyList;
RecyclerViewAdapter(List<OmnipodHistoryRecord> historyList) { RecyclerViewAdapter(List<ErosHistoryRecordEntity> historyList) {
this.historyList = historyList; this.historyList = historyList;
} }
void setHistoryList(List<OmnipodHistoryRecord> historyList) { void setHistoryList(List<ErosHistoryRecordEntity> historyList) {
this.historyList = historyList; this.historyList = historyList;
Collections.sort(this.historyList); Collections.sort(this.historyList);
} }
@ -228,7 +228,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
@Override @Override
public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) { public void onBindViewHolder(@NonNull HistoryViewHolder holder, int position) {
OmnipodHistoryRecord record = historyList.get(position); ErosHistoryRecordEntity record = historyList.get(position);
if (record != null) { if (record != null) {
holder.timeView.setText(record.getDateTimeString()); holder.timeView.setText(record.getDateTimeString());
@ -238,7 +238,7 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
} }
private void setValue(OmnipodHistoryRecord historyEntry, TextView valueView) { private void setValue(ErosHistoryRecordEntity historyEntry, TextView valueView) {
//valueView.setText(""); //valueView.setText("");
if (historyEntry.isSuccess()) { if (historyEntry.isSuccess()) {

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
@ -34,6 +35,7 @@ class OmnipodErosPumpPluginTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock(answer = Answers.RETURNS_DEEP_STUBS) lateinit var activePlugin: ActivePlugin @Mock(answer = Answers.RETURNS_DEEP_STUBS) lateinit var activePlugin: ActivePlugin
@Mock lateinit var aapsOmnipodErosManager: AapsOmnipodErosManager @Mock lateinit var aapsOmnipodErosManager: AapsOmnipodErosManager
@Mock lateinit var erosHistory: ErosHistory
@Mock lateinit var commandQueueProvider: CommandQueueProvider @Mock lateinit var commandQueueProvider: CommandQueueProvider
@Mock lateinit var rileyLinkUtil: RileyLinkUtil @Mock lateinit var rileyLinkUtil: RileyLinkUtil
@Mock lateinit var pumpSync: PumpSync @Mock lateinit var pumpSync: PumpSync
@ -51,7 +53,7 @@ class OmnipodErosPumpPluginTest : TestBase() {
// mock all the things // mock all the things
val plugin = OmnipodErosPumpPlugin( val plugin = OmnipodErosPumpPlugin(
injector, aapsLogger, TestAapsSchedulers(), rxBusWrapper, null, injector, aapsLogger, TestAapsSchedulers(), rxBusWrapper, null,
resourceHelper, activePlugin, null, null, aapsOmnipodErosManager, commandQueueProvider, resourceHelper, activePlugin, null, null, erosHistory, aapsOmnipodErosManager, commandQueueProvider,
null, null, null, null, null, null, null, null,
rileyLinkUtil, null, null, pumpSync rileyLinkUtil, null, null, pumpSync
) )