BolusIntentRequest.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import Combine
  2. import CoreData
  3. import Foundation
  4. @available(iOS 16.0,*) final class BolusIntentRequest: BaseIntentsRequest {
  5. func bolus(_ bolusAmount: Double) async throws -> String {
  6. var bolusQuantity: Decimal = 0
  7. switch settingsManager.settings.bolusShortcut {
  8. // Block boluses if they are disabled
  9. case .notAllowed:
  10. return String(
  11. localized:
  12. "Bolusing via Shortcuts is disabled in Trio settings."
  13. )
  14. // Block any bolus attempted if it is larger than the max bolus in settings
  15. case .limitBolusMax:
  16. if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
  17. return String(
  18. localized:
  19. "The bolus cannot be larger than the pump setting max bolus (\(settingsManager.pumpSettings.maxBolus.description))."
  20. )
  21. } else {
  22. bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
  23. }
  24. await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false, callback: nil)
  25. return String(
  26. localized:
  27. "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent."
  28. )
  29. }
  30. }
  31. }