From fc0320aef6abf3dc4a1e5042599d1d3766a15424 Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Thu, 30 Oct 2025 17:50:04 +0000 Subject: [PATCH] Initial code for user supplied confirmation messages --- HISTORY.md | 2 +- README.md | 1 + config.schema.json | 4 ++-- examples/Actions.md | 8 ++++++++ source/HomeAssistantConfirmation.mc | 9 ++++++--- source/HomeAssistantNumericMenuItem.mc | 9 +++++++-- source/HomeAssistantTapMenuItem.mc | 12 ++++++++---- source/HomeAssistantToggleMenuItem.mc | 9 +++++++-- source/HomeAssistantView.mc | 2 +- 9 files changed, 41 insertions(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 78897e8..d43e3af 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -51,4 +51,4 @@ | 3.3 | Providing automatic detection for menu definition updates, but still requires an application restart. | | 3.4 | Fixed a bug where templates failed to display in toggle menu items (at least on some devices). Fixed a bug where a menu item requesting to exit on completion appeared to indicate failure when using Wi-Fi or LTE. The fix uses a delay in exiting the application modelled as sufficient for a Venu 2 device, so this might need tweaking for other devices. Attempt to fixed an "Out of Memory" bug caused by v3.3 by making automatic checking for menu updates both optional and automatically turned off when insufficient memory is available. This last bug is device dependent and may require another attempt. Internationalisation improvements with thanks to [@krzys_h](https://github.com/krzys-h) for a new automated translations script. | | 3.5 | Added support for Edge 550, 850 & MTB, Fenix 8 Pro 47mm, GPSMAP H1, Instinct Crossover AMOLED, Venu 4 41mm & 45mm, & Venu X1 devices which also required an SDK update to 8.3.0. The simulation of the Edge 850 device was off, as it failed to update the display and text was the wrong colour, but the buttons menu items operated HA correctly. The assumption is the simulation model is buggy until someone [reports](https://github.com/house-of-abbey/GarminHomeAssistant/issues) otherwise. | -| 3.6 | Added `numeric` menu item type thanks to [@thmichel](https://github.com/thmichel). This allows you to select a numeric value to set for an entity. | +| 3.6 | Added `numeric` menu item type thanks to [@thmichel](https://github.com/thmichel). This allows you to select a numeric value to set for an entity. Confirmations can now display a user supplied message. | diff --git a/README.md b/README.md index 2a9a5cb..5eabb97 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,7 @@ This allows the `confirm` and `pin` fields to be accommodated in the `tap_action * [Switches](examples/Switches.md) * [Actions](examples/Actions.md) * [Templates](examples/Templates.md) +* [Numeric](examples/Numeric.md) ## Editing the JSON file diff --git a/config.schema.json b/config.schema.json index a696066..b49c1ac 100644 --- a/config.schema.json +++ b/config.schema.json @@ -845,10 +845,10 @@ "type": "string" }, "confirm": { - "type": "boolean", + "type": ["boolean", "string"], "default": false, "title": "Confirmation", - "description": "Optional confirmation of the action before execution as a precaution." + "description": "Optional confirmation of the action before execution as a precaution. Use a Boolean for the default message. Specify a string to display a specific confirmation message." }, "pin": { "type": "boolean", diff --git a/examples/Actions.md b/examples/Actions.md index 822d46c..6a25c15 100644 --- a/examples/Actions.md +++ b/examples/Actions.md @@ -37,6 +37,14 @@ For example: "confirm": true } } + +``` +The `confirm` field may contain a string instead of a Boolean in order to provide a custom message to display instead of the default "Sure?" text. + +```json + "tap_action": { + "confirm": "Toggle the cover?" + } ``` **The authors do not advise the use of this application for security sensitive devices. But we suspect users are taking that risk anyway, hence a PIN confirmation is provided that can be used for additional menu item security.** diff --git a/source/HomeAssistantConfirmation.mc b/source/HomeAssistantConfirmation.mc index 2eac1e8..fb261f8 100644 --- a/source/HomeAssistantConfirmation.mc +++ b/source/HomeAssistantConfirmation.mc @@ -24,10 +24,13 @@ class HomeAssistantConfirmation extends WatchUi.Confirmation { //! Class Constructor // - function initialize() { - WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm) as Lang.String); + function initialize(message as Lang.String?) { + if (message == null) { + WatchUi.Confirmation.initialize(WatchUi.loadResource($.Rez.Strings.Confirm) as Lang.String); + } else { + WatchUi.Confirmation.initialize(message); + } } - } //! Delegate to respond to the confirmation request. diff --git a/source/HomeAssistantNumericMenuItem.mc b/source/HomeAssistantNumericMenuItem.mc index 06a298f..c26c8e8 100644 --- a/source/HomeAssistantNumericMenuItem.mc +++ b/source/HomeAssistantNumericMenuItem.mc @@ -23,7 +23,7 @@ using Toybox.Graphics; class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem { private var mHomeAssistantService as HomeAssistantService?; private var mService as Lang.String?; - private var mConfirm as Lang.Boolean; + private var mConfirm as Lang.Boolean or Lang.String or Null; private var mExit as Lang.Boolean; private var mPin as Lang.Boolean; private var mData as Lang.Dictionary?; @@ -127,7 +127,12 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem { WatchUi.SLIDE_LEFT ); } else { - var view = new HomeAssistantConfirmation(); + var view; + if (mConfirm instanceof Lang.String) { + view = new HomeAssistantConfirmation(mConfirm as Lang.String?); + } else { + view = new HomeAssistantConfirmation(null); + } WatchUi.pushView( view, new HomeAssistantConfirmationDelegate({ diff --git a/source/HomeAssistantTapMenuItem.mc b/source/HomeAssistantTapMenuItem.mc index fa84e31..f718983 100644 --- a/source/HomeAssistantTapMenuItem.mc +++ b/source/HomeAssistantTapMenuItem.mc @@ -22,7 +22,7 @@ using Toybox.Graphics; class HomeAssistantTapMenuItem extends HomeAssistantMenuItem { private var mHomeAssistantService as HomeAssistantService; private var mService as Lang.String?; - private var mConfirm as Lang.Boolean; + private var mConfirm as Lang.Boolean or Lang.String or Null; private var mExit as Lang.Boolean; private var mPin as Lang.Boolean; private var mData as Lang.Dictionary?; @@ -95,8 +95,7 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem { if ((! System.getDeviceSettings().phoneConnected || ! System.getDeviceSettings().connectionAvailable) && Settings.getWifiLteExecutionEnabled()) { - var dialogMsg = WatchUi.loadResource($.Rez.Strings.WifiLtePrompt) as Lang.String; - var dialog = new WatchUi.Confirmation(dialogMsg); + var dialog = new WatchUi.Confirmation(WatchUi.loadResource($.Rez.Strings.WifiLtePrompt) as Lang.String); WatchUi.pushView( dialog, new WifiLteExecutionConfirmDelegate({ @@ -108,7 +107,12 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem { WatchUi.SLIDE_LEFT ); } else { - var view = new HomeAssistantConfirmation(); + var view; + if (mConfirm instanceof Lang.String) { + view = new HomeAssistantConfirmation(mConfirm as Lang.String?); + } else { + view = new HomeAssistantConfirmation(null); + } WatchUi.pushView( view, new HomeAssistantConfirmationDelegate({ diff --git a/source/HomeAssistantToggleMenuItem.mc b/source/HomeAssistantToggleMenuItem.mc index aeaffbe..1cdd7cc 100644 --- a/source/HomeAssistantToggleMenuItem.mc +++ b/source/HomeAssistantToggleMenuItem.mc @@ -25,7 +25,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { private var mData as Lang.Dictionary; private var mTemplate as Lang.String?; private var mExit as Lang.Boolean; - private var mConfirm as Lang.Boolean; + private var mConfirm as Lang.Boolean or Lang.String or Null; private var mPin as Lang.Boolean; private var mHasVibrate as Lang.Boolean = false; @@ -324,7 +324,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem { Settings.getWifiLteExecutionEnabled()) { wifiPrompt(b); } else { - var confirmationView = new HomeAssistantConfirmation(); + var confirmationView; + if (mConfirm instanceof Lang.String) { + confirmationView = new HomeAssistantConfirmation(mConfirm as Lang.String?); + } else { + confirmationView = new HomeAssistantConfirmation(null); + } WatchUi.pushView( confirmationView, new HomeAssistantConfirmationDelegate({ diff --git a/source/HomeAssistantView.mc b/source/HomeAssistantView.mc index 08b4141..9f68afa 100644 --- a/source/HomeAssistantView.mc +++ b/source/HomeAssistantView.mc @@ -48,7 +48,7 @@ class HomeAssistantView extends WatchUi.Menu2 { var entity = items[i].get("entity") as Lang.String?; var tap_action = items[i].get("tap_action") as Lang.Dictionary?; var service = items[i].get("service") as Lang.String?; // Deprecated schema - var confirm = false as Lang.Boolean?; + var confirm = false as Lang.Boolean or Lang.String or Null; var pin = false as Lang.Boolean?; var data = null as Lang.Dictionary?; var enabled = true as Lang.Boolean?;