BolusStateModel.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. import CoreData
  2. import Foundation
  3. import LoopKit
  4. import SwiftUI
  5. import Swinject
  6. extension Bolus {
  7. final class StateModel: BaseStateModel<Provider> {
  8. @Injected() var unlockmanager: UnlockManager!
  9. @Injected() var apsManager: APSManager!
  10. @Injected() var broadcaster: Broadcaster!
  11. @Injected() var pumpHistoryStorage: PumpHistoryStorage!
  12. // added for bolus calculator
  13. @Injected() var settings: SettingsManager!
  14. @Injected() var nsManager: NightscoutManager!
  15. @Injected() var carbsStorage: CarbsStorage!
  16. @Injected() var glucoseStorage: GlucoseStorage!
  17. @Injected() var determinationStorage: DeterminationStorage!
  18. @Published var predictions: Predictions?
  19. @Published var amount: Decimal = 0
  20. @Published var insulinRecommended: Decimal = 0
  21. @Published var insulinRequired: Decimal = 0
  22. @Published var units: GlucoseUnits = .mgdL
  23. @Published var percentage: Decimal = 0
  24. @Published var threshold: Decimal = 0
  25. @Published var maxBolus: Decimal = 0
  26. @Published var errorString: Decimal = 0
  27. @Published var evBG: Decimal = 0
  28. @Published var insulin: Decimal = 0
  29. @Published var isf: Decimal = 0
  30. @Published var error: Bool = false
  31. @Published var minGuardBG: Decimal = 0
  32. @Published var minDelta: Decimal = 0
  33. @Published var expectedDelta: Decimal = 0
  34. @Published var minPredBG: Decimal = 0
  35. @Published var waitForSuggestion: Bool = false
  36. @Published var carbRatio: Decimal = 0
  37. @Published var addButtonPressed: Bool = false
  38. var waitForSuggestionInitial: Bool = false
  39. // added for bolus calculator
  40. @Published var target: Decimal = 0
  41. @Published var cob: Int16 = 0
  42. @Published var iob: Decimal = 0
  43. @Published var currentBG: Decimal = 0
  44. @Published var fifteenMinInsulin: Decimal = 0
  45. @Published var deltaBG: Decimal = 0
  46. @Published var targetDifferenceInsulin: Decimal = 0
  47. @Published var targetDifference: Decimal = 0
  48. @Published var wholeCob: Decimal = 0
  49. @Published var wholeCobInsulin: Decimal = 0
  50. @Published var iobInsulinReduction: Decimal = 0
  51. @Published var wholeCalc: Decimal = 0
  52. @Published var insulinCalculated: Decimal = 0
  53. @Published var fraction: Decimal = 0
  54. @Published var useCalc: Bool = false
  55. @Published var basal: Decimal = 0
  56. @Published var fattyMeals: Bool = false
  57. @Published var fattyMealFactor: Decimal = 0
  58. @Published var useFattyMealCorrectionFactor: Bool = false
  59. @Published var displayPresets: Bool = true
  60. @Published var currentBasal: Decimal = 0
  61. @Published var sweetMeals: Bool = false
  62. @Published var sweetMealFactor: Decimal = 0
  63. @Published var useSuperBolus: Bool = false
  64. @Published var superBolusInsulin: Decimal = 0
  65. @Published var meal: [CarbsEntry]?
  66. @Published var carbs: Decimal = 0
  67. @Published var fat: Decimal = 0
  68. @Published var protein: Decimal = 0
  69. @Published var note: String = ""
  70. @Published var date = Date()
  71. @Published var carbsRequired: Decimal?
  72. @Published var useFPUconversion: Bool = false
  73. @Published var dish: String = ""
  74. @Published var selection: MealPresetStored?
  75. @Published var summation: [String] = []
  76. @Published var maxCarbs: Decimal = 0
  77. @Published var id_: String = ""
  78. @Published var summary: String = ""
  79. @Published var skipBolus: Bool = false
  80. @Published var externalInsulin: Bool = false
  81. @Published var showInfo: Bool = false
  82. @Published var glucoseFromPersistence: [GlucoseStored] = []
  83. @Published var determination: [OrefDetermination] = []
  84. let now = Date.now
  85. let context = CoreDataStack.shared.persistentContainer.viewContext
  86. let backgroundContext = CoreDataStack.shared.newTaskContext()
  87. typealias PumpEvent = PumpEventStored.EventType
  88. override func subscribe() {
  89. setupNotification()
  90. setupGlucoseArray()
  91. setupDeterminationsArray()
  92. broadcaster.register(DeterminationObserver.self, observer: self)
  93. broadcaster.register(BolusFailureObserver.self, observer: self)
  94. units = settingsManager.settings.units
  95. percentage = settingsManager.settings.insulinReqPercentage
  96. maxBolus = provider.pumpSettings().maxBolus
  97. // added
  98. fraction = settings.settings.overrideFactor
  99. useCalc = settings.settings.useCalc
  100. fattyMeals = settings.settings.fattyMeals
  101. fattyMealFactor = settings.settings.fattyMealFactor
  102. sweetMeals = settings.settings.sweetMeals
  103. sweetMealFactor = settings.settings.sweetMealFactor
  104. displayPresets = settings.settings.displayPresets
  105. maxCarbs = settings.settings.maxCarbs
  106. skipBolus = settingsManager.settings.skipBolusScreenAfterCarbs
  107. useFPUconversion = settingsManager.settings.useFPUconversion
  108. if waitForSuggestionInitial {
  109. Task {
  110. let ok = await apsManager.determineBasal()
  111. if !ok {
  112. self.waitForSuggestion = false
  113. self.insulinRequired = 0
  114. self.insulinRecommended = 0
  115. }
  116. }
  117. }
  118. }
  119. // MARK: - Basal
  120. func getCurrentBasal() {
  121. let basalEntries = provider.getProfile()
  122. let now = Date()
  123. let calendar = Calendar.current
  124. let dateFormatter = DateFormatter()
  125. dateFormatter.dateFormat = "HH:mm:ss"
  126. dateFormatter.timeZone = TimeZone.current
  127. for (index, entry) in basalEntries.enumerated() {
  128. guard let entryTime = dateFormatter.date(from: entry.start) else {
  129. print("Invalid entry start time: \(entry.start)")
  130. continue
  131. }
  132. // Combine the current date with the time from entry.start
  133. let entryStartTime = calendar.date(
  134. bySettingHour: calendar.component(.hour, from: entryTime),
  135. minute: calendar.component(.minute, from: entryTime),
  136. second: calendar.component(.second, from: entryTime),
  137. of: now
  138. )!
  139. let entryEndTime: Date
  140. if index < basalEntries.count - 1,
  141. let nextEntryTime = dateFormatter.date(from: basalEntries[index + 1].start)
  142. {
  143. let nextEntryStartTime = calendar.date(
  144. bySettingHour: calendar.component(.hour, from: nextEntryTime),
  145. minute: calendar.component(.minute, from: nextEntryTime),
  146. second: calendar.component(.second, from: nextEntryTime),
  147. of: now
  148. )!
  149. entryEndTime = nextEntryStartTime
  150. } else {
  151. // If it's the last entry, use the same start time plus one day as the end time
  152. entryEndTime = calendar.date(byAdding: .day, value: 1, to: entryStartTime)!
  153. }
  154. if now >= entryStartTime, now < entryEndTime {
  155. currentBasal = entry.rate
  156. break
  157. }
  158. }
  159. }
  160. // MARK: CALCULATIONS FOR THE BOLUS CALCULATOR
  161. /// Calculate insulin recommendation
  162. func calculateInsulin() -> Decimal {
  163. // ensure that isf is in mg/dL
  164. var conversion: Decimal {
  165. units == .mmolL ? 0.0555 : 1
  166. }
  167. let isfForCalculation = isf / conversion
  168. // insulin needed for the current blood glucose
  169. targetDifference = currentBG - target
  170. targetDifferenceInsulin = targetDifference / isfForCalculation
  171. // more or less insulin because of bg trend in the last 15 minutes
  172. fifteenMinInsulin = deltaBG / isfForCalculation
  173. // determine whole COB for which we want to dose insulin for and then determine insulin for wholeCOB
  174. wholeCob = Decimal(cob) + carbs
  175. wholeCobInsulin = wholeCob / carbRatio
  176. // determine how much the calculator reduces/ increases the bolus because of IOB
  177. iobInsulinReduction = (-1) * iob
  178. // adding everything together
  179. // add a calc for the case that no fifteenMinInsulin is available
  180. if deltaBG != 0 {
  181. wholeCalc = (targetDifferenceInsulin + iobInsulinReduction + wholeCobInsulin + fifteenMinInsulin)
  182. } else {
  183. // add (rare) case that no glucose value is available -> maybe display warning?
  184. // if no bg is available, ?? sets its value to 0
  185. if currentBG == 0 {
  186. wholeCalc = (iobInsulinReduction + wholeCobInsulin)
  187. } else {
  188. wholeCalc = (targetDifferenceInsulin + iobInsulinReduction + wholeCobInsulin)
  189. }
  190. }
  191. // apply custom factor at the end of the calculations
  192. let result = wholeCalc * fraction
  193. // apply custom factor if fatty meal toggle in bolus calc config settings is on and the box for fatty meals is checked (in RootView)
  194. if useFattyMealCorrectionFactor {
  195. insulinCalculated = result * fattyMealFactor
  196. } else if useSuperBolus {
  197. superBolusInsulin = sweetMealFactor * currentBasal
  198. insulinCalculated = result + superBolusInsulin
  199. } else {
  200. insulinCalculated = result
  201. }
  202. // display no negative insulinCalculated
  203. insulinCalculated = max(insulinCalculated, 0)
  204. insulinCalculated = min(insulinCalculated, maxBolus)
  205. guard let apsManager = apsManager else {
  206. debug(.apsManager, "APSManager could not be gracefully unwrapped")
  207. return insulinCalculated
  208. }
  209. return apsManager.roundBolus(amount: insulinCalculated)
  210. }
  211. // MARK: - Button tasks
  212. @MainActor func invokeTreatmentsTask() {
  213. Task {
  214. addButtonPressed = true
  215. let isInsulinGiven = amount > 0
  216. let isCarbsPresent = carbs > 0
  217. let isFatPresent = fat > 0
  218. let isProteinPresent = protein > 0
  219. if isInsulinGiven {
  220. try await handleInsulin(isExternal: externalInsulin)
  221. } else if isCarbsPresent || isFatPresent || isProteinPresent {
  222. waitForSuggestion = true
  223. } else {
  224. hideModal()
  225. return
  226. }
  227. await saveMeal()
  228. // if glucose data is stale end the custom loading animation by hiding the modal
  229. // guard glucoseOfLast20Min.first?.date ?? now >= Date().addingTimeInterval(-12.minutes.timeInterval) else {
  230. // return hideModal()
  231. // }
  232. }
  233. }
  234. // MARK: - Insulin
  235. @MainActor private func handleInsulin(isExternal: Bool) async throws {
  236. if !isExternal {
  237. await addPumpInsulin()
  238. } else {
  239. await addExternalInsulin()
  240. }
  241. waitForSuggestion = true
  242. }
  243. @MainActor func addPumpInsulin() async {
  244. guard amount > 0 else {
  245. showModal(for: nil)
  246. return
  247. }
  248. let maxAmount = Double(min(amount, maxBolus))
  249. do {
  250. let authenticated = try await unlockmanager.unlock()
  251. if authenticated {
  252. await apsManager.enactBolus(amount: maxAmount, isSMB: false)
  253. } else {
  254. print("authentication failed")
  255. }
  256. } catch {
  257. print("authentication error for pump bolus: \(error.localizedDescription)")
  258. DispatchQueue.main.async {
  259. self.waitForSuggestion = false
  260. if self.addButtonPressed {
  261. self.hideModal()
  262. }
  263. }
  264. }
  265. }
  266. private func savePumpInsulin(amount _: Decimal) {
  267. context.perform {
  268. // create pump event
  269. let newPumpEvent = PumpEventStored(context: self.context)
  270. newPumpEvent.timestamp = Date()
  271. newPumpEvent.type = PumpEvent.bolus.rawValue
  272. // create bolus entry and specify relationship to pump event
  273. let newBolusEntry = BolusStored(context: self.context)
  274. newBolusEntry.pumpEvent = newPumpEvent
  275. newBolusEntry.amount = self.amount as NSDecimalNumber
  276. newBolusEntry.isExternal = false
  277. newBolusEntry.isSMB = false
  278. do {
  279. guard self.context.hasChanges else { return }
  280. try self.context.save()
  281. } catch {
  282. print(error.localizedDescription)
  283. }
  284. }
  285. }
  286. // MARK: - EXTERNAL INSULIN
  287. @MainActor func addExternalInsulin() async {
  288. guard amount > 0 else {
  289. showModal(for: nil)
  290. return
  291. }
  292. amount = min(amount, maxBolus * 3)
  293. do {
  294. let authenticated = try await unlockmanager.unlock()
  295. if authenticated {
  296. // store external dose to pump history
  297. await pumpHistoryStorage.storeExternalInsulinEvent(amount: amount, timestamp: date)
  298. // perform determine basal sync
  299. await apsManager.determineBasalSync()
  300. } else {
  301. print("authentication failed")
  302. }
  303. } catch {
  304. print("authentication error for external insulin: \(error.localizedDescription)")
  305. DispatchQueue.main.async {
  306. self.waitForSuggestion = false
  307. if self.addButtonPressed {
  308. self.hideModal()
  309. }
  310. }
  311. }
  312. }
  313. // MARK: - Carbs
  314. @MainActor func saveMeal() async {
  315. guard carbs > 0 || fat > 0 || protein > 0 else { return }
  316. carbs = min(carbs, maxCarbs)
  317. id_ = UUID().uuidString
  318. let carbsToStore = [CarbsEntry(
  319. id: id_,
  320. createdAt: now,
  321. actualDate: date,
  322. carbs: carbs,
  323. fat: fat,
  324. protein: protein,
  325. note: note,
  326. enteredBy: CarbsEntry.manual,
  327. isFPU: false, fpuID: UUID().uuidString
  328. )]
  329. await carbsStorage.storeCarbs(carbsToStore)
  330. if carbs > 0 || fat > 0 || protein > 0 {
  331. // only perform determine basal sync if the user doesn't use the pump bolus, otherwise the enact bolus func in the APSManger does a sync
  332. if amount <= 0 {
  333. await apsManager.determineBasalSync()
  334. }
  335. }
  336. }
  337. // MARK: - Presets
  338. func deletePreset() {
  339. if selection != nil {
  340. context.delete(selection!)
  341. do {
  342. guard context.hasChanges else { return }
  343. try context.save()
  344. } catch {
  345. print(error.localizedDescription)
  346. }
  347. carbs = 0
  348. fat = 0
  349. protein = 0
  350. }
  351. selection = nil
  352. }
  353. func removePresetFromNewMeal() {
  354. let a = summation.firstIndex(where: { $0 == selection?.dish! })
  355. if a != nil, summation[a ?? 0] != "" {
  356. summation.remove(at: a!)
  357. }
  358. }
  359. func addPresetToNewMeal() {
  360. let test: String = selection?.dish ?? "dontAdd"
  361. if test != "dontAdd" {
  362. summation.append(test)
  363. }
  364. }
  365. func addNewPresetToWaitersNotepad(_ dish: String) {
  366. summation.append(dish)
  367. }
  368. func addToSummation() {
  369. summation.append(selection?.dish ?? "")
  370. }
  371. func waitersNotepad() -> String {
  372. var filteredArray = summation.filter { !$0.isEmpty }
  373. if carbs == 0, protein == 0, fat == 0 {
  374. filteredArray = []
  375. }
  376. guard filteredArray != [] else {
  377. return ""
  378. }
  379. var carbs_: Decimal = 0.0
  380. var fat_: Decimal = 0.0
  381. var protein_: Decimal = 0.0
  382. var presetArray = [MealPresetStored]()
  383. context.performAndWait {
  384. let requestPresets = MealPresetStored.fetchRequest() as NSFetchRequest<MealPresetStored>
  385. try? presetArray = context.fetch(requestPresets)
  386. }
  387. var waitersNotepad = [String]()
  388. var stringValue = ""
  389. for each in filteredArray {
  390. let countedSet = NSCountedSet(array: filteredArray)
  391. let count = countedSet.count(for: each)
  392. if each != stringValue {
  393. waitersNotepad.append("\(count) \(each)")
  394. }
  395. stringValue = each
  396. for sel in presetArray {
  397. if sel.dish == each {
  398. carbs_ += (sel.carbs)! as Decimal
  399. fat_ += (sel.fat)! as Decimal
  400. protein_ += (sel.protein)! as Decimal
  401. break
  402. }
  403. }
  404. }
  405. let extracarbs = carbs - carbs_
  406. let extraFat = fat - fat_
  407. let extraProtein = protein - protein_
  408. var addedString = ""
  409. if extracarbs > 0, filteredArray.isNotEmpty {
  410. addedString += "Additional carbs: \(extracarbs) ,"
  411. } else if extracarbs < 0 { addedString += "Removed carbs: \(extracarbs) " }
  412. if extraFat > 0, filteredArray.isNotEmpty {
  413. addedString += "Additional fat: \(extraFat) ,"
  414. } else if extraFat < 0 { addedString += "Removed fat: \(extraFat) ," }
  415. if extraProtein > 0, filteredArray.isNotEmpty {
  416. addedString += "Additional protein: \(extraProtein) ,"
  417. } else if extraProtein < 0 { addedString += "Removed protein: \(extraProtein) ," }
  418. if addedString != "" {
  419. waitersNotepad.append(addedString)
  420. }
  421. var waitersNotepadString = ""
  422. if waitersNotepad.count == 1 {
  423. waitersNotepadString = waitersNotepad[0]
  424. } else if waitersNotepad.count > 1 {
  425. for each in waitersNotepad {
  426. if each != waitersNotepad.last {
  427. waitersNotepadString += " " + each + ","
  428. } else { waitersNotepadString += " " + each }
  429. }
  430. }
  431. return waitersNotepadString
  432. }
  433. }
  434. }
  435. extension Bolus.StateModel: DeterminationObserver, BolusFailureObserver {
  436. func determinationDidUpdate(_: Determination) {
  437. DispatchQueue.main.async {
  438. self.waitForSuggestion = false
  439. if self.addButtonPressed {
  440. self.hideModal()
  441. }
  442. }
  443. }
  444. func bolusDidFail() {
  445. DispatchQueue.main.async {
  446. self.waitForSuggestion = false
  447. if self.addButtonPressed {
  448. self.hideModal()
  449. }
  450. }
  451. }
  452. }
  453. // MARK: - Setup Notifications
  454. extension Bolus.StateModel {
  455. /// listens for the notifications sent when the managedObjectContext has saved!
  456. func setupNotification() {
  457. Foundation.NotificationCenter.default.addObserver(
  458. self,
  459. selector: #selector(contextDidSave(_:)),
  460. name: Notification.Name.NSManagedObjectContextDidSave,
  461. object: backgroundContext
  462. )
  463. }
  464. /// determine the actions when the context has changed
  465. ///
  466. /// its done on a background thread and after that the UI gets updated on the main thread
  467. @objc private func contextDidSave(_ notification: Notification) {
  468. guard let userInfo = notification.userInfo else { return }
  469. Task { [weak self] in
  470. await self?.processUpdates(userInfo: userInfo)
  471. }
  472. }
  473. private func processUpdates(userInfo: [AnyHashable: Any]) async {
  474. var objects = Set((userInfo[NSInsertedObjectsKey] as? Set<NSManagedObject>) ?? [])
  475. objects.formUnion((userInfo[NSUpdatedObjectsKey] as? Set<NSManagedObject>) ?? [])
  476. objects.formUnion((userInfo[NSDeletedObjectsKey] as? Set<NSManagedObject>) ?? [])
  477. let glucoseUpdates = objects.filter { $0 is GlucoseStored }
  478. let determinationUpdates = objects.filter { $0 is OrefDetermination }
  479. DispatchQueue.global(qos: .background).async {
  480. if glucoseUpdates.isNotEmpty {
  481. self.setupGlucoseArray()
  482. }
  483. if determinationUpdates.isNotEmpty {
  484. self.setupDeterminationsArray()
  485. }
  486. }
  487. }
  488. }
  489. // MARK: - Setup Glucose and Determinations
  490. extension Bolus.StateModel {
  491. // Glucose
  492. private func setupGlucoseArray() {
  493. Task {
  494. let ids = await self.fetchGlucose()
  495. await updateGlucoseArray(with: ids)
  496. }
  497. }
  498. private func fetchGlucose() async -> [NSManagedObjectID] {
  499. let results = await CoreDataStack.shared.fetchEntitiesAsync(
  500. ofType: GlucoseStored.self,
  501. onContext: backgroundContext,
  502. predicate: NSPredicate.predicateFor30MinAgo,
  503. key: "date",
  504. ascending: false,
  505. fetchLimit: 3
  506. )
  507. return await backgroundContext.perform {
  508. return results.map(\.objectID)
  509. }
  510. }
  511. @MainActor private func updateGlucoseArray(with IDs: [NSManagedObjectID]) {
  512. do {
  513. let glucoseObjects = try IDs.compactMap { id in
  514. try context.existingObject(with: id) as? GlucoseStored
  515. }
  516. glucoseFromPersistence = glucoseObjects
  517. let lastGlucose = glucoseFromPersistence.first?.glucose ?? 0
  518. let thirdLastGlucose = glucoseFromPersistence.last?.glucose ?? 0
  519. let delta = Decimal(lastGlucose) - Decimal(thirdLastGlucose)
  520. currentBG = Decimal(lastGlucose)
  521. deltaBG = delta
  522. } catch {
  523. debugPrint(
  524. "Home State: \(#function) \(DebuggingIdentifiers.failed) error while updating the glucose array: \(error.localizedDescription)"
  525. )
  526. }
  527. }
  528. // Determinations
  529. private func setupDeterminationsArray() {
  530. Task {
  531. let ids = await determinationStorage.fetchLastDeterminationObjectID(
  532. predicate: NSPredicate.enactedDetermination
  533. )
  534. await updateDeterminationsArray(with: ids)
  535. }
  536. }
  537. @MainActor private func updateDeterminationsArray(with IDs: [NSManagedObjectID]) {
  538. do {
  539. let determinationObjects = try IDs.compactMap { id in
  540. try context.existingObject(with: id) as? OrefDetermination
  541. }
  542. guard let mostRecentDetermination = determinationObjects.first else { return }
  543. determination = determinationObjects
  544. // setup vars for bolus calculation
  545. insulinRequired = (mostRecentDetermination.insulinReq ?? 0) as Decimal
  546. evBG = (mostRecentDetermination.eventualBG ?? 0) as Decimal
  547. insulin = (mostRecentDetermination.insulinForManualBolus ?? 0) as Decimal
  548. target = (mostRecentDetermination.currentTarget ?? 100) as Decimal
  549. isf = (mostRecentDetermination.insulinSensitivity ?? 0) as Decimal
  550. cob = mostRecentDetermination.cob as Int16
  551. iob = (mostRecentDetermination.iob ?? 0) as Decimal
  552. basal = (mostRecentDetermination.tempBasal ?? 0) as Decimal
  553. carbRatio = (mostRecentDetermination.carbRatio ?? 0) as Decimal
  554. getCurrentBasal()
  555. insulinCalculated = calculateInsulin()
  556. } catch {
  557. debugPrint(
  558. "Home State: \(#function) \(DebuggingIdentifiers.failed) error while updating the determinations array: \(error.localizedDescription)"
  559. )
  560. }
  561. }
  562. }