ListStateIntent.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import AppIntents
  2. import Foundation
  3. @available(iOS 16.0, *) struct ListStateIntent: AppIntent {
  4. // Title of the action in the Shortcuts app
  5. static var title: LocalizedStringResource = "List last state available with Trio"
  6. var stateIntent = StateIntentRequest()
  7. // Description of the action in the Shortcuts app
  8. static var description = IntentDescription(
  9. "Allow to list the last Blood Glucose, trends, IOB and COB available in Trio"
  10. )
  11. static var parameterSummary: some ParameterSummary {
  12. Summary("List all states of Trio")
  13. }
  14. <<<<<<< HEAD
  15. @MainActor func perform() async throws -> some ReturnsValue<StateiAPSResults> & ShowsSnippetView {
  16. let context = CoreDataStack.shared.persistentContainer.viewContext
  17. let glucoseValues = try? stateIntent.getLastGlucose(onContext: context)
  18. let iob_cob_value = try? stateIntent.getIobAndCob(onContext: context)
  19. =======
  20. @MainActor func perform() async throws -> some ReturnsValue<StateResults> & ShowsSnippetView {
  21. let glucoseValues = try? stateIntent.getLastBG()
  22. let iob_cob_value = try? stateIntent.getIOB_COB()
  23. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  24. guard let glucoseValue = glucoseValues else { throw StateIntentError.NoBG }
  25. guard let iob_cob = iob_cob_value else { throw StateIntentError.NoIOBCOB }
  26. let BG = StateResults(
  27. glucose: glucoseValue.glucose,
  28. trend: glucoseValue.trend,
  29. delta: glucoseValue.delta,
  30. date: glucoseValue.dateGlucose,
  31. iob: iob_cob.iob,
  32. cob: iob_cob.cob,
  33. unit: stateIntent.settingsManager.settings.units
  34. )
  35. let iob_text = String(format: "%.2f", iob_cob.iob)
  36. let cob_text = String(format: "%.2f", iob_cob.cob)
  37. return .result(
  38. value: BG,
  39. view: ListStateView(state: BG)
  40. )
  41. }
  42. }