Compare commits

...

5 Commits

Author SHA1 Message Date
Philip Abbey
5639ff5c42 Amended heading levels in docs 2025-07-09 21:51:18 +01:00
Philip Abbey
8b3e86a00f Amended documentation for two new menu item options
The options are 'enable' and 'exit'.
2025-07-09 21:48:58 +01:00
Philip Abbey
6dbcea94cf Update HomeAssistantView.mc
Refined more precisely where the exit option can be used and enforced in the code.
2025-07-09 21:09:33 +01:00
Philip Abbey
b28daacafd Update config.schema.json
Removed exit from non-actionable menu items.
2025-07-09 20:54:28 +01:00
Philip Abbey
029a9f373e Update config.schema.json
Added to boolean options for disable and exit.
2025-07-09 19:57:11 +01:00
5 changed files with 124 additions and 2 deletions

View File

@@ -47,6 +47,12 @@
}
},
"additionalProperties": false
},
"enable": {
"$ref": "#/$defs/enable"
},
"exit": {
"$ref": "#/$defs/exit"
}
},
"required": ["entity", "name", "type"],
@@ -75,6 +81,9 @@
"deprecated": true,
"title": "Schema change:",
"description": "Use 'info' or 'tap' instead."
},
"enable": {
"$ref": "#/$defs/enable"
}
},
"required": ["name", "content", "type"],
@@ -101,6 +110,12 @@
},
"tap_action": {
"$ref": "#/$defs/tap_action"
},
"enable": {
"$ref": "#/$defs/enable"
},
"exit": {
"$ref": "#/$defs/exit"
}
},
"required": ["name", "content", "type", "tap_action"],
@@ -120,6 +135,9 @@
"type": {
"$ref": "#/$defs/type",
"const": "info"
},
"enable": {
"$ref": "#/$defs/enable"
}
},
"required": ["name", "content", "type"],
@@ -149,6 +167,12 @@
},
"tap_action": {
"$ref": "#/$defs/tap_action"
},
"enable": {
"$ref": "#/$defs/enable"
},
"exit": {
"$ref": "#/$defs/exit"
}
},
"required": ["name", "type"],
@@ -181,6 +205,9 @@
},
"items": {
"$ref": "#/$defs/items"
},
"enable": {
"$ref": "#/$defs/enable"
}
},
"required": ["name", "title", "type", "items"],
@@ -293,6 +320,18 @@
"required": ["type"]
}
]
},
"enable": {
"type": "boolean",
"default": true,
"title": "Enable the menu item",
"description": "Typically used to temporarily disable a menu item, e.g. for seasonal variations. Enabled (true) by default."
},
"exit": {
"type": "boolean",
"default": false,
"title": "Exit on selection",
"description": "Choose to exit the application after this item has been selected. Disabled (false) by default. N.B. Only actionable menu items can have this field added."
}
}
}

View File

@@ -76,3 +76,35 @@ Note that for notify events, you _must_ not supply an `entity_id` or the API cal
> Be careful with the value of the `service` field.
Note that the `service` field will need to be a locally custom `script.<something>` as soon as any `data` fields are populated and not something more generic like `script.turn_on`. If the `service` field is wrong, the application will fail with a [`Communications.INVALID_HTTP_BODY_IN_NETWORK_RESPONSE`](https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html) error in the response from your Home Assistant and show the error message as _"No JSON returned from HTTP request"_ on your device. In the [web-based editor](https://house-of-abbey.github.io/GarminHomeAssistant/web/) you can use the standard developer tools to observe an `HTTP 400` error which the application does not see. Here we are limited by the [Garmin Connect IQ](https://developer.garmin.com/connect-iq/overview/) software development kit (SDK). We do not have enough information at the point of execution in the application to determine the cause of the error. Nor is there an immediately obvious way of identifying this issue using the JSON schema checks.
## Exit on Tap
You can choose individual items that will quit after they have completed their action.
```json
{
"entity": "automation.turn_off_stuff",
"name": "Turn off Stuff",
"type": "tap",
"tap_action": {
"service": "automation.trigger"
},
"exit": true
}
```
## Disable Menu Item
If you would like to temporarily disable an item in your menu, e.g. for seasonal reasons like not needing to turn on the heating in summer, then rather than swapping menu definition files or deleting a section of the menu you can mark the item as 'disabled'. This field applies to all menu items.
```json
{
"entity": "automation.turn_off_stuff",
"name": "Turn off Stuff",
"type": "tap",
"tap_action": {
"service": "automation.trigger"
},
"enabled": false
}
```

View File

@@ -109,3 +109,29 @@ Then you can use the following in your config:
"type": "toggle"
}
```
## Exit On Toggle
You can choose individual items that will quit after they have completed their action.
```json
{
"entity": "light.hall_light",
"name": "Hall Light & Quit",
"type": "toggle",
"exit": true
}
```
## Disable Menu Item
If you would like to temporarily disable an item in your menu, e.g. for seasonal reasons like not needing to turn on Christmas tree lights outside the festive season, then rather than swapping menu definition files or deleting a section of the menu you can mark the item as 'disabled'. This field applies to all menu items.
```json
{
"entity": "light.chrissmas_tree",
"name": "Christmas Lights",
"type": "toggle",
"enabled": false
}
```

View File

@@ -218,6 +218,19 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
}
```
## Disable Menu Item
If you would like to temporarily disable an item in your menu, then rather than swapping menu definition files or deleting a section of the menu you can mark the item as 'disabled'. This field applies to all menu items.
```json
{
"name": "Phone",
"type": "info",
"content": "{{ ... }}",
"enabled": false
}
```
## Warnings
Just remember, on older smaller memory devices **you have the ability to crash the application by creating an excessive menu definition**. Templates can require significant definition for highly customised text. Don't be silly.

View File

@@ -72,9 +72,21 @@ class HomeAssistantView extends WatchUi.Menu2 {
if (type != null && name != null && enable) {
if (type.equals("toggle") && entity != null) {
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, content, exit, confirm, pin));
} else if ((type.equals("tap") && service != null) || (type.equals("info") && content != null) || (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".
} else if (type.equals("tap") && service != null) {
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, data, exit, confirm, pin));
} 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, service, data, false, confirm, pin));
} else {
// You may exit from template item with a 'tap_action'.
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, data, exit, confirm, pin));
}
} else if (type.equals("info") && content != null) {
// Cannot exit from a non-actionable information only menu item.
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, content, service, data, false, confirm, pin));
} else if (type.equals("group")) {
addItem(HomeAssistantMenuItemFactory.create().group(items[i], content));
}