Big fix for PIN enabled items on non-touchscreen devices

This commit is contained in:
Philip Abbey
2026-07-28 19:36:26 +01:00
parent f042b59932
commit 802388aac8
2 changed files with 58 additions and 57 deletions

View File

@@ -60,3 +60,4 @@
| 3.12 | Amended GPS accuracy values used by the background service. |
| 3.13 | Added support for new devices: `d2mach2pro`, `fr170`, `fr170m`, `fr70`. |
| 3.14 | Numeric items now support `tap_action.data` fields so service call options like `transition` are catered for. See the documentation on [Additional Action Data](https://github.com/house-of-abbey/GarminHomeAssistant/blob/main/examples/Numeric.md#additional-action-data). This features has been provided by [@StumblingGamer](https://github.com/StumblingGamer). Now prevent PIN enabled menu items from being enabled on non-touch screen devices. The PIN must be removed for the menu item to function. Fix for initialising numeric pickers with no user defined template. |
| 3.15 | The prevention of PIN enabled menu items on non-touch screen devices was improperly implemented, this version provides a bug fix. |

View File

@@ -76,49 +76,32 @@ class HomeAssistantView extends WatchUi.Menu2 {
}
}
if (type != null && name != null && enabled) {
if (type.equals("toggle") && entity != null) {
addItem(HomeAssistantMenuItemFactory.create().toggle(
name,
entity,
content,
{
:exit => exit,
:confirm => confirm,
:pin => pin
}
));
} else if (type.equals("tap") && action != null) {
if (pin && !System.getDeviceSettings().isTouchScreen) {
addItem(HomeAssistantMenuItemFactory.create().tap(
name,
entity,
content,
action,
"PIN requires Touchscreen",
null,
null,
null,
data,
{
:exit => exit,
:confirm => confirm,
:pin => pin
:exit => false,
:confirm => false,
:pin => false
}
));
} else if (type.equals("template") && content != null) {
// NB. "template" is deprecated in the schema and remains only for backward compatibility. All menu items can now use templates, so the replacement is "info".
// The exit option is dependent on the type of template.
if (tap_action == null) {
// No exit from an information only item
addItem(HomeAssistantMenuItemFactory.create().tap(
} else {
if (type.equals("toggle") && entity != null) {
addItem(HomeAssistantMenuItemFactory.create().toggle(
name,
entity,
content,
action,
data,
{
:exit => false,
:exit => exit,
:confirm => confirm,
:pin => pin
}
));
} else {
// You may exit from template item with a 'tap_action'.
} else if (type.equals("tap") && action != null) {
addItem(HomeAssistantMenuItemFactory.create().tap(
name,
entity,
@@ -131,9 +114,39 @@ class HomeAssistantView extends WatchUi.Menu2 {
:pin => pin
}
));
}
} else if (type.equals("numeric") && action != null) {
if (System.getDeviceSettings().isTouchScreen) {
} else if (type.equals("template") && content != null) {
// NB. "template" is deprecated in the schema and remains only for backward compatibility. All menu items can now use templates, so the replacement is "info".
// The exit option is dependent on the type of template.
if (tap_action == null) {
// No exit from an information only item
addItem(HomeAssistantMenuItemFactory.create().tap(
name,
entity,
content,
action,
data,
{
:exit => false,
:confirm => confirm,
:pin => pin
}
));
} else {
// You may exit from template item with a 'tap_action'.
addItem(HomeAssistantMenuItemFactory.create().tap(
name,
entity,
content,
action,
data,
{
:exit => exit,
:confirm => confirm,
:pin => pin
}
));
}
} else if (type.equals("numeric") && action != null) {
// Numeric items are only actionable on touch screen devices.
if (tap_action != null) {
var picker = tap_action.get("picker") as Lang.Dictionary?;
@@ -153,36 +166,23 @@ class HomeAssistantView extends WatchUi.Menu2 {
));
}
}
} else {
} else if (type.equals("info") && content != null) {
// Cannot exit from a non-actionable information only menu item.
addItem(HomeAssistantMenuItemFactory.create().tap(
"PIN requires Touchscreen",
null,
null,
null,
name,
entity,
content,
action,
data,
{
:exit => false,
:confirm => false,
:pin => false
:confirm => confirm,
:pin => pin
}
));
} else if (type.equals("group")) {
addItem(HomeAssistantMenuItemFactory.create().group(items[i], content));
}
} else if (type.equals("info") && content != null) {
// Cannot exit from a non-actionable information only menu item.
addItem(HomeAssistantMenuItemFactory.create().tap(
name,
entity,
content,
action,
data,
{
:exit => false,
:confirm => confirm,
:pin => pin
}
));
} else if (type.equals("group")) {
addItem(HomeAssistantMenuItemFactory.create().group(items[i], content));
}
}
}