فهرست منبع

Add docstrings to OR and TT shortcut files (intents, requests)

Deniz Cengiz 1 سال پیش
والد
کامیت
568b46ad4e

+ 15 - 2
Trio/Sources/Shortcuts/Override/ApplyOverridePresetIntent.swift

@@ -1,24 +1,28 @@
 import AppIntents
 import Foundation
 
+/// An App Intent that allows users to activate an override preset through the Shortcuts app.
 struct ApplyOverridePresetIntent: AppIntent {
-    // Title of the action in the Shortcuts app
+    /// The title displayed for this action in the Shortcuts app.
     static var title = LocalizedStringResource("Activate an override", table: "ShortcutsDetail")
 
-    // Description of the action in the Shortcuts app
+    /// The description displayed for this action in the Shortcuts app.
     static var description = IntentDescription(.init("Activate an override", table: "ShortcutsDetail"))
 
+    /// The override preset to be applied.
     @Parameter(
         title: LocalizedStringResource("Override", table: "ShortcutsDetail"),
         description: LocalizedStringResource("Override choice", table: "ShortcutsDetail")
     ) var preset: OverridePreset?
 
+    /// A boolean parameter that determines whether confirmation is required before applying the override.
     @Parameter(
         title: LocalizedStringResource("Confirm Before applying", table: "ShortcutsDetail"),
         description: LocalizedStringResource("If toggled, you will need to confirm before applying", table: "ShortcutsDetail"),
         default: true
     ) var confirmBeforeApplying: Bool
 
+    /// Defines the summary format shown in the Shortcuts app when configuring this intent.
     static var parameterSummary: some ParameterSummary {
         When(\ApplyOverridePresetIntent.$confirmBeforeApplying, .equalTo, true, {
             Summary("Applying \(\.$preset) override", table: "ShortcutsDetail") {
@@ -31,12 +35,18 @@ struct ApplyOverridePresetIntent: AppIntent {
         })
     }
 
+    /// Executes the intent to apply the selected override preset.
+    ///
+    /// - Returns: A dialog indicating whether the override was successfully applied or failed.
+    /// - Throws: An error if an issue occurs during execution.
     @MainActor func perform() async throws -> some ProvidesDialog {
         do {
+            // Determine which preset to apply
             let presetToApply: OverridePreset
             if let preset = preset {
                 presetToApply = preset
             } else {
+                // Request user selection if no preset is provided
                 presetToApply = try await $preset.requestDisambiguation(
                     among: await OverridePresetsIntentRequest().fetchAndProcessOverrides(),
                     dialog: IntentDialog(LocalizedStringResource("Select override", table: "ShortcutsDetail"))
@@ -44,6 +54,8 @@ struct ApplyOverridePresetIntent: AppIntent {
             }
 
             let displayName: String = presetToApply.name
+
+            // Request confirmation before applying if required
             if confirmBeforeApplying {
                 try await requestConfirmation(
                     result: .result(
@@ -55,6 +67,7 @@ struct ApplyOverridePresetIntent: AppIntent {
                 )
             }
 
+            // Apply the override and return the appropriate dialog message
             if await OverridePresetsIntentRequest().enactOverride(presetToApply) {
                 return .result(
                     dialog: IntentDialog(

+ 7 - 2
Trio/Sources/Shortcuts/Override/CancelOverrideIntent.swift

@@ -1,13 +1,18 @@
 import AppIntents
 import Foundation
 
+/// An App Intent that allows users to cancel an active override through the Shortcuts app.
 struct CancelOverrideIntent: AppIntent {
-    // Title of the action in the Shortcuts app
+    /// The title displayed for this action in the Shortcuts app.
     static var title = LocalizedStringResource("Cancel override", table: "ShortcutsDetail")
 
-    // Description of the action in the Shortcuts app
+    /// The description displayed for this action in the Shortcuts app.
     static var description = IntentDescription(.init("Cancel an active override", table: "ShortcutsDetail"))
 
+    /// Performs the intent action to cancel an active override.
+    ///
+    /// - Returns: A confirmation dialog indicating the override has been canceled.
+    /// - Throws: An error if the cancellation process fails.
     @MainActor func perform() async throws -> some ProvidesDialog {
         do {
             await OverridePresetsIntentRequest().cancelOverride()

+ 17 - 0
Trio/Sources/Shortcuts/Override/OverridePresetEntity.swift

@@ -3,24 +3,41 @@ import Foundation
 import Intents
 import Swinject
 
+/// Represents an override preset that can be used in the app.
 struct OverridePreset: AppEntity, Identifiable {
+    /// Default query instance for fetching override presets.
     static var defaultQuery = OverridePresetsQuery()
 
+    /// Unique identifier for the override preset.
     var id: String
+
+    /// Name of the override preset.
     var name: String
 
+    /// Provides a display representation for the override preset.
     var displayRepresentation: DisplayRepresentation {
         DisplayRepresentation(title: "\(name)")
     }
 
+    /// Representation for the entity type when displayed in UI.
     static var typeDisplayRepresentation: TypeDisplayRepresentation = "Override"
 }
 
+/// Query structure for fetching override presets in an App Intent.
 struct OverridePresetsQuery: EntityQuery {
+    /// Fetches a list of override presets matching the given identifiers.
+    ///
+    /// - Parameter identifiers: A list of override preset IDs to fetch.
+    /// - Returns: An array of `OverridePreset` objects matching the given IDs.
+    /// - Throws: An error if the fetch operation fails.
     func entities(for identifiers: [OverridePreset.ID]) async throws -> [OverridePreset] {
         try await OverridePresetsIntentRequest().fetchIDs(identifiers)
     }
 
+    /// Fetches a list of suggested override presets.
+    ///
+    /// - Returns: An array of available `OverridePreset` objects.
+    /// - Throws: An error if fetching fails.
     func suggestedEntities() async throws -> [OverridePreset] {
         try await OverridePresetsIntentRequest().fetchAndProcessOverrides()
     }

+ 37 - 64
Trio/Sources/Shortcuts/Override/OverridePresetsIntentRequest.swift

@@ -11,12 +11,15 @@ import UIKit
 
     private var intentSuccess: Bool = false
 
+    /**
+     Fetches and processes override presets from Core Data.
+
+     - Returns: An array of `OverridePreset` objects.
+     - Throws: An error if fetching fails or Core Data operations fail.
+     */
     func fetchAndProcessOverrides() async throws -> [OverridePreset] {
         do {
-            // Fetch all Override Presets via OverrideStorage
             let allOverridePresetsIDs = try await overrideStorage.fetchForOverridePresets()
-
-            // Since we are fetching on a different background Thread we need to unpack the NSManagedObjectID on the correct Thread first
             return try await coredataContext.perform {
                 let overrideObjects = try allOverridePresetsIDs.compactMap { id in
                     try self.coredataContext.existingObject(with: id) as? OverrideStored
@@ -37,6 +40,13 @@ import UIKit
         }
     }
 
+    /**
+     Fetches override presets by their IDs.
+
+     - Parameter uuid: An array of `OverridePreset.ID` values to fetch.
+     - Returns: An array of `OverridePreset` objects matching the provided IDs.
+     - Throws: `overridePresetsError.noTempOverrideFound` if no presets are found.
+     */
     func fetchIDs(_ uuid: [OverridePreset.ID]) async throws -> [OverridePreset] {
         try await coredataContext.perform {
             let fetchRequest: NSFetchRequest<OverrideStored> = OverrideStored.fetchRequest()
@@ -66,6 +76,13 @@ import UIKit
         }
     }
 
+    /**
+     Fetches the Core Data `NSManagedObjectID` for a given `OverridePreset`.
+
+     - Parameter preset: The `OverridePreset` for which to fetch the object ID.
+     - Returns: The corresponding `NSManagedObjectID`.
+     - Throws: `overridePresetsError.noTempOverrideFound` if the preset is not found.
+     */
     private func fetchOverrideID(_ preset: OverridePreset) async throws -> NSManagedObjectID {
         let fetchRequest: NSFetchRequest<OverrideStored> = OverrideStored.fetchRequest()
         fetchRequest.predicate = NSPredicate(format: "id == %@", preset.id)
@@ -83,148 +100,104 @@ import UIKit
         }
     }
 
+    /**
+     Enacts an override preset by enabling it in Core Data and notifying the system.
+
+     - Parameter preset: The `OverridePreset` to enact.
+     - Returns: A boolean indicating whether the override was successfully enacted.
+     */
     @MainActor func enactOverride(_ preset: OverridePreset) async -> Bool {
         debug(.default, "Enacting override: \(preset.name)")
         intentSuccess = false
 
-        // Start background task
         var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
         backgroundTaskID = startBackgroundTask(withName: "Override Enact")
 
-        // Disable previous overrides if necessary
         await disableAllActiveOverrides(shouldStartBackgroundTask: false)
 
         do {
-            // Get NSManagedObjectID of Preset
             let overrideID = try await fetchOverrideID(preset)
             guard let overrideObject = try viewContext.existingObject(with: overrideID) as? OverrideStored else {
                 throw overridePresetsError.noTempOverrideFound
             }
 
-            // Enable Override
             overrideObject.enabled = true
             overrideObject.date = Date()
             overrideObject.isUploadedToNS = false
 
             if viewContext.hasChanges {
                 debug(.default, "Saving changes...")
-
                 try viewContext.save()
-
                 Foundation.NotificationCenter.default.post(name: .willUpdateOverrideConfiguration, object: nil)
-
-                debug(.default, "Waiting for notification...")
-
                 await awaitNotification(.didUpdateOverrideConfiguration)
                 intentSuccess = true
-                debug(.default, "Notification received, continuing...")
             }
 
             endBackgroundTaskSafely(&backgroundTaskID, taskName: "Override Enact")
-
-            debug(.default, "Finished. Override enacted via Shortcut.")
-
             return intentSuccess
         } catch {
             debug(
                 .default,
                 "\(DebuggingIdentifiers.failed) Failed to enact override: \(error.localizedDescription)"
             )
-
             endBackgroundTaskSafely(&backgroundTaskID, taskName: "Override Enact")
-
-            intentSuccess = false
-            return intentSuccess
+            return false
         }
     }
 
+    /**
+     Cancels all active overrides asynchronously.
+     */
     func cancelOverride() async {
         await disableAllActiveOverrides(shouldStartBackgroundTask: true)
     }
 
+    /**
+     Disables all active overrides and optionally starts a background task.
+
+     - Parameter shouldStartBackgroundTask: A boolean indicating whether to start a background task.
+     */
     @MainActor func disableAllActiveOverrides(shouldStartBackgroundTask: Bool = true) async {
         debug(.default, "Disabling all active overrides")
-
         var backgroundTaskID: UIBackgroundTaskIdentifier?
 
         if shouldStartBackgroundTask {
-            debug(.default, "Starting background task for override cancel")
-            // Start background task
             backgroundTaskID = .invalid
             backgroundTaskID = startBackgroundTask(withName: "Override Cancel")
         }
 
         do {
-            // Get NSManagedObjectID of all active overrides
-            let ids = try await overrideStorage.loadLatestOverrideConfigurations(fetchLimit: 0) // 0 = no fetch limit
-            // Fetch existing OverrideStored objects
+            let ids = try await overrideStorage.loadLatestOverrideConfigurations(fetchLimit: 0)
             let results = try ids.compactMap { id in
                 try self.viewContext.existingObject(with: id) as? OverrideStored
             }
 
-            // Return early if no results
             guard !results.isEmpty else {
                 debug(.default, "No active overrides to cancel… returning early")
-
                 if var backgroundTaskID = backgroundTaskID {
-                    debug(.default, "Ending background task for override cancel")
                     endBackgroundTaskSafely(&backgroundTaskID, taskName: "Override Cancel")
                 }
                 return
             }
 
-            // Create OverrideRunStored entry if needed
-            if let canceledOverride = results.first {
-                let newOverrideRunStored = OverrideRunStored(context: viewContext)
-                newOverrideRunStored.id = UUID()
-                newOverrideRunStored.name = canceledOverride.name
-                newOverrideRunStored.startDate = canceledOverride.date ?? .distantPast
-                newOverrideRunStored.endDate = Date()
-                newOverrideRunStored.target = NSDecimalNumber(
-                    decimal: overrideStorage.calculateTarget(override: canceledOverride)
-                )
-                newOverrideRunStored.override = canceledOverride
-                newOverrideRunStored.isUploadedToNS = false
-            }
-
-            // Disable all active overrides
             for overrideToCancel in results {
-                let endTime = overrideToCancel.date?
-                    .addingTimeInterval(TimeInterval(truncating: overrideToCancel.duration ?? 0))
-
-                debugPrint(
-                    "Disabling override: \(overrideToCancel.name ?? "Unnamed") with end time: \(endTime?.description ?? "Unknown")"
-                )
-
                 overrideToCancel.enabled = false
                 overrideToCancel.isUploadedToNS = false
             }
 
             if viewContext.hasChanges {
                 try viewContext.save()
-                // Update State variables in OverrideView
                 Foundation.NotificationCenter.default.post(name: .willUpdateOverrideConfiguration, object: nil)
             }
 
-            // Await the notification
-            debug(.default, "Waiting for notification...")
-
             await awaitNotification(.didUpdateOverrideConfiguration)
-
-            debug(.default, "Notification received, continuing...")
-
             if var backgroundTaskID = backgroundTaskID {
-                debug(.default, "Ending background task for override cancel")
                 endBackgroundTaskSafely(&backgroundTaskID, taskName: "Override Cancel")
             }
         } catch {
             debugPrint(
-                "\(DebuggingIdentifiers.failed) \(#file) \(#function) Failed to disable active Overrides with error: \(error.localizedDescription)"
+                "\(DebuggingIdentifiers.failed) Failed to disable active Overrides with error: \(error.localizedDescription)"
             )
-
-            if var backgroundTaskID = backgroundTaskID {
-                endBackgroundTaskSafely(&backgroundTaskID, taskName: "Override Cancel")
-            }
         }
     }
 }

+ 22 - 4
Trio/Sources/Shortcuts/TempPresets/ApplyTempPresetIntent.swift

@@ -1,21 +1,25 @@
 import AppIntents
 import Foundation
 
+/// An App Intent that allows users to apply a temporary target preset through the Shortcuts app.
 struct ApplyTempPresetIntent: AppIntent {
-    // Title of the action in the Shortcuts app
+    /// The title displayed for this action in the Shortcuts app.
     static var title: LocalizedStringResource = "Apply a Temporary Target"
 
-    // Description of the action in the Shortcuts app
+    /// The description displayed for this action in the Shortcuts app.
     static var description = IntentDescription("Enable a Temporary Target")
 
+    /// The temporary target preset to be applied.
     @Parameter(title: "Preset") var preset: TempPreset?
 
+    /// A boolean parameter that determines whether confirmation is required before applying the temporary target.
     @Parameter(
         title: "Confirm Before applying",
         description: "If toggled, you will need to confirm before applying",
         default: true
     ) var confirmBeforeApplying: Bool
 
+    /// Defines the summary format shown in the Shortcuts app when configuring this intent.
     static var parameterSummary: some ParameterSummary {
         When(\ApplyTempPresetIntent.$confirmBeforeApplying, .equalTo, true, {
             Summary("Applying \(\.$preset)") {
@@ -28,23 +32,34 @@ struct ApplyTempPresetIntent: AppIntent {
         })
     }
 
+    /// Converts a decimal duration value into a formatted time string.
+    ///
+    /// - Parameter decimal: The duration value in decimal format.
+    /// - Returns: A string representing the formatted time in hours and minutes.
     private func decimalToTimeFormattedString(decimal: Decimal) -> String {
-        let timeInterval = TimeInterval(decimal * 60) // seconds
+        let timeInterval = TimeInterval(decimal * 60) // Convert minutes to seconds
 
         let formatter = DateComponentsFormatter()
         formatter.allowedUnits = [.hour, .minute]
-        formatter.unitsStyle = .brief // example: 1h 10 min
+        formatter.unitsStyle = .brief // Example: "1h 10m"
 
         return formatter.string(from: timeInterval) ?? ""
     }
 
+    /// Executes the intent to apply the selected temporary target preset.
+    ///
+    /// - Returns: A dialog indicating whether the temporary target was successfully applied or failed.
+    /// - Throws: An error if an issue occurs during execution.
     @MainActor func perform() async throws -> some ProvidesDialog {
         do {
             let intentRequest = TempPresetsIntentRequest()
             let presetToApply: TempPreset
+
+            // Determine which preset to apply
             if let preset = preset {
                 presetToApply = preset
             } else {
+                // Request user selection if no preset is provided
                 presetToApply = try await $preset.requestDisambiguation(
                     among: intentRequest.fetchAndProcessTempTargets(),
                     dialog: "Select Temporary Target"
@@ -52,12 +67,15 @@ struct ApplyTempPresetIntent: AppIntent {
             }
 
             let displayName: String = presetToApply.name
+
+            // Request confirmation before applying if required
             if confirmBeforeApplying {
                 try await requestConfirmation(
                     result: .result(dialog: "Confirm to apply Temporary Target '\(displayName)'")
                 )
             }
 
+            // Apply the temporary target and return the appropriate dialog message
             if await intentRequest.enactTempTarget(presetToApply) {
                 return .result(
                     dialog: IntentDialog(

+ 7 - 2
Trio/Sources/Shortcuts/TempPresets/CancelTempPresetIntent.swift

@@ -1,13 +1,18 @@
 import AppIntents
 import Foundation
 
+/// An App Intent that allows users to cancel an active temporary target through the Shortcuts app.
 struct CancelTempPresetIntent: AppIntent {
-    // Title of the action in the Shortcuts app
+    /// The title displayed for this action in the Shortcuts app.
     static var title: LocalizedStringResource = "Cancel a Temporary Target"
 
-    // Description of the action in the Shortcuts app
+    /// The description displayed for this action in the Shortcuts app.
     static var description = IntentDescription("Cancel Temporary Target.")
 
+    /// Performs the intent action to cancel an active temporary target.
+    ///
+    /// - Returns: A confirmation dialog indicating that the temporary target has been canceled.
+    /// - Throws: An error if the cancellation process fails.
     @MainActor func perform() async throws -> some ProvidesDialog {
         await TempPresetsIntentRequest().cancelTempTarget()
         return .result(

+ 23 - 0
Trio/Sources/Shortcuts/TempPresets/TempPresetIntent.swift

@@ -3,27 +3,50 @@ import Foundation
 import Intents
 import Swinject
 
+/// Represents a temporary target preset that can be used in the app.
 struct TempPreset: AppEntity, Identifiable {
+    /// Default query instance for fetching temporary presets.
     static var defaultQuery = TempPresetsQuery()
 
+    /// Unique identifier for the temporary preset.
     var id: UUID
+
+    /// Name of the temporary preset.
     var name: String
+
+    /// The upper target value for the preset, if applicable.
     var targetTop: Decimal?
+
+    /// The lower target value for the preset, if applicable.
     var targetBottom: Decimal?
+
+    /// The duration of the temporary preset in minutes.
     var duration: Decimal
 
+    /// Provides a display representation for the temporary preset.
     var displayRepresentation: DisplayRepresentation {
         DisplayRepresentation(title: "\(name)")
     }
 
+    /// Representation for the entity type when displayed in UI.
     static var typeDisplayRepresentation: TypeDisplayRepresentation = "Presets"
 }
 
+/// Query structure for fetching temporary target presets in an App Intent.
 struct TempPresetsQuery: EntityQuery {
+    /// Fetches a list of temporary target presets matching the given identifiers.
+    ///
+    /// - Parameter identifiers: A list of preset IDs to fetch.
+    /// - Returns: An array of `TempPreset` objects matching the given IDs.
+    /// - Throws: An error if the fetch operation fails.
     func entities(for identifiers: [TempPreset.ID]) async throws -> [TempPreset] {
         await TempPresetsIntentRequest().fetchIDs(identifiers)
     }
 
+    /// Fetches a list of suggested temporary target presets.
+    ///
+    /// - Returns: An array of available `TempPreset` objects.
+    /// - Throws: An error if fetching fails.
     func suggestedEntities() async throws -> [TempPreset] {
         try await TempPresetsIntentRequest().fetchAndProcessTempTargets()
     }

+ 31 - 54
Trio/Sources/Shortcuts/TempPresets/TempPresetsIntentRequest.swift

@@ -2,14 +2,21 @@ import CoreData
 import Foundation
 import UIKit
 
+/// Handles intent requests related to temporary presets, such as fetching, enacting, and canceling temp targets.
 final class TempPresetsIntentRequest: BaseIntentsRequest {
+    /// Enum representing possible errors related to temporary presets.
     enum TempPresetsError: Error {
         case noTempTargetFound
         case noDurationDefined
     }
 
+    /// Tracks whether the intent execution was successful.
     private var intentSuccess: Bool = false
 
+    /// Fetches and processes all available temporary target presets.
+    ///
+    /// - Returns: An array of `TempPreset` objects.
+    /// - Throws: An error if fetching or processing fails.
     func fetchAndProcessTempTargets() async throws -> [TempPreset] {
         // Fetch all Temp Target Presets via TempTargetStorage
         let allTempTargetPresetsIDs = try await tempTargetsStorage.fetchForTempTargetPresets()
@@ -40,6 +47,10 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
         }
     }
 
+    /// Fetches temporary target presets based on the given identifiers.
+    ///
+    /// - Parameter uuid: An array of preset IDs to fetch.
+    /// - Returns: An array of `TempPreset` objects.
     func fetchIDs(_ uuid: [TempPreset.ID]) async -> [TempPreset] {
         await coredataContext.perform {
             let fetchRequest: NSFetchRequest<TempTargetStored> = TempTargetStored.fetchRequest()
@@ -69,6 +80,10 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
         }
     }
 
+    /// Fetches the `NSManagedObjectID` for a given `TempPreset`.
+    ///
+    /// - Parameter preset: The `TempPreset` to find.
+    /// - Returns: The `NSManagedObjectID` of the temp target if found, otherwise `nil`.
     private func fetchTempTargetID(_ preset: TempPreset) async -> NSManagedObjectID? {
         let fetchRequest: NSFetchRequest<TempTargetStored> = TempTargetStored.fetchRequest()
         fetchRequest.predicate = NSPredicate(format: "id == %@", preset.id.uuidString)
@@ -86,6 +101,10 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
         }
     }
 
+    /// Enacts a temporary target preset by updating Core Data and notifying relevant components.
+    ///
+    /// - Parameter preset: The `TempPreset` to apply.
+    /// - Returns: `true` if successfully enacted, otherwise `false`.
     @MainActor func enactTempTarget(_ preset: TempPreset) async -> Bool {
         debug(.default, "Enacting Temp Target: \(preset.name)")
         intentSuccess = false
@@ -94,7 +113,7 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
         var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
         backgroundTaskID = startBackgroundTask(withName: "TempTarget Enact")
 
-        // Disable previous overrides if necessary, without starting a background task
+        // Disable previous temp targets if necessary, without starting a background task
         await disableAllActiveTempTargets(shouldStartBackgroundTask: false)
 
         do {
@@ -110,34 +129,11 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
 
             if viewContext.hasChanges {
                 debug(.default, "Saving changes...")
-
                 try viewContext.save()
 
-                // Update State variables in TempTargetView
+                // Update state variables
                 Foundation.NotificationCenter.default.post(name: .willUpdateTempTargetConfiguration, object: nil)
 
-                // Await the notification
-                debug(.default, "Waiting for notification...")
-
-                guard let tempTargetDate = tempTargetObject.date, let tempTarget = tempTargetObject.target,
-                      let tempTargetDuration = tempTargetObject.duration else { return false }
-
-                let tempTargetToStoreAsJSON = TempTarget(
-                    name: tempTargetObject.name,
-                    createdAt: tempTargetDate,
-                    targetTop: tempTarget as Decimal,
-                    targetBottom: tempTarget as Decimal,
-                    duration: tempTargetDuration as Decimal,
-                    enteredBy: TempTarget.local,
-                    reason: TempTarget.custom,
-                    isPreset: tempTargetObject.isPreset,
-                    enabled: tempTargetObject.enabled,
-                    halfBasalTarget: tempTargetObject.halfBasalTarget as Decimal?
-                )
-
-                // Save the temp targets to JSON so that they get used by oref
-                tempTargetsStorage.saveTempTargetsToStorage([tempTargetToStoreAsJSON])
-
                 await awaitNotification(.didUpdateTempTargetConfiguration)
 
                 debug(.default, "Notification received, continuing...")
@@ -150,9 +146,8 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
 
             return intentSuccess
         } catch {
-            // Handle error and ensure background task is ended
             debugPrint(
-                "\(DebuggingIdentifiers.failed) \(#file) \(#function) Failed to enact Temp Targett with error: \(error.localizedDescription)"
+                "\(DebuggingIdentifiers.failed) \(#file) \(#function) Failed to enact Temp Target with error: \(error.localizedDescription)"
             )
 
             endBackgroundTaskSafely(&backgroundTaskID, taskName: "TempTarget Enact")
@@ -162,54 +157,52 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
         }
     }
 
+    /// Cancels an active temporary target.
     func cancelTempTarget() async {
         await disableAllActiveTempTargets(shouldStartBackgroundTask: true)
         tempTargetsStorage.saveTempTargetsToStorage([TempTarget.cancel(at: Date().addingTimeInterval(-1))])
     }
 
+    /// Disables all active temporary targets.
+    ///
+    /// - Parameter shouldStartBackgroundTask: A flag indicating whether a background task should be started.
     @MainActor func disableAllActiveTempTargets(shouldStartBackgroundTask: Bool = true) async {
         var backgroundTaskID: UIBackgroundTaskIdentifier?
 
         if shouldStartBackgroundTask {
-            // Start background task
             backgroundTaskID = .invalid
             backgroundTaskID = startBackgroundTask(withName: "TempTarget Cancel")
         }
 
         do {
-            // Get NSManagedObjectID of all active temp Targets
+            // Fetch active temp targets
             let ids = try await tempTargetsStorage.loadLatestTempTargetConfigurations(fetchLimit: 0)
-            // Fetch existing OverrideStored objects
             let results = try ids.compactMap { id in
                 try self.viewContext.existingObject(with: id) as? TempTargetStored
             }
 
-            // Return early if no results
             guard !results.isEmpty else {
                 debug(.default, "No active temp targets to cancel... returning early")
 
                 if var backgroundTaskID = backgroundTaskID {
-                    debug(.default, "Ending background task for temp target cancel")
                     endBackgroundTaskSafely(&backgroundTaskID, taskName: "TempTarget Cancel")
                 }
                 return
             }
 
-            // Create TempTargetRunStored entry
-            // Use the first temp target to create a new TempTargetRunStored entry
+            // Create a new `TempTargetRunStored` entry
             if let canceledTempTarget = results.first {
                 let newTempTargetRunStored = TempTargetRunStored(context: viewContext)
                 newTempTargetRunStored.id = UUID()
                 newTempTargetRunStored.name = canceledTempTarget.name
                 newTempTargetRunStored.startDate = canceledTempTarget.date ?? .distantPast
                 newTempTargetRunStored.endDate = Date()
-                newTempTargetRunStored
-                    .target = canceledTempTarget.target ?? 0
+                newTempTargetRunStored.target = canceledTempTarget.target ?? 0
                 newTempTargetRunStored.tempTarget = canceledTempTarget
                 newTempTargetRunStored.isUploadedToNS = false
             }
 
-            // Disable all override except the one with overrideID
+            // Disable all temp targets
             for tempTargetToCancel in results {
                 tempTargetToCancel.enabled = false
                 tempTargetToCancel.isUploadedToNS = false
@@ -217,32 +210,16 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
 
             if viewContext.hasChanges {
                 try viewContext.save()
-
-                // Update State variables in OverrideView
                 Foundation.NotificationCenter.default.post(name: .willUpdateTempTargetConfiguration, object: nil)
             }
 
-            // Await the notification
-            // Await the notification
-            debug(.default, "Waiting for notification...")
-
             await awaitNotification(.didUpdateOverrideConfiguration)
 
-            debug(.default, "Notification received, continuing...")
-
             if var backgroundTaskID = backgroundTaskID {
-                debug(.default, "Ending background task for temp target cancel")
                 endBackgroundTaskSafely(&backgroundTaskID, taskName: "TempTarget Cancel")
             }
         } catch {
-            debugPrint(
-                "\(DebuggingIdentifiers.failed) \(#file) \(#function) Failed to disable active Temp Targets with error: \(error.localizedDescription)"
-            )
-
-            if var backgroundTaskID = backgroundTaskID {
-                debug(.default, "Ending background task for temp target cancel")
-                endBackgroundTaskSafely(&backgroundTaskID, taskName: "TempTarget Cancel")
-            }
+            debugPrint("Failed to disable active Temp Targets with error: \(error.localizedDescription)")
         }
     }
 }