DataTableProvider.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import CoreData
  2. import Foundation
  3. import HealthKit
  4. extension DataTable {
  5. final class Provider: BaseProvider, DataTableProvider {
  6. @Injected() var nightscoutManager: NightscoutManager!
  7. @Injected() var healthkitManager: HealthKitManager!
  8. @Injected() var tidepoolManager: TidepoolManager!
  9. func pumpSettings() -> PumpSettings {
  10. storage.retrieve(OpenAPS.Settings.settings, as: PumpSettings.self)
  11. ?? PumpSettings(from: OpenAPS.defaults(for: OpenAPS.Settings.settings))
  12. ?? PumpSettings(insulinActionCurve: 6, maxBolus: 10, maxBasal: 2)
  13. }
  14. func deleteCarbsFromNightscout(withID id: String) {
  15. Task.detached { [weak self] in
  16. guard let self = self else { return }
  17. await self.nightscoutManager.deleteCarbs(withID: id)
  18. }
  19. }
  20. func deleteInsulinFromNightscout(withID id: String) {
  21. Task.detached { [weak self] in
  22. guard let self = self else { return }
  23. await self.nightscoutManager.deleteInsulin(withID: id)
  24. }
  25. }
  26. func deleteInsulinFromHealth(withSyncID id: String) {
  27. Task.detached { [weak self] in
  28. guard let self = self else { return }
  29. await self.healthkitManager.deleteInsulin(syncID: id)
  30. }
  31. }
  32. func deleteManualGlucoseFromNightscout(withID id: String) {
  33. Task.detached { [weak self] in
  34. guard let self = self else { return }
  35. await self.nightscoutManager.deleteManualGlucose(withID: id)
  36. }
  37. }
  38. func deleteGlucoseFromHealth(withSyncID id: String) {
  39. Task.detached { [weak self] in
  40. guard let self = self else { return }
  41. await self.healthkitManager.deleteGlucose(syncID: id)
  42. }
  43. }
  44. func deleteMealDataFromHealth(byID id: String, sampleType: HKSampleType) {
  45. Task.detached { [weak self] in
  46. guard let self = self else { return }
  47. await self.healthkitManager.deleteMealData(byID: id, sampleType: sampleType)
  48. }
  49. }
  50. }
  51. }