PumpOpsSession+LoopKit.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // PumpOpsSession.swift
  3. // Loop
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import Foundation
  8. import LoopKit
  9. extension PumpOpsSession {
  10. public func getBasalRateSchedule(for profile: BasalProfile) throws -> BasalRateSchedule? {
  11. let basalSchedule = try getBasalSchedule(for: profile)
  12. return BasalRateSchedule(dailyItems: basalSchedule?.entries.map { $0.repeatingScheduleValue } ?? [], timeZone: pump.timeZone)
  13. }
  14. }
  15. extension BasalSchedule {
  16. public init(repeatingScheduleValues: [LoopKit.RepeatingScheduleValue<Double>]) {
  17. self.init(entries: repeatingScheduleValues.enumerated().map({ (index, value) -> BasalScheduleEntry in
  18. return BasalScheduleEntry(index: index, repeatingScheduleValue: value)
  19. }))
  20. }
  21. }
  22. extension MinimedKit.BasalScheduleEntry {
  23. init(index: Int, repeatingScheduleValue: LoopKit.RepeatingScheduleValue<Double>) {
  24. self.init(index: index, timeOffset: repeatingScheduleValue.startTime, rate: repeatingScheduleValue.value)
  25. }
  26. var repeatingScheduleValue: LoopKit.RepeatingScheduleValue<Double> {
  27. return RepeatingScheduleValue(startTime: timeOffset, value: rate)
  28. }
  29. }