mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-11-05 09:08:15 +00:00
Initial code for user supplied confirmation messages (#307)
Hopefully a simple change to the code. This is on top of #306.
This commit is contained in:
@@ -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. |
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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.**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user