Skip to content

Commit

Permalink
Merge pull request #95 from kylmcw/temp-target-duration-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kylmcw authored Apr 14, 2024
2 parents 23e711a + 19490ec commit 2656373
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Um einen NIEDRIGEN BZ zu verhindern, werden %d g Kohlenhydrate benötigt";

/* */
"iAPS not active" = "iAPS ist nicht aktiv";
"Open-iAPS Not Active" = "Open-iAPS ist nicht aktiv";

/* */
"Last loop was more than %d min ago" = "Letzter Loop vor mehr als %d Minuten";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Pour éviter BAS %d g de glucides requis";

/* */
"iAPS not active" = "iAPS pas actif";
"Open-iAPS Not Active" = "Open-iAPS pas actif";

/* */
"Last loop was more than %d min ago" = "Dernier bouclage depuis plus de %d min";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Per evitare glicemia BASSA servono %d g di carboidrati";

/* */
"iAPS not active" = "iAPS non attivo";
"Open-iAPS Not Active" = "Open-iAPS non attivo";

/* */
"Last loop was more than %d min ago" = "L'ultimo ciclo è stato più di %d min fa";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "For å forhindre lavt blodsukker: %d g karbo nødvendig";

/* */
"iAPS not active" = "iAPS ikke aktiv";
"Open-iAPS Not Active" = "Open-iAPS ikke aktiv";

/* */
"Last loop was more than %d min ago" = "Siste loop var mer enn %d min siden";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Om LAAG te voorkomen zijn %d g koolhydraten nodig";

/* */
"iAPS not active" = "iAPS is niet actief!";
"Open-iAPS Not Active" = "Open-iAPS is niet actief!";

/* */
"Last loop was more than %d min ago" = "Laatste loop was meer dan %d min geleden";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ Połączono z Nightscout!";
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "To prevent LOW required %d g of carbs";

/* */
"iAPS not active" = "iAPS not active";
"Open-iAPS Not Active" = "Open-iAPS Not Active";

/* */
"Last loop was more than %d min ago" = "Last loop was more than %d min ago";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Для избежания ГИПО необходимо %d г углеводов";

/* */
"iAPS not active" = "iAPS неактивен";
"Open-iAPS Not Active" = "Open-iAPS неактивен";

/* */
"Last loop was more than %d min ago" = "Последний цикл был более %d минут назад";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Na zabránenie NÍZKY potrebných %d g sacharidov";

/* */
"iAPS not active" = "iAPS nie je aktívny";
"Open-iAPS Not Active" = "Open-iAPS nie je aktívny";

/* */
"Last loop was more than %d min ago" = "Posledná slučka bola pred viac ako %d min";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "För att förhindra ett lågt blodsocker krävs uppskattningsvis %d g kolhydrater";

/* */
"iAPS not active" = "iAPS är inte aktiv";
"Open-iAPS Not Active" = "Open-iAPS är inte aktiv";

/* */
"Last loop was more than %d min ago" = "Senaste loop var för mer än %d min sedan";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "DÜŞÜK KŞ'ini önlemek için gerekli Karbonhidrat %d g";

/* */
"iAPS not active" = "iAPS etkin değil";
"Open-iAPS Not Active" = "Open-iAPS etkin değil";

/* */
"Last loop was more than %d min ago" = "Son döngü %d dak kadar önceydi";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Для запобігання ГІПО потрібно %d g вуглеводів";

/* */
"iAPS not active" = "iAPS не активний";
"Open-iAPS Not Active" = "Open-iAPS не активний";

/* */
"Last loop was more than %d min ago" = "Останній цикл був більше, ніж %d хв тому";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "Để hạn chế LOW yêu cầu %d g carbs";

/* */
"iAPS not active" = "iAPS chưa hoạt động";
"Open-iAPS Not Active" = "Open-iAPS chưa hoạt động";

/* */
"Last loop was more than %d min ago" = "Loop dừng hoạt động hơn %d phút trước";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ Enact a temp Basal or a temp target */
"To prevent LOW required %d g of carbs" = "为了防止低血糖, 需要%d 克碳水";

/* */
"iAPS not active" = "iAPS 未激活";
"Open-iAPS Not Active" = "Open-iAPS 未激活";

/* */
"Last loop was more than %d min ago" = "上次闭环成功在 %d 分钟前";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In

private func scheduleMissingLoopNotifiactions(date _: Date) {
ensureCanSendNotification {
let title = NSLocalizedString("iAPS not active", comment: "iAPS not active")
let body = NSLocalizedString("Last loop was more then %d min ago", comment: "Last loop was more then %d min ago")
let title = NSLocalizedString("Open-iAPS Not Active", comment: "Open-iAPS Not Active")
let body = NSLocalizedString("Last loop was more than %d min ago", comment: "Last loop was more than %d min ago")

let firstInterval = 20 // min
let secondInterval = 40 // min
Expand Down
2 changes: 1 addition & 1 deletion FreeAPS/Sources/Shortcuts/State/ListStateIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
)

static var parameterSummary: some ParameterSummary {
Summary("List all states of iAPS")
Summary("List all states of Open-iAPS")
}

@MainActor func perform() async throws -> some ReturnsValue<StateiAPSResults> & ShowsSnippetView {
Expand Down
21 changes: 16 additions & 5 deletions FreeAPS/Sources/Shortcuts/TempPresets/ApplyTempPresetIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation

@available(iOS 16.0, *) struct ApplyTempPresetIntent: AppIntent {
// Title of the action in the Shortcuts app
static var title: LocalizedStringResource = "Apply a temporary Preset"
static var title: LocalizedStringResource = "Apply a temporary target"

// Description of the action in the Shortcuts app
static var description = IntentDescription("Allow to apply a specific temporary preset.")
static var description = IntentDescription("Enable a temporary target")

internal var intentRequest: TempPresetsIntentRequest

Expand Down Expand Up @@ -34,6 +34,16 @@ import Foundation
})
}

private func decimalToTimeFormattedString(decimal: Decimal) -> String {
let timeInterval = TimeInterval(decimal * 60) // seconds

let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
formatter.unitsStyle = .brief // example: 1h 10 min

return formatter.string(from: timeInterval) ?? ""
}

@MainActor func perform() async throws -> some ProvidesDialog {
do {
let presetToApply: tempPreset
Expand All @@ -42,22 +52,23 @@ import Foundation
} else {
presetToApply = try await $preset.requestDisambiguation(
among: intentRequest.fetchAll(),
dialog: "What temp preset would you like ?"
dialog: "Select Temporary Target"
)
}

let displayName: String = presetToApply.name
if confirmBeforeApplying {
try await requestConfirmation(
result: .result(dialog: "Are you sure to applying the temp target \(displayName) ?")
result: .result(dialog: "Confirm to apply temporary target '\(displayName)'")
)
}

// TODO: enact the temp target
let tempTarget = try intentRequest.findTempTarget(presetToApply)
let finalTempTargetApply = try intentRequest.enactTempTarget(tempTarget)
let formattedTime = decimalToTimeFormattedString(decimal: finalTempTargetApply.duration)
let displayDetail: String =
"the target \(finalTempTargetApply.displayName) is applying during \(finalTempTargetApply.duration) mn"
"Target '\(finalTempTargetApply.displayName)' applied for \(formattedTime)"
return .result(
dialog: IntentDialog(stringLiteral: displayDetail)
)
Expand Down

0 comments on commit 2656373

Please sign in to comment.