From 4e90fa82ba1f5e12f653dfb2755c3b1143d9da92 Mon Sep 17 00:00:00 2001 From: olorinmaia <114103483+olorinmaia@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:23:10 -0700 Subject: [PATCH 1/2] Automation triggers: a pick in the editor is shown at once The Bluetooth device, temp target, time and WiFi trigger editors did not get the tick that the other editors use to redraw. After a pick the value was stored in the trigger, but the screen kept the old text, so it looked like the pick was lost. The Bluetooth device field also showed the first paired device when nothing was stored. A user who did not open the list saved a trigger with an empty device name, which never fires. The field is now empty until the user picks a device. Fixes #5550 --- .../compose/triggers/TriggerEditors.kt | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/triggers/TriggerEditors.kt b/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/triggers/TriggerEditors.kt index 1eafaac2c302..9ffa33a2fa96 100644 --- a/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/triggers/TriggerEditors.kt +++ b/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/triggers/TriggerEditors.kt @@ -92,14 +92,14 @@ fun TriggerEditor( is TriggerPodChange -> TriggerPodChangeEditor() is TriggerPumpLastConnection -> TriggerPumpLastConnectionEditor(trigger, onChange, tick) is TriggerProfilePercent -> TriggerProfilePercentEditor(trigger, onChange, tick) - is TriggerTempTarget -> TriggerTempTargetEditor(trigger, onChange) + is TriggerTempTarget -> TriggerTempTargetEditor(trigger, onChange, tick) is TriggerTempTargetValue -> TriggerTempTargetValueEditor(trigger, onChange, tick) is TriggerStepsCount -> TriggerStepsCountEditor(trigger, onChange, tick) - is TriggerTime -> TriggerTimeEditor(trigger, onChange) + is TriggerTime -> TriggerTimeEditor(trigger, onChange, tick) is TriggerRecurringTime -> TriggerRecurringTimeEditor(trigger, onChange) is TriggerTimeRange -> TriggerTimeRangeEditor(trigger, onChange) - is TriggerWifiSsid -> TriggerWifiSsidEditor(trigger, onChange) - is TriggerBTDevice -> TriggerBTDeviceEditor(trigger, bondedDevices, onChange) + is TriggerWifiSsid -> TriggerWifiSsidEditor(trigger, onChange, tick) + is TriggerBTDevice -> TriggerBTDeviceEditor(trigger, bondedDevices, onChange, tick) is TriggerLocation -> TriggerLocationEditor(trigger, onChange, tick, onUseCurrentLocation, onPickLocationFromMap) is TriggerConnector -> Text("Connector") is TriggerUnknown -> Text(trigger.friendlyDescription()) @@ -437,7 +437,8 @@ fun TriggerProfilePercentEditor(t: TriggerProfilePercent, onChange: () -> Unit, } @Composable -fun TriggerTempTargetEditor(t: TriggerTempTarget, onChange: () -> Unit) { +fun TriggerTempTargetEditor(t: TriggerTempTarget, onChange: () -> Unit, tick: Int = 0) { + @Suppress("UNUSED_EXPRESSION") tick ComparatorExistsEditor(t.comparator.value, onValueChange = { t.comparator.value = it; onChange() }) } @@ -495,7 +496,8 @@ fun TriggerStepsCountEditor(t: TriggerStepsCount, onChange: () -> Unit, tick: In } @Composable -fun TriggerTimeEditor(t: TriggerTime, onChange: () -> Unit) { +fun TriggerTimeEditor(t: TriggerTime, onChange: () -> Unit, tick: Int = 0) { + @Suppress("UNUSED_EXPRESSION") tick InputDateTimeEditor(timeMillis = t.time.value, onChange = { t.time.value = it; onChange() }) } @@ -519,22 +521,29 @@ fun TriggerTimeRangeEditor(t: TriggerTimeRange, onChange: () -> Unit) { } @Composable -fun TriggerWifiSsidEditor(t: TriggerWifiSsid, onChange: () -> Unit) = CompareRow( - comparator = t.comparator.value, - onComparatorChange = { t.comparator.value = it; onChange() }, - label = "" -) { - InputStringEditor(value = t.ssid.value, onValueChange = { t.ssid.value = it; onChange() }) +fun TriggerWifiSsidEditor(t: TriggerWifiSsid, onChange: () -> Unit, tick: Int = 0) { + @Suppress("UNUSED_EXPRESSION") tick + CompareRow( + comparator = t.comparator.value, + onComparatorChange = { t.comparator.value = it; onChange() }, + label = "" + ) { + InputStringEditor(value = t.ssid.value, onValueChange = { t.ssid.value = it; onChange() }) + } } @Composable fun TriggerBTDeviceEditor( t: TriggerBTDevice, bondedDevices: List, - onChange: () -> Unit + onChange: () -> Unit, + tick: Int = 0 ) { + @Suppress("UNUSED_EXPRESSION") tick + // No fallback to the first paired device: the field must show what is stored. An empty field + // tells the user that no device is picked yet. AutomationDropdown( - value = t.btDevice.value.ifEmpty { bondedDevices.firstOrNull() ?: "" }, + value = t.btDevice.value, options = bondedDevices, onValueChange = { t.btDevice.setValue(it); onChange() } ) From 6449c7746017e701cfadd3d6b36681e5859fd86d Mon Sep 17 00:00:00 2001 From: olorinmaia <114103483+olorinmaia@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:23:11 -0700 Subject: [PATCH 2/2] Automation time trigger: the picked date is not moved by the time zone The date picker gives and takes a day as midnight UTC. The editor read the pick in the local zone and gave the picker the raw trigger time. West of UTC the stored date was one day too early. The picker could also open on the wrong day, for example in the first hour after midnight in Norway. The pick is now read in UTC, and the picker gets the local date as midnight UTC. The time of day is untouched. --- .../automation/compose/elements/TimeElements.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/elements/TimeElements.kt b/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/elements/TimeElements.kt index 424e8d1dddb2..d272ece5d023 100644 --- a/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/elements/TimeElements.kt +++ b/plugins/automation/src/commonMain/kotlin/app/aaps/plugins/automation/compose/elements/TimeElements.kt @@ -117,15 +117,19 @@ fun InputDateTimeEditor( } } if (showDate) { - val dpState = rememberDatePickerState(initialSelectedDateMillis = timeMillis) + // The date picker works in UTC: a day is given and returned as midnight UTC of that day. + // So the local date goes in as midnight UTC, and the pick is read back in UTC. Reading or + // writing it in the local zone moves the date by one day west of UTC. + val dpState = rememberDatePickerState( + initialSelectedDateMillis = LocalDateTime(local.date, LocalTime(0, 0)).toInstant(TimeZone.UTC).toEpochMilliseconds() + ) DatePickerDialog( onDismissRequest = { showDate = false }, confirmButton = { TextButton(onClick = { dpState.selectedDateMillis?.let { sel -> - // Read back in the same zone the display uses, so the day the user tapped is the - // day that gets stored. Keeps the time of day untouched. - val pickedDate = Instant.fromEpochMilliseconds(sel).toLocalDateTime(zone).date + // The day the user tapped, joined with the local time of day, which stays untouched. + val pickedDate = Instant.fromEpochMilliseconds(sel).toLocalDateTime(TimeZone.UTC).date onChange(LocalDateTime(pickedDate, local.time).toInstant(zone).toEpochMilliseconds()) } showDate = false