Suggested code changes from philipabbey

1. attribute is option, so needs a different template in the API call when absent.
2. Automatically derive the format string from the picker step value for any precision of step.
3. Changed all Lang.String representations of numbers to Lang.Number or Lang.Float. I'm keen to remove the use of strings to hold a numeric value.
4. Tidied up and completed some code comments.
5. Adjusted the JSON schema definition. This is still not finished as the 'picker' object is required for 'numeric' menu items and must not be present for the others. Additional schema changes are required for greater precision.
6. Moved fields over from 'data' to 'picker'.
This commit is contained in:
Philip Abbey
2025-10-29 14:26:02 +00:00
parent 2cd171637c
commit a5ddb65512
8 changed files with 223 additions and 207 deletions

View File

@@ -158,7 +158,7 @@ class HomeAssistantMenuItemFactory {
entity_id as Lang.String?,
template as Lang.String?,
service as Lang.String?,
data as Lang.Dictionary?,
picker as Lang.Dictionary,
options as {
:exit as Lang.Boolean,
:confirm as Lang.Boolean,
@@ -166,25 +166,21 @@ class HomeAssistantMenuItemFactory {
:icon as WatchUi.Bitmap
}
) as WatchUi.MenuItem {
var data = null;
if (entity_id != null) {
if (data == null) {
data = { "entity_id" => entity_id };
} else {
data.put("entity_id", entity_id);
}
}
data = { "entity_id" => entity_id };
}
var keys = mMenuItemOptions.keys();
for (var i = 0; i < keys.size(); i++) {
options.put(keys[i], mMenuItemOptions.get(keys[i]));
}
options.put(:icon, mTapTypeIcon);
options.put(:icon, mTapTypeIcon);
return new HomeAssistantNumericMenuItem(
label,
template,
service,
data,
picker,
options,
mHomeAssistantService
);