Preserve tap action data for numeric picker actions

Pass tap_action.data into numeric menu items and merge it with the selected picker value before calling the Home Assistant service.
This commit is contained in:
StumblingGamer
2026-06-22 11:03:23 -04:00
parent 2fb59d2a56
commit b1fb5d9417
3 changed files with 21 additions and 7 deletions

View File

@@ -163,6 +163,7 @@ class HomeAssistantMenuItemFactory {
entity_id as Lang.String?,
template as Lang.String?,
action as Lang.String?,
data as Lang.Dictionary?,
picker as Lang.Dictionary,
options as {
:exit as Lang.Boolean,
@@ -171,9 +172,12 @@ class HomeAssistantMenuItemFactory {
:icon as WatchUi.Bitmap
}
) as WatchUi.MenuItem {
var data = null;
if (entity_id != null) {
data = { "entity_id" => entity_id };
if (data == null) {
data = { "entity_id" => entity_id };
} else {
data["entity_id"] = entity_id;
}
}
var keys = mMenuItemOptions.keys();
for (var i = 0; i < keys.size(); i++) {

View File

@@ -155,7 +155,10 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
//
function onConfirm(b as Lang.Boolean) as Void {
var dataAttribute = mPicker["data_attribute"] as Lang.String?;
var entity_id = mData["entity_id"] as Lang.String?;
var entity_id = null as Lang.String?;
if (mData != null) {
entity_id = mData["entity_id"] as Lang.String?;
}
WatchUi.popView(WatchUi.SLIDE_RIGHT);
WatchUi.requestUpdate();
@@ -164,12 +167,18 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
return;
}
if (mAction != null) {
var data = {} as Lang.Dictionary;
if (mData != null) {
var keys = mData.keys();
for (var i = 0; i < keys.size(); i++) {
data[keys[i]] = mData[keys[i]];
}
}
data["entity_id"] = entity_id.toString();
data[dataAttribute.toString()] = mValue;
mHomeAssistantService.call(
mAction,
{
"entity_id" => entity_id.toString(),
dataAttribute.toString() => mValue
},
data,
mExit
);
}

View File

@@ -141,6 +141,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
entity,
content,
action,
data,
picker,
{
:exit => exit,