move profiles to interfaces

This commit is contained in:
Milos Kozak 2022-11-10 16:55:18 +01:00
parent cca40b9606
commit c31bfc7c23
28 changed files with 114 additions and 76 deletions

View file

@ -6,7 +6,6 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.APS
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.BgSource
import info.nightscout.androidaps.interfaces.ProfileSource
import info.nightscout.androidaps.interfaces.Pump
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.interfaces.Sensitivity
@ -21,6 +20,7 @@ import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.sync.NsClient
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventAppInitialized

View file

@ -4,7 +4,6 @@ import info.nightscout.androidaps.interfaces.APS
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.BgSource
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileSource
import info.nightscout.androidaps.interfaces.Pump
import info.nightscout.androidaps.interfaces.Sensitivity
import info.nightscout.interfaces.Config
@ -13,6 +12,7 @@ import info.nightscout.interfaces.constraints.Safety
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.sync.NsClient
import info.nightscout.interfaces.sync.Sync
import info.nightscout.rx.logging.AAPSLogger

View file

@ -1,22 +1,22 @@
package info.nightscout.androidaps.plugins.configBuilder
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.ValueWrapper
import info.nightscout.database.impl.transactions.InsertOrUpdateProfileSwitch
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.extensions.fromConstant
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.main.R
import info.nightscout.database.entities.ProfileSwitch
import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.ValueWrapper
import info.nightscout.database.impl.transactions.InsertOrUpdateProfileSwitch
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusData
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.utils.wizard
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.extensions.valueToUnits
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.Loop
@ -34,6 +35,14 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider
// for mock
@OpenForTesting
class Time {
fun secondsFromMidnight(): Int = Profile.secondsFromMidnight()
}
var time = Time()
lateinit var storage: JSONObject
var position: Int = -1
@ -96,7 +105,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
return this
}
fun isActive(): Boolean = profileFunction.secondsFromMidnight() >= validFrom() && profileFunction.secondsFromMidnight() <= validTo() && forDevice(DEVICE_PHONE)
fun isActive(): Boolean = time.secondsFromMidnight() >= validFrom() && time.secondsFromMidnight() <= validTo() && forDevice(DEVICE_PHONE)
fun doCalc(profile: Profile, profileName: String, lastBG: GlucoseValue, _synchronized: Boolean): BolusWizard {
val dbRecord = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()

View file

@ -7,12 +7,13 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InsulinConfiguration
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -172,6 +173,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -6,9 +6,9 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.androidaps.utils.wizard.QuickWizard
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONArray
import org.junit.Assert
import org.junit.Before
@ -28,13 +28,19 @@ class QuickWizardTest : TestBase() {
"\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":1,\"useBasalIOB\":2,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}"
private var array: JSONArray = JSONArray("[$data1,$data2]")
val injector = HasAndroidInjector {
class MockedTime : QuickWizardEntry.Time() {
override fun secondsFromMidnight() = 0
}
private val mockedTime = MockedTime()
private val injector = HasAndroidInjector {
AndroidInjector {
if (it is QuickWizardEntry) {
it.aapsLogger = aapsLogger
it.sp = sp
it.profileFunction = profileFunction
it.loop = loop
it.time = mockedTime
}
}
}
@ -43,7 +49,7 @@ class QuickWizardTest : TestBase() {
@Before
fun mock() {
`when`(profileFunction.secondsFromMidnight()).thenReturn(0)
`when`(sp.getString(R.string.key_quickwizard, "[]")).thenReturn("[]")
quickWizard = QuickWizard(sp, injector)
}

View file

@ -3,15 +3,16 @@ package info.nightscout.androidaps
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.database.impl.AppRepository
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -56,6 +57,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileSource
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.automation.triggers.Trigger
import info.nightscout.database.entities.OfflineEvent
@ -18,6 +17,7 @@ import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper

View file

@ -3,9 +3,9 @@ package info.nightscout.androidaps.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.data.PumpEnactResultImpl
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData
import info.nightscout.core.profile.ProfileStoreObject
@Module
@Suppress("unused")
@ -15,5 +15,5 @@ abstract class CoreDataClassesModule {
@ContributesAndroidInjector abstract fun apsResultInjector(): APSResult
@ContributesAndroidInjector abstract fun autosensDataInjector(): AutosensData
@ContributesAndroidInjector abstract fun profileStoreInjector(): ProfileStore
@ContributesAndroidInjector abstract fun profileStoreInjector(): ProfileStoreObject
}

View file

@ -5,6 +5,7 @@ import info.nightscout.interfaces.constraints.Safety
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.sync.NsClient
import info.nightscout.interfaces.sync.Sync

View file

@ -152,8 +152,7 @@ interface Profile {
}
fun milliSecFromMidnight(date: Long): Long {
val passed = DateTime(date).millisOfDay.toLong()
return passed
return DateTime(date).millisOfDay.toLong()
}
/*
* Units conversion

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.interfaces
import info.nightscout.database.entities.ProfileSwitch
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.profile.ProfileStore
interface ProfileFunction {
@ -89,11 +90,4 @@ interface ProfileFunction {
* @return true if profile switch is created
*/
fun createProfileSwitch(durationInMinutes: Int, percentage: Int, timeShiftInHours: Int): Boolean
/*
* Midnight time conversion
* (here as well for easy mock)
*/
fun secondsFromMidnight(): Int = Profile.secondsFromMidnight()
fun secondsFromMidnight(date: Long): Int = Profile.secondsFromMidnight(date)
}

View file

@ -1,11 +1,13 @@
package info.nightscout.androidaps.interfaces
package info.nightscout.core.profile
import androidx.collection.ArrayMap
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.rx.bus.RxBus
@ -16,7 +18,7 @@ import org.json.JSONException
import org.json.JSONObject
import javax.inject.Inject
class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val dateUtil: DateUtil) {
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePlugin
@ -42,7 +44,7 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
return null
}
fun getStartDate(): Long {
override fun getStartDate(): Long {
val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0
return try {
dateUtil.fromISODateString(iso)
@ -51,15 +53,15 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
}
}
fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
fun getDefaultProfileName(): String? {
override fun getDefaultProfileName(): String? {
val defaultProfileName = data.optString("defaultProfile")
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
}
fun getProfileList(): ArrayList<CharSequence> {
override fun getProfileList(): ArrayList<CharSequence> {
val ret = ArrayList<CharSequence>()
getStore()?.keys()?.let { keys ->
while (keys.hasNext()) {
@ -71,7 +73,7 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
}
@Synchronized
fun getSpecificProfile(profileName: String): PureProfile? {
override fun getSpecificProfile(profileName: String): PureProfile? {
var profile: PureProfile? = null
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
getStore()?.let { store ->
@ -96,7 +98,7 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
return null
}
val allProfilesValid: Boolean
override val allProfilesValid: Boolean
get() = getProfileList()
.asSequence()
.map { profileName -> getSpecificProfile(profileName.toString()) }

View file

@ -7,12 +7,13 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
@ -41,7 +42,7 @@ open class TestBaseWithProfile : TestBase() {
val profileInjector = HasAndroidInjector {
AndroidInjector {
if (it is ProfileStore) {
if (it is ProfileStoreObject) {
it.aapsLogger = aapsLogger
it.activePlugin = activePluginProvider
it.config = config
@ -77,7 +78,7 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
fun getInvalidProfileStore1(): ProfileStore {
@ -86,7 +87,7 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(invalidProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
fun getInvalidProfileStore2(): ProfileStore {
@ -96,6 +97,6 @@ open class TestBaseWithProfile : TestBase() {
store.put("invalid", JSONObject(invalidProfileJSON))
json.put("defaultProfile", TESTPROFILENAME + "invalid")
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -7,12 +7,13 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InsulinConfiguration
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -172,6 +173,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.interfaces
package info.nightscout.interfaces.profile
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.profile.PureProfile
import org.json.JSONArray
interface ProfileSource {

View file

@ -0,0 +1,15 @@
package info.nightscout.interfaces.profile
import org.json.JSONObject
interface ProfileStore {
val data: JSONObject
fun getStartDate(): Long
fun getDefaultProfile(): PureProfile?
fun getDefaultProfileJson(): JSONObject?
fun getDefaultProfileName(): String?
fun getProfileList(): ArrayList<CharSequence>
fun getSpecificProfile(profileName: String): PureProfile?
val allProfilesValid: Boolean
}

View file

@ -24,14 +24,15 @@ import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.utils.MidnightTime
import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.R
@ -96,7 +97,7 @@ class AutotuneFragment : DaggerFragment() {
if (autotunePlugin.lastNbDays.isEmpty())
autotunePlugin.lastNbDays = sp.getInt(R.string.key_autotune_default_tune_days, 5).toString()
val defaultValue = sp.getInt(R.string.key_autotune_default_tune_days, 5).toDouble()
profileStore = activePlugin.activeProfileSource.profile ?: ProfileStore(injector, JSONObject(), dateUtil)
profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil)
profileName = if (binding.profileList.text.toString() == rh.gs(R.string.active)) "" else binding.profileList.text.toString()
profileFunction.getProfile()?.let { currentProfile ->
profile = ATProfile(profileStore.getSpecificProfile(profileName)?.let { ProfileSealed.Pure(it) } ?: currentProfile, LocalInsulin(""), injector)
@ -297,7 +298,7 @@ class AutotuneFragment : DaggerFragment() {
@Synchronized
private fun updateGui() {
_binding ?: return
profileStore = activePlugin.activeProfileSource.profile ?: ProfileStore(injector, JSONObject(), dateUtil)
profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil)
profileName = if (binding.profileList.text.toString() == rh.gs(R.string.active)) "" else binding.profileList.text.toString()
profileFunction.getProfile()?.let { currentProfile ->
profile = ATProfile(profileStore.getSpecificProfile(profileName)?.let { ProfileSealed.Pure(it) } ?: currentProfile, LocalInsulin(""), injector)

View file

@ -6,9 +6,9 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.interfaces.BuildHelper
@ -325,7 +325,7 @@ class AutotunePlugin @Inject constructor(
fun updateProfile(newProfile: ATProfile?) {
if (newProfile == null) return
val circadian = sp.getBoolean(R.string.key_autotune_circadian_ic_isf, false)
val profileStore = activePlugin.activeProfileSource.profile ?: ProfileStore(injector, JSONObject(), dateUtil)
val profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil)
val profileList: ArrayList<CharSequence> = profileStore.getProfileList()
var indexLocalProfile = -1
for (p in profileList.indices)

View file

@ -6,13 +6,14 @@ import info.nightscout.androidaps.extensions.blockValueBySeconds
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.main.R
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.data.Block
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.Round
import info.nightscout.rx.bus.RxBus
@ -177,7 +178,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector:
json.put("defaultProfile", profilename)
json.put("store", store)
json.put("startDate", dateUtil.toISOAsUTC(dateUtil.now()))
profileStore = ProfileStore(injector, json, dateUtil)
profileStore = ProfileStoreObject(injector, json, dateUtil)
} catch (e: JSONException) {
}
return profileStore

View file

@ -12,8 +12,6 @@ import info.nightscout.androidaps.extensions.blockFromJsonArray
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileSource
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.interfaces.XDripBroadcast
import info.nightscout.androidaps.receivers.DataWorkerStorage
import info.nightscout.androidaps.utils.DecimalFormatter
@ -21,6 +19,7 @@ import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.GlucoseUnit
@ -28,6 +27,8 @@ import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.plugins.R
@ -72,7 +73,7 @@ class ProfilePlugin @Inject constructor(
aapsLogger, rh, injector
), ProfileSource {
private var rawProfile: ProfileStore? = null
private var rawProfile: ProfileStoreObject? = null
private val defaultArray = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]"
@ -388,7 +389,7 @@ class ProfilePlugin @Inject constructor(
isEdited = false
}
fun createProfileStore(): ProfileStore {
fun createProfileStore(): ProfileStoreObject {
val json = JSONObject()
val store = JSONObject()
@ -417,7 +418,7 @@ class ProfilePlugin @Inject constructor(
aapsLogger.error("Unhandled exception", e)
}
return ProfileStore(injector, json, dateUtil)
return ProfileStoreObject(injector, json, dateUtil)
}
override val profile: ProfileStore?
@ -453,7 +454,7 @@ class ProfilePlugin @Inject constructor(
?: return Result.failure(workDataOf("Error" to "missing input data"))
xDripBroadcast.sendProfile(profileJson)
if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) {
val store = ProfileStore(injector, profileJson, dateUtil)
val store = ProfileStoreObject(injector, profileJson, dateUtil)
val createdAt = store.getStartDate()
val lastLocalChange = sp.getLong(R.string.key_local_profile_last_change, 0)
aapsLogger.debug(LTag.PROFILE, "Received profileStore: createdAt: $createdAt Local last modification: $lastLocalChange")

View file

@ -7,12 +7,13 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InsulinConfiguration
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -172,6 +173,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -10,7 +10,6 @@ import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.interfaces.ProfileSource
import info.nightscout.androidaps.interfaces.XDripBroadcast
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
@ -27,6 +26,7 @@ import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.IobTotal
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.queue.Callback

View file

@ -1,18 +1,19 @@
package info.nightscout.androidaps.dana
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.Constants
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.rx.events.EventOverviewBolusProgress
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.shared.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.shared.utils.T
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.rx.events.EventOverviewBolusProgress
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.json.JSONArray
@ -380,7 +381,7 @@ class DanaPump @Inject constructor(
} catch (e: Exception) {
return null
}
return ProfileStore(injector, json, dateUtil)
return ProfileStoreObject(injector, json, dateUtil)
}
return null
}

View file

@ -6,11 +6,12 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -58,6 +59,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -7,10 +7,11 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -152,6 +153,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -6,11 +6,12 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -54,6 +55,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -7,12 +7,13 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.core.fabric.FabricPrivacy
import info.nightscout.core.profile.ProfileStoreObject
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InsulinConfiguration
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
@ -172,6 +173,6 @@ open class TestBaseWithProfile : TestBase() {
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStore(profileInjector, json, dateUtil)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}