Refactor HomeAssistantNumericPicker for improved value parsing (#345)

ref
https://github.com/house-of-abbey/GarminHomeAssistant/issues/238#issuecomment-3941469731

fix numberpicker issue
refactored with Amazon Q
tested on Vivoactive 5 (simulator and device)
tested on Venu2 (simulator only)
This commit is contained in:
Philip Abbey
2026-03-01 08:24:58 +00:00
committed by GitHub
2 changed files with 14 additions and 10 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ Thumbs.db
source/ClientId.mc
# Gemini API key for automated translations
gemini_api_key.txt
developer_key

View File

@@ -32,24 +32,27 @@ class HomeAssistantNumericPicker extends WatchUi.Picker {
) {
mItem = haItem;
var picker = mItem.getPicker();
var min = (picker.get("min") as Lang.String).toFloat();
var step = (picker.get("step") as Lang.String).toFloat();
var minStr = picker.get("min");
var stepStr = picker.get("step");
var val = haItem.getValue();
if (min == null) {
min = 0.0;
var min = 0.0;
var step = 1.0;
if (minStr != null) {
min = (minStr as Lang.String).toFloat();
}
if (step == null) {
step = 1.0;
if (stepStr != null) {
step = (stepStr as Lang.String).toFloat();
}
WatchUi.Picker.initialize({
:title => new WatchUi.Text({
:title => new WatchUi.Text({
:text => haItem.getLabel(),
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
:locY => WatchUi.LAYOUT_VALIGN_BOTTOM
}),
:pattern => [factory],
:pattern => [factory],
:defaults => [((val - min) / step).toNumber()]
});
}
@@ -95,4 +98,4 @@ class HomeAssistantNumericPickerDelegate extends WatchUi.PickerDelegate {
mPicker.onConfirm(values[0]);
return true;
}
}
}