mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-11-13 20:48:14 +00:00
Compare commits
3 Commits
Picker-for
...
support-mo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6aafd4fcb1 | ||
|
|
a52d6188be | ||
|
|
e697f75ce3 |
@@ -81,7 +81,7 @@ Example schema:
|
||||
"name": "Food is Ready!",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "script.turn_on",
|
||||
"action": "script.turn_on",
|
||||
"confirm": true
|
||||
}
|
||||
},
|
||||
@@ -132,7 +132,7 @@ Example schema:
|
||||
"name": "Turn off USBs",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "automation.trigger"
|
||||
"action": "automation.trigger"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -140,7 +140,7 @@ Example schema:
|
||||
"name": "TV Lights Scene",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "scene.turn_on",
|
||||
"action": "scene.turn_on",
|
||||
"pin": true
|
||||
}
|
||||
},
|
||||
@@ -150,7 +150,7 @@ Example schema:
|
||||
"type": "numeric",
|
||||
"entity": "climate.myheating",
|
||||
"tap_action": {
|
||||
"service": "climate.set_temperature",
|
||||
"action": "climate.set_temperature",
|
||||
"data": {
|
||||
"step": "0.5",
|
||||
"start": "10",
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
"$defs": {
|
||||
"toggle": {
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"type": "toggle",
|
||||
"name": "Example",
|
||||
"entity": "switch.example"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity"
|
||||
@@ -115,16 +122,29 @@
|
||||
"$ref": "#/$defs/tap_action",
|
||||
"properties": {
|
||||
"service": {
|
||||
"$ref": "#/$defs/service"
|
||||
"$ref": "#/$defs/action",
|
||||
"deprecated": true
|
||||
},
|
||||
"action": {
|
||||
"$ref": "#/$defs/action"
|
||||
},
|
||||
"data": {
|
||||
"type": "object",
|
||||
"title": "Your services's parameters",
|
||||
"title": "Your action's parameters",
|
||||
"description": "The object containing the parameters and their values to be passed to the entity. No schema checking can be done here, you are on your own! On application crash, remove the parameters."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"service"
|
||||
"anyOf": [
|
||||
{
|
||||
"required": [
|
||||
"service"
|
||||
]
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"action"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"enabled": {
|
||||
@@ -170,6 +190,18 @@
|
||||
},
|
||||
"tap": {
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"type": "tap",
|
||||
"name": "Example",
|
||||
"tap_action": {
|
||||
"action": "notify.notify",
|
||||
"data": {
|
||||
"message": "Example"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity"
|
||||
@@ -185,7 +217,7 @@
|
||||
"$ref": "#/$defs/content"
|
||||
},
|
||||
"service": {
|
||||
"$ref": "#/$defs/service",
|
||||
"$ref": "#/$defs/action",
|
||||
"deprecated": true,
|
||||
"title": "Schema change:",
|
||||
"description": "Use 'tap_action' instead to mirror Home Assistant."
|
||||
@@ -194,16 +226,29 @@
|
||||
"$ref": "#/$defs/tap_action",
|
||||
"properties": {
|
||||
"service": {
|
||||
"$ref": "#/$defs/service"
|
||||
"$ref": "#/$defs/action",
|
||||
"deprecated": true
|
||||
},
|
||||
"action": {
|
||||
"$ref": "#/$defs/action"
|
||||
},
|
||||
"data": {
|
||||
"type": "object",
|
||||
"title": "Your services's parameters",
|
||||
"title": "Your actions's parameters",
|
||||
"description": "The object containing the parameters and their values to be passed to the entity. No schema checking can be done here, you are on your own! On application crash, remove the parameters."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"service"
|
||||
"anyOf": [
|
||||
{
|
||||
"required": [
|
||||
"service"
|
||||
]
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"action"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"enabled": {
|
||||
@@ -221,6 +266,14 @@
|
||||
},
|
||||
"group": {
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"type": "group",
|
||||
"name": "Example",
|
||||
"title": "Example",
|
||||
"items": []
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity",
|
||||
@@ -261,6 +314,105 @@
|
||||
},
|
||||
"numeric": {
|
||||
"type": "object",
|
||||
"examples": [
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "light.example",
|
||||
"attribute": "brightness",
|
||||
"action": "light.turn_on",
|
||||
"action_attribute": "brightness",
|
||||
"min": 0,
|
||||
"max": 255,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "input_number.example",
|
||||
"action": "input_number.set_value",
|
||||
"action_attribute": "value",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "number.example",
|
||||
"action": "number.set_value",
|
||||
"action_attribute": "value",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "fan.example",
|
||||
"attribute": "percentage",
|
||||
"action": "fan.set_percentage",
|
||||
"action_attribute": "percentage",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "valve.example",
|
||||
"attribute": "position",
|
||||
"action": "valve.set_valve_position",
|
||||
"action_attribute": "position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "cover.example",
|
||||
"attribute": "position",
|
||||
"action": "cover.set_position",
|
||||
"action_attribute": "position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "cover.example",
|
||||
"attribute": "tilt_position",
|
||||
"action": "cover.set_tilt_position",
|
||||
"action_attribute": "tilt_position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "media_player.example",
|
||||
"attribute": "volume_level",
|
||||
"action": "media_player.volume_set",
|
||||
"action_attribute": "volume_level",
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "climate.example",
|
||||
"attribute": "temperature",
|
||||
"action": "climate.set_temperature",
|
||||
"action_attribute": "temperature",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
}
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
@@ -283,14 +435,49 @@
|
||||
"exit": {
|
||||
"$ref": "#/$defs/exit"
|
||||
},
|
||||
"min": {
|
||||
"type": "number",
|
||||
"title": "Minimum value"
|
||||
},
|
||||
"max": {
|
||||
"type": "number",
|
||||
"title": "Maximum value"
|
||||
},
|
||||
"step": {
|
||||
"type": "number",
|
||||
"title": "Step size"
|
||||
},
|
||||
"decimals": {
|
||||
"type": "number",
|
||||
"title": "Number of decimals to display",
|
||||
"minimum": 0,
|
||||
"maximum": 10,
|
||||
"default": 1
|
||||
},
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity"
|
||||
},
|
||||
"attribute": {
|
||||
"type": "string",
|
||||
"title": "Attribute on the entity with the current numeric value. To use the state of the entity, do not specify."
|
||||
},
|
||||
"action": {
|
||||
"$ref": "#/$defs/action"
|
||||
},
|
||||
"action_attribute": {
|
||||
"type": "string",
|
||||
"title": "Attribute on the action data for the value to set."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"type",
|
||||
"entity"
|
||||
"min",
|
||||
"max",
|
||||
"step",
|
||||
"entity",
|
||||
"action",
|
||||
"action_attribute"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
@@ -312,10 +499,10 @@
|
||||
"attribute": {
|
||||
"const": "brightness"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "light.turn_on"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "brightness"
|
||||
},
|
||||
"min": {
|
||||
@@ -340,10 +527,10 @@
|
||||
"attribute": {
|
||||
"const": "value"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "input_number.set_value"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "value"
|
||||
}
|
||||
},
|
||||
@@ -366,10 +553,10 @@
|
||||
"attribute": {
|
||||
"const": "value"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "number.set_value"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "value"
|
||||
}
|
||||
},
|
||||
@@ -392,10 +579,10 @@
|
||||
"attribute": {
|
||||
"const": "percentage"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "fan.set_percentage"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "percentage"
|
||||
},
|
||||
"min": {
|
||||
@@ -419,10 +606,10 @@
|
||||
"attribute": {
|
||||
"const": "position"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "valve.set_valve_position"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "position"
|
||||
},
|
||||
"min": {
|
||||
@@ -446,10 +633,10 @@
|
||||
"attribute": {
|
||||
"const": "position"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "cover.set_position"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "position"
|
||||
},
|
||||
"min": {
|
||||
@@ -473,10 +660,10 @@
|
||||
"attribute": {
|
||||
"const": "tilt_position"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "cover.set_tilt_position"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "tilt_position"
|
||||
},
|
||||
"min": {
|
||||
@@ -500,10 +687,10 @@
|
||||
"attribute": {
|
||||
"const": "volume_level"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "media_player.volume_set"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "volume_level"
|
||||
},
|
||||
"min": {
|
||||
@@ -527,10 +714,10 @@
|
||||
"attribute": {
|
||||
"const": "temperature"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"const": "climate.set_temperature"
|
||||
},
|
||||
"data_attribute": {
|
||||
"action_attribute": {
|
||||
"const": "temperature"
|
||||
}
|
||||
}
|
||||
@@ -553,210 +740,24 @@
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"examples": [
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "tap",
|
||||
"name": "Example",
|
||||
"tap_action": {
|
||||
"service": "notify.notify",
|
||||
"data": {
|
||||
"message": "Example"
|
||||
}
|
||||
}
|
||||
"$ref": "#/$defs/toggle"
|
||||
},
|
||||
{
|
||||
"type": "toggle",
|
||||
"name": "Example",
|
||||
"entity": "switch.example"
|
||||
"$ref": "#/$defs/template"
|
||||
},
|
||||
{
|
||||
"type": "group",
|
||||
"name": "Example",
|
||||
"title": "Example",
|
||||
"items": []
|
||||
"$ref": "#/$defs/tap"
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "light.example",
|
||||
"attribute": "brightness",
|
||||
"service": "light.turn_on",
|
||||
"data_attribute": "brightness",
|
||||
"min": 0,
|
||||
"max": 255,
|
||||
"step": 1
|
||||
"$ref": "#/$defs/info"
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "input_number.example",
|
||||
"service": "input_number.set_value",
|
||||
"data_attribute": "value",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
"$ref": "#/$defs/group"
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "number.example",
|
||||
"service": "number.set_value",
|
||||
"data_attribute": "value",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "fan.example",
|
||||
"attribute": "percentage",
|
||||
"service": "fan.set_percentage",
|
||||
"data_attribute": "percentage",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1,
|
||||
"display_format": "%.0f%%"
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "valve.example",
|
||||
"attribute": "position",
|
||||
"service": "valve.set_valve_position",
|
||||
"data_attribute": "position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "cover.example",
|
||||
"attribute": "position",
|
||||
"service": "cover.set_position",
|
||||
"data_attribute": "position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "cover.example",
|
||||
"attribute": "tilt_position",
|
||||
"service": "cover.set_tilt_position",
|
||||
"data_attribute": "tilt_position",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "media_player.example",
|
||||
"attribute": "volume_level",
|
||||
"service": "media_player.volume_set",
|
||||
"data_attribute": "volume_level",
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"type": "numeric",
|
||||
"name": "Example",
|
||||
"entity": "climate.example",
|
||||
"attribute": "temperature",
|
||||
"service": "climate.set_temperature",
|
||||
"data_attribute": "temperature"
|
||||
}
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"toggle",
|
||||
"template",
|
||||
"tap",
|
||||
"info",
|
||||
"group",
|
||||
"numeric"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "toggle"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/toggle"
|
||||
},
|
||||
"else": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "template"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/template"
|
||||
},
|
||||
"else": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "tap"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/tap"
|
||||
},
|
||||
"else": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "info"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/info"
|
||||
},
|
||||
"else": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "group"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/group"
|
||||
},
|
||||
"else": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "numeric"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"$ref": "#/$defs/numeric"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"$ref": "#/$defs/numeric"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -770,9 +771,9 @@
|
||||
"title": "Home Assistant entity name",
|
||||
"pattern": "^[^.]+\\.[^.]+$"
|
||||
},
|
||||
"service": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"title": "Home Assistant service name",
|
||||
"title": "Home Assistant action name",
|
||||
"pattern": "^[^.]+\\.[^.]+$"
|
||||
},
|
||||
"tap_action": {
|
||||
@@ -780,9 +781,6 @@
|
||||
"title": "Action",
|
||||
"description": "'confirm' field is optional.",
|
||||
"properties": {
|
||||
"picker": {
|
||||
"$ref": "#/$defs/picker"
|
||||
},
|
||||
"confirm": {
|
||||
"$ref": "#/$defs/confirm"
|
||||
},
|
||||
@@ -791,41 +789,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"picker": {
|
||||
"type": "object",
|
||||
"title": "Number picker configuration",
|
||||
"description": "'attribute' field is optional.",
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "number",
|
||||
"title": "Minimum Value"
|
||||
},
|
||||
"max": {
|
||||
"type": "number",
|
||||
"title": "Maximum Value"
|
||||
},
|
||||
"step": {
|
||||
"type": "number",
|
||||
"title": "Step Size"
|
||||
},
|
||||
"attribute": {
|
||||
"type": "string",
|
||||
"title": "Attribute on the entity",
|
||||
"description": "Attribute on the entity with the current numeric value. To use the state of the entity, do not specify."
|
||||
},
|
||||
"data_attribute": {
|
||||
"type": "string",
|
||||
"title": "Attribute on the service data",
|
||||
"description": "Attribute on the service data for the value to set."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"min",
|
||||
"max",
|
||||
"step",
|
||||
"data_attribute"
|
||||
]
|
||||
},
|
||||
"content": {
|
||||
"title": "Home Assistant Template",
|
||||
"description": "Jinja2 template defining the text to display. Must be included in an 'info'. Optional in a 'toggle', 'tap' and 'group'. Special characters may not render in the glance context.",
|
||||
@@ -890,4 +853,4 @@
|
||||
"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."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ A simple example using a scene as a `tap` menu item.
|
||||
"name": "Telly Scene",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "scene.turn_on"
|
||||
"action": "scene.turn_on"
|
||||
}
|
||||
},
|
||||
```
|
||||
@@ -62,7 +62,7 @@ Note that for notify events, you _must_ not supply an `entity_id` or the API cal
|
||||
"name": "Message",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "notify.mobile_app_on_phone",
|
||||
"action": "notify.mobile_app_on_phone",
|
||||
"data": {
|
||||
"title": "This is a title",
|
||||
"message": "This is the message"
|
||||
@@ -73,9 +73,9 @@ Note that for notify events, you _must_ not supply an `entity_id` or the API cal
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Be careful with the value of the `service` field.
|
||||
> Be careful with the value of the `action` 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 HomeAssistant 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.
|
||||
Note that the `action` 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 `action` 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 HomeAssistant 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
|
||||
|
||||
@@ -87,7 +87,7 @@ You can choose individual items that will quit after they have completed their a
|
||||
"name": "Turn off Stuff",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "automation.trigger"
|
||||
"action": "automation.trigger"
|
||||
},
|
||||
"exit": true
|
||||
}
|
||||
@@ -103,7 +103,7 @@ If you would like to temporarily disable an item in your menu, e.g. for seasonal
|
||||
"name": "Turn off Stuff",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "automation.trigger"
|
||||
"action": "automation.trigger"
|
||||
},
|
||||
"enabled": false
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ switch:
|
||||
friendly_name: <name>
|
||||
value_template: <value>
|
||||
turn_on:
|
||||
service: <service>
|
||||
action: <action>
|
||||
data:
|
||||
entity_id: <entity>
|
||||
<attribute>: <value>
|
||||
turn_off:
|
||||
service: <service>
|
||||
action: <action>
|
||||
data:
|
||||
entity_id: <entity>
|
||||
<attribute>: <value>
|
||||
@@ -90,11 +90,11 @@ switch:
|
||||
friendly_name: Cover
|
||||
value_template: "{{ is_state('cover.cover', 'open') }}"
|
||||
turn_on:
|
||||
service: cover.open_cover
|
||||
action: cover.open_cover
|
||||
data:
|
||||
entity_id: cover.cover
|
||||
turn_off:
|
||||
service: cover.close_cover
|
||||
action: cover.close_cover
|
||||
data:
|
||||
entity_id: cover.cover
|
||||
```
|
||||
|
||||
@@ -116,7 +116,7 @@ Note: Only when you use the `tap_action` field do you also need to include the `
|
||||
"type": "tap",
|
||||
"content": "{% if is_state('binary_sensor.garage_connected', 'on') %}{{state_translated('cover.garage_door')}} - {{state_attr('cover.garage_door', 'current_position')}}%{%else%}Unconnected{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "cover.toggle",
|
||||
"action": "cover.toggle",
|
||||
"pin": true
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
||||
"type": "tap",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0)) | int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"action": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 12
|
||||
}
|
||||
@@ -184,7 +184,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
||||
"name": "LEDs 1",
|
||||
"type": "tap",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"action": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 37
|
||||
}
|
||||
@@ -196,7 +196,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
||||
"type": "tap",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0)) | int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"action": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 62
|
||||
}
|
||||
@@ -208,7 +208,7 @@ An example of a dimmer light with 4 brightness settings 0..3. Here our light wor
|
||||
"type": "tap",
|
||||
"content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0))| int }}%{% else %}Off{% endif %}",
|
||||
"tap_action": {
|
||||
"service": "light.turn_on",
|
||||
"action": "light.turn_on",
|
||||
"data": {
|
||||
"brightness_pct": 87
|
||||
}
|
||||
|
||||
@@ -629,12 +629,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
if (item instanceof HomeAssistantToggleMenuItem) {
|
||||
(item as HomeAssistantToggleMenuItem).updateToggleState(data[i.toString() + "t"]);
|
||||
}
|
||||
if (item instanceof HomeAssistantNumericMenuItem) {
|
||||
var s = data[i.toString() + "n"];
|
||||
if ((s instanceof Lang.Number) or (s instanceof Lang.Float)) {
|
||||
(item as HomeAssistantNumericMenuItem).setValue(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Settings.getMenuCheck() && Settings.getCacheConfig() && !mIsCacheChecked) {
|
||||
// We are caching the menu configuration, so let's fetch it and check if its been updated.
|
||||
@@ -729,11 +723,6 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
"template" => (item as HomeAssistantToggleMenuItem).getToggleTemplate()
|
||||
});
|
||||
}
|
||||
if (item instanceof HomeAssistantNumericMenuItem) {
|
||||
mTemplates.put(i.toString() + "n", {
|
||||
"template" => (item as HomeAssistantNumericMenuItem).getNumericTemplate()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// https://developers.home-assistant.io/docs/api/native-app-integration/sending-data/#render-templates
|
||||
@@ -833,7 +822,7 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
var phoneConnected = System.getDeviceSettings().phoneConnected;
|
||||
var connectionAvailable = System.getDeviceSettings().connectionAvailable;
|
||||
|
||||
// System.println("HomeAssistantApp fetchApiStatus(): API URL = " + Settings.getApiUrl());
|
||||
// System.println("API URL = " + Settings.getApiUrl());
|
||||
if (Settings.getApiUrl().equals("")) {
|
||||
mApiStatus = WatchUi.loadResource($.Rez.Strings.Unconfigured) as Lang.String;
|
||||
WatchUi.requestUpdate();
|
||||
|
||||
@@ -99,7 +99,7 @@ class HomeAssistantMenuItemFactory {
|
||||
//! @param label Menu item label.
|
||||
//! @param entity_id Home Assistant Entity ID (optional)
|
||||
//! @param template Template for Home Assistant to render (optional)
|
||||
//! @param service Template for Home Assistant to render (optional)
|
||||
//! @param action Action to run on Home Assistant (optional)
|
||||
//! @param data Sourced from the menu JSON, this is the `data` field from the `tap_action` field.
|
||||
//! @param options Menu item options to be passed on, including both SDK and menu options, e.g. exit, confirm & pin.
|
||||
//
|
||||
@@ -107,7 +107,7 @@ class HomeAssistantMenuItemFactory {
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity_id as Lang.String?,
|
||||
template as Lang.String?,
|
||||
service as Lang.String?,
|
||||
action as Lang.String?,
|
||||
data as Lang.Dictionary?,
|
||||
options as {
|
||||
:exit as Lang.Boolean,
|
||||
@@ -126,12 +126,12 @@ class HomeAssistantMenuItemFactory {
|
||||
for (var i = 0; i < keys.size(); i++) {
|
||||
options.put(keys[i], mMenuItemOptions.get(keys[i]));
|
||||
}
|
||||
if (service != null) {
|
||||
if (action != null) {
|
||||
options.put(:icon, mTapTypeIcon);
|
||||
return new HomeAssistantTapMenuItem(
|
||||
label,
|
||||
template,
|
||||
service,
|
||||
action,
|
||||
data,
|
||||
options,
|
||||
mHomeAssistantService
|
||||
@@ -157,8 +157,8 @@ class HomeAssistantMenuItemFactory {
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity_id as Lang.String?,
|
||||
template as Lang.String?,
|
||||
service as Lang.String?,
|
||||
picker as Lang.Dictionary,
|
||||
action as Lang.String?,
|
||||
data as Lang.Dictionary?,
|
||||
options as {
|
||||
:exit as Lang.Boolean,
|
||||
:confirm as Lang.Boolean,
|
||||
@@ -166,21 +166,25 @@ 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.put("entity_id", entity_id);
|
||||
}
|
||||
}
|
||||
var keys = mMenuItemOptions.keys();
|
||||
for (var i = 0; i < keys.size(); i++) {
|
||||
options.put(keys[i], mMenuItemOptions.get(keys[i]));
|
||||
}
|
||||
options.put(:icon, mTapTypeIcon);
|
||||
options.put(:icon, mTapTypeIcon);
|
||||
|
||||
return new HomeAssistantNumericMenuItem(
|
||||
label,
|
||||
template,
|
||||
service,
|
||||
action,
|
||||
data,
|
||||
picker,
|
||||
options,
|
||||
mHomeAssistantService
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// tested on a Venu 2 device. The source code is provided at:
|
||||
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
||||
//
|
||||
// P A Abbey & J D Abbey & @thmichel, 13 October 2025
|
||||
// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
@@ -17,29 +17,30 @@ using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
using Toybox.Graphics;
|
||||
|
||||
|
||||
//! Menu button with an icon that opens a sub-menu, i.e. group, and optionally renders
|
||||
//! a Home Assistant Template.
|
||||
//
|
||||
class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
private var mHomeAssistantService as HomeAssistantService?;
|
||||
private var mService as Lang.String?;
|
||||
private var mAction as Lang.String?;
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mExit as Lang.Boolean;
|
||||
private var mPin as Lang.Boolean;
|
||||
private var mData as Lang.Dictionary?;
|
||||
private var mPicker as Lang.Dictionary?;
|
||||
private var mValue as Lang.Number or Lang.Float = 0;
|
||||
private var mFormatString as Lang.String = "%d";
|
||||
private var mValue as Lang.String?;
|
||||
private var mFormatString as Lang.String="%.1f";
|
||||
|
||||
|
||||
//! Class Constructor
|
||||
//!
|
||||
//! @param label Menu item label.
|
||||
//! @param template Menu item template.
|
||||
//! @param service Menu item service.
|
||||
//! @param data Data to supply to the service call.
|
||||
//! @param exit Should the service call complete and then exit?
|
||||
//! @param confirm Should the service call be confirmed to avoid accidental invocation?
|
||||
//! @param pin Should the service call be protected with a PIN for some low level of security?
|
||||
//! @param action Menu item action.
|
||||
//! @param data Data to supply to the action call.
|
||||
//! @param exit Should the action call complete and then exit?
|
||||
//! @param confirm Should the action call be confirmed to avoid accidental invocation?
|
||||
//! @param pin Should the action call be protected with a PIN for some low level of security?
|
||||
//! @param icon Icon to use for the menu item.
|
||||
//! @param options Menu item options to be passed on, including both SDK and menu options, e.g. exit, confirm & pin.
|
||||
//! @param haService Shared Home Assistant service object that will perform the required call. Only
|
||||
@@ -48,9 +49,8 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
function initialize(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
template as Lang.String,
|
||||
service as Lang.String?,
|
||||
action as Lang.String?,
|
||||
data as Lang.Dictionary?,
|
||||
picker as Lang.Dictionary,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment,
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol,
|
||||
@@ -60,9 +60,8 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
}?,
|
||||
haService as HomeAssistantService
|
||||
) {
|
||||
mService = service;
|
||||
mAction = action;
|
||||
mData = data;
|
||||
mPicker = picker;
|
||||
mExit = options[:exit];
|
||||
mConfirm = options[:confirm];
|
||||
mPin = options[:pin];
|
||||
@@ -75,25 +74,13 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
{
|
||||
:alignment => options[:alignment],
|
||||
:icon => options[:icon]
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (picker != null) {
|
||||
var s = picker["step"];
|
||||
if (s != null) {
|
||||
var step = s.toFloat() as Lang.Float;
|
||||
var dp = 0;
|
||||
while (step < 1.0) {
|
||||
step *= 10;
|
||||
dp++;
|
||||
// Assigned inside the loop and in each iteration to avoid clobbering the default '%d'.
|
||||
mFormatString = "%." + dp.toString() + "f";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function callService() as Void {
|
||||
|
||||
|
||||
function callAction() as Void {
|
||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||
if (mPin && hasTouchScreen) {
|
||||
var pin = Settings.getPin();
|
||||
@@ -102,10 +89,10 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
WatchUi.pushView(
|
||||
pinConfirmationView,
|
||||
new HomeAssistantPinConfirmationDelegate({
|
||||
:callback => method(:onConfirm),
|
||||
:pin => pin,
|
||||
:state => false,
|
||||
:view => pinConfirmationView,
|
||||
:callback => method(:onConfirm),
|
||||
:pin => pin,
|
||||
:state => false,
|
||||
:view => pinConfirmationView,
|
||||
}),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
@@ -119,8 +106,8 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
WatchUi.pushView(
|
||||
dialog,
|
||||
new WifiLteExecutionConfirmDelegate({
|
||||
:type => "service",
|
||||
:service => mService,
|
||||
:type => "action",
|
||||
:action => mAction,
|
||||
:data => mData,
|
||||
:exit => mExit,
|
||||
}, dialog),
|
||||
@@ -143,60 +130,25 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! Callback function after the menu items selection has been (optionally) confirmed.
|
||||
//!
|
||||
//! @param b Ignored. It is included in order to match the expected function prototype of the callback method.
|
||||
//
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
var dataAttribute = mPicker["data_attribute"];
|
||||
if (dataAttribute == null) {
|
||||
//return without call service if no data attribute is set to avoid crash
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
return;
|
||||
}
|
||||
var entity_id = mData["entity_id"];
|
||||
if (entity_id == null) {
|
||||
//return without call service if no entity_id is set to avoid crash
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
return;
|
||||
}
|
||||
mHomeAssistantService.call(
|
||||
mService,
|
||||
{
|
||||
"entity_id" => entity_id.toString(),
|
||||
dataAttribute.toString() => mValue
|
||||
},
|
||||
mExit
|
||||
);
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
mHomeAssistantService.call(mAction, {"entity_id" => mData.get("entity_id").toString(),mData.get("valueLabel").toString() => mValue}, mExit);
|
||||
|
||||
}
|
||||
|
||||
//! Return a numeric menu item's fetch state template.
|
||||
//!
|
||||
//! @return A string with the menu item's template definition (or null).
|
||||
//
|
||||
function getNumericTemplate() as Lang.String? {
|
||||
var entity_id = mData["entity_id"];
|
||||
var attribute = mPicker["attribute"] as Lang.String;
|
||||
if (entity_id == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (attribute == null) {
|
||||
// Compiler says: "Statement is not reachable."
|
||||
// This is wrong because a break point on the following line proves it is executed!
|
||||
return "{{states('" + entity_id.toString() + "')}}";
|
||||
} else {
|
||||
return "{{state_attr('" + entity_id.toString() + "','" + attribute + "')}}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! Update the menu item's sub label to display the template rendered by Home Assistant.
|
||||
//!
|
||||
//! @param data The rendered template (typically a string) to be placed in the sub label. This may
|
||||
//! unusually be a number if the SDK interprets the JSON returned by Home Assistant as such.
|
||||
//
|
||||
public function updateState(data as Lang.String or Lang.Dictionary or Lang.Number or Lang.Float or Null) as Void {
|
||||
function updateState(data as Lang.String or Lang.Dictionary or Lang.Number or Lang.Float or Null) as Void {
|
||||
if (data == null) {
|
||||
setSubLabel($.Rez.Strings.Empty);
|
||||
} else if(data instanceof Lang.Float) {
|
||||
@@ -205,45 +157,26 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem {
|
||||
} else if(data instanceof Lang.Number) {
|
||||
var f = data.toFloat() as Lang.Float;
|
||||
setSubLabel(f.format(mFormatString));
|
||||
} else if (data instanceof Lang.String) {
|
||||
// This should not happen
|
||||
} else if (data instanceof Lang.String){
|
||||
setSubLabel(data);
|
||||
} else {
|
||||
// The template must return a Float on Numeric value, or the item cannot be formatted locally without error.
|
||||
}
|
||||
else {
|
||||
// The template must return a Float, or the item cannot be formatted locally without error.
|
||||
setSubLabel(WatchUi.loadResource($.Rez.Strings.TemplateError) as Lang.String);
|
||||
}
|
||||
WatchUi.requestUpdate();
|
||||
}
|
||||
|
||||
//! Set the Picker's value. Needed to set new value via the Service call
|
||||
//!
|
||||
//! @param value New value to set.
|
||||
//
|
||||
public function setValue(value as Lang.Number or Lang.Float) as Void {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
//! Get the Picker's value.
|
||||
//! Set the mValue value.
|
||||
//!
|
||||
//! Needed to set new value via the Service call
|
||||
//
|
||||
public function getValue() as Lang.Number or Lang.Float {
|
||||
return mValue;
|
||||
function setValue(value as Lang.String) as Void {
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
//! Get the original 'data' field supplied by the JSON menu.
|
||||
//!
|
||||
//! @return Dictionary containing the 'data' field.
|
||||
//
|
||||
public function getData() as Lang.Dictionary {
|
||||
function getData() as Lang.Dictionary {
|
||||
return mData;
|
||||
}
|
||||
|
||||
// Get the original 'picker' field supplied by the JSON menu.
|
||||
//!
|
||||
//! @return Dictionary containing the 'picker' field.
|
||||
//
|
||||
public function getPicker() as Lang.Dictionary {
|
||||
return mPicker;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class HomeAssistantService {
|
||||
break;
|
||||
|
||||
case 200:
|
||||
// System.println("HomeAssistantService onReturnCall(): Service executed.");
|
||||
// System.println("HomeAssistantService onReturnCall(): Action executed.");
|
||||
getApp().forceStatusUpdates();
|
||||
var d = data as Lang.Array;
|
||||
var toast = WatchUi.loadResource($.Rez.Strings.Executed) as Lang.String;
|
||||
@@ -118,13 +118,13 @@ class HomeAssistantService {
|
||||
}
|
||||
}
|
||||
|
||||
//! Invoke a service call for a menu item.
|
||||
//! Invoke a action call for a menu item.
|
||||
//!
|
||||
//! @param service The Home Assistant service to be run, e.g. from the JSON `service` field.
|
||||
//! @param data Data to be supplied to the service call.
|
||||
//! @param action The Home Assistant action to be run, e.g. from the JSON `action` field.
|
||||
//! @param data Data to be supplied to the action call.
|
||||
//
|
||||
function call(
|
||||
service as Lang.String,
|
||||
action as Lang.String,
|
||||
data as Lang.Dictionary?,
|
||||
exit as Lang.Boolean
|
||||
) as Void {
|
||||
@@ -136,8 +136,8 @@ class HomeAssistantService {
|
||||
WatchUi.pushView(
|
||||
dialog,
|
||||
new WifiLteExecutionConfirmDelegate({
|
||||
:type => "service",
|
||||
:service => service,
|
||||
:type => "action",
|
||||
:action => action,
|
||||
:data => data,
|
||||
:exit => exit,
|
||||
}, dialog),
|
||||
@@ -151,9 +151,9 @@ class HomeAssistantService {
|
||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.NoInternet) as Lang.String);
|
||||
} else {
|
||||
// Can't use null for substring() parameters due to API version level.
|
||||
var url = Settings.getApiUrl() + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, service.length());
|
||||
var url = Settings.getApiUrl() + "/services/" + action.substring(0, action.find(".")) + "/" + action.substring(action.find(".")+1, action.length());
|
||||
// System.println("HomeAssistantService call() URL=" + url);
|
||||
// System.println("HomeAssistantService call() service=" + service);
|
||||
// System.println("HomeAssistantService call() action=" + action);
|
||||
|
||||
var entity_id = "";
|
||||
if (data != null) {
|
||||
|
||||
@@ -50,9 +50,9 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
var url;
|
||||
|
||||
switch (type) {
|
||||
case "service":
|
||||
var service = WifiLteExecutionConfirmDelegate.mCommandData[:service];
|
||||
url = Settings.getApiUrl() + "/services/" + service.substring(0, service.find(".")) + "/" + service.substring(service.find(".")+1, service.length());
|
||||
case "action":
|
||||
var action = WifiLteExecutionConfirmDelegate.mCommandData[:action];
|
||||
url = Settings.getApiUrl() + "/services/" + action.substring(0, action.find(".")) + "/" + action.substring(action.find(".")+1, action.length());
|
||||
var entity_id = "";
|
||||
if (data != null) {
|
||||
entity_id = data.get("entity_id");
|
||||
@@ -78,7 +78,7 @@ class HomeAssistantSyncDelegate extends Communications.SyncDelegate {
|
||||
private function performRequest(url as Lang.String, data as Lang.Dictionary?) {
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
data, // May include {"entity_id": xxxx} for service calls
|
||||
data, // May include {"entity_id": xxxx} for action calls
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => Settings.augmentHttpHeaders({
|
||||
|
||||
@@ -21,7 +21,7 @@ using Toybox.Graphics;
|
||||
//
|
||||
class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
private var mHomeAssistantService as HomeAssistantService;
|
||||
private var mService as Lang.String?;
|
||||
private var mAction as Lang.String?;
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mExit as Lang.Boolean;
|
||||
private var mPin as Lang.Boolean;
|
||||
@@ -31,11 +31,11 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
//!
|
||||
//! @param label Menu item label.
|
||||
//! @param template Menu item template.
|
||||
//! @param service Menu item service.
|
||||
//! @param data Data to supply to the service call.
|
||||
//! @param exit Should the service call complete and then exit?
|
||||
//! @param confirm Should the service call be confirmed to avoid accidental invocation?
|
||||
//! @param pin Should the service call be protected with a PIN for some low level of security?
|
||||
//! @param action Menu item action.
|
||||
//! @param data Data to supply to the action call.
|
||||
//! @param exit Should the action call complete and then exit?
|
||||
//! @param confirm Should the action call be confirmed to avoid accidental invocation?
|
||||
//! @param pin Should the action call be protected with a PIN for some low level of security?
|
||||
//! @param icon Icon to use for the menu item.
|
||||
//! @param options Menu item options to be passed on, including both SDK and menu options, e.g. exit, confirm & pin.
|
||||
//! @param haService Shared Home Assistant service object that will perform the required call. Only
|
||||
@@ -44,7 +44,7 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
function initialize(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
template as Lang.String,
|
||||
service as Lang.String?,
|
||||
action as Lang.String?,
|
||||
data as Lang.Dictionary?,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment,
|
||||
@@ -65,16 +65,16 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
);
|
||||
|
||||
mHomeAssistantService = haService;
|
||||
mService = service;
|
||||
mAction = action;
|
||||
mData = data;
|
||||
mExit = options[:exit];
|
||||
mConfirm = options[:confirm];
|
||||
mPin = options[:pin];
|
||||
}
|
||||
|
||||
//! Call a Home Assistant service only after checks have been done for confirmation or PIN entry.
|
||||
//! Call a Home Assistant action only after checks have been done for confirmation or PIN entry.
|
||||
//
|
||||
function callService() as Void {
|
||||
function callAction() as Void {
|
||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||
if (mPin && hasTouchScreen) {
|
||||
var pin = Settings.getPin();
|
||||
@@ -100,10 +100,10 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
WatchUi.pushView(
|
||||
dialog,
|
||||
new WifiLteExecutionConfirmDelegate({
|
||||
:type => "service",
|
||||
:service => mService,
|
||||
:data => mData,
|
||||
:exit => mExit,
|
||||
:type => "action",
|
||||
:action => mAction,
|
||||
:data => mData,
|
||||
:exit => mExit,
|
||||
}, dialog),
|
||||
WatchUi.SLIDE_LEFT
|
||||
);
|
||||
@@ -128,9 +128,9 @@ class HomeAssistantTapMenuItem extends HomeAssistantMenuItem {
|
||||
//!
|
||||
//! @param b Ignored. It is included in order to match the expected function prototype of the callback method.
|
||||
//
|
||||
public function onConfirm(b as Lang.Boolean) as Void {
|
||||
if (mService != null) {
|
||||
mHomeAssistantService.call(mService, mData, mExit);
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
if (mAction != null) {
|
||||
mHomeAssistantService.call(mAction, mData, mExit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
//!
|
||||
//! @param label Menu item label.
|
||||
//! @param template Menu item template.
|
||||
//! @param data Data to supply to the service call.
|
||||
//! @param data Data to supply to the action call.
|
||||
//! @param options Menu item options to be passed on, including both SDK and menu options, e.g. exit, confirm & pin.
|
||||
//
|
||||
function initialize(
|
||||
@@ -72,10 +72,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
//
|
||||
private function setUiToggle(state as Null or Lang.String) as Void {
|
||||
if (state != null) {
|
||||
if (state.equals("on") && !isEnabled()) {
|
||||
setEnabled(true);
|
||||
} else if (state.equals("off") && isEnabled()) {
|
||||
if (state.equals("unavailable" || "unknown")) {
|
||||
return;
|
||||
} else if ((state.equals("off") || state.equals("closed")) && isEnabled()) {
|
||||
setEnabled(false);
|
||||
} else if (!isEnabled()) {
|
||||
setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,7 +297,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
|
||||
//! Call a Home Assistant service only after checks have been done for confirmation or PIN entry.
|
||||
//
|
||||
function callService(b as Lang.Boolean) as Void {
|
||||
function callAction(b as Lang.Boolean) as Void {
|
||||
var hasTouchScreen = System.getDeviceSettings().isTouchScreen;
|
||||
if (mPin && hasTouchScreen) {
|
||||
// Undo the toggle
|
||||
@@ -377,7 +379,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
//! @param id The entity ID, e.g., `"switch.kitchen"`.
|
||||
//! @param s Desired state: `true` for "turn_on", `false` for "turn_off".
|
||||
//!
|
||||
//! @return Full service URL string.
|
||||
//! @return Full action URL string.
|
||||
//
|
||||
private static function getUrl(id as Lang.String, s as Lang.Boolean) as Lang.String {
|
||||
var url = Settings.getApiUrl() + "/services/";
|
||||
|
||||
@@ -47,7 +47,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
var content = items[i].get("content") as Lang.String?;
|
||||
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 action = items[i].get("service") as Lang.String?; // Deprecated schema
|
||||
var confirm = false as Lang.Boolean?;
|
||||
var pin = false as Lang.Boolean?;
|
||||
var data = null as Lang.Dictionary?;
|
||||
@@ -60,7 +60,10 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
exit = items[i].get("exit"); // Optional
|
||||
}
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
action = tap_action.get("service"); // Deprecated
|
||||
if (tap_action.get("action") != null) {
|
||||
action = tap_action.get("action"); // Optional
|
||||
}
|
||||
data = tap_action.get("data"); // Optional
|
||||
if (tap_action.get("confirm") != null) {
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
@@ -81,12 +84,12 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
:pin => pin
|
||||
}
|
||||
));
|
||||
} else if (type.equals("tap") && service != null) {
|
||||
} else if (type.equals("tap") && action != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(
|
||||
name,
|
||||
entity,
|
||||
content,
|
||||
service,
|
||||
action,
|
||||
data,
|
||||
{
|
||||
:exit => exit,
|
||||
@@ -103,7 +106,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
name,
|
||||
entity,
|
||||
content,
|
||||
service,
|
||||
action,
|
||||
data,
|
||||
{
|
||||
:exit => false,
|
||||
@@ -117,7 +120,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
name,
|
||||
entity,
|
||||
content,
|
||||
service,
|
||||
action,
|
||||
data,
|
||||
{
|
||||
:exit => exit,
|
||||
@@ -126,31 +129,26 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
}
|
||||
));
|
||||
}
|
||||
} else if (type.equals("numeric") && service != null) {
|
||||
if (tap_action != null) {
|
||||
var picker = tap_action.get("picker") as Lang.Dictionary?;
|
||||
if (picker != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().numeric(
|
||||
name,
|
||||
entity,
|
||||
content,
|
||||
service,
|
||||
picker,
|
||||
{
|
||||
:exit => exit,
|
||||
:confirm => confirm,
|
||||
:pin => pin
|
||||
}
|
||||
));
|
||||
} else if (type.equals("numeric") && action != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().numeric(
|
||||
name,
|
||||
entity,
|
||||
content,
|
||||
action,
|
||||
data,
|
||||
{
|
||||
:exit => exit,
|
||||
:confirm => confirm,
|
||||
:pin => 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,
|
||||
action,
|
||||
data,
|
||||
{
|
||||
:exit => false,
|
||||
@@ -172,6 +170,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
//!
|
||||
//! @return An array of menu items that need to be updated periodically to reflect the latest Home Assistant state.
|
||||
//
|
||||
|
||||
function getItemsToUpdate() as Lang.Array<HomeAssistantToggleMenuItem or HomeAssistantTapMenuItem or HomeAssistantGroupMenuItem or HomeAssistantNumericMenuItem or Null> {
|
||||
var fullList = [];
|
||||
var lmi = mItems as Lang.Array<WatchUi.MenuItem>;
|
||||
@@ -207,8 +206,8 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
//! Called when this View is brought to the foreground. Restore
|
||||
//! the state of this View and prepare it to be shown. This includes
|
||||
//! loading resources into memory.
|
||||
//
|
||||
function onShow() as Void {}
|
||||
|
||||
}
|
||||
|
||||
//! Delegate for the HomeAssistantView.
|
||||
@@ -267,22 +266,27 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
if (item instanceof HomeAssistantToggleMenuItem) {
|
||||
var haToggleItem = item as HomeAssistantToggleMenuItem;
|
||||
// System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
|
||||
haToggleItem.callService(haToggleItem.isEnabled());
|
||||
haToggleItem.callAction(haToggleItem.isEnabled());
|
||||
} else if (item instanceof HomeAssistantTapMenuItem) {
|
||||
var haItem = item as HomeAssistantTapMenuItem;
|
||||
// System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
haItem.callService();
|
||||
haItem.callAction();
|
||||
} else if (item instanceof HomeAssistantNumericMenuItem) {
|
||||
var haItem = item as HomeAssistantNumericMenuItem;
|
||||
// System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
// create new view to select new value
|
||||
var mPickerFactory = new HomeAssistantNumericFactory((haItem as HomeAssistantNumericMenuItem).getPicker());
|
||||
var mPicker = new HomeAssistantNumericPicker(mPickerFactory,haItem);
|
||||
|
||||
var mPickerFactory = new HomeAssistantNumericFactory(haItem.getData());
|
||||
|
||||
var mPicker = new HomeAssistantNumericPicker(mPickerFactory,haItem);
|
||||
var mPickerDelegate = new HomeAssistantNumericPickerDelegate(mPicker);
|
||||
WatchUi.pushView(mPicker,mPickerDelegate,WatchUi.SLIDE_LEFT);
|
||||
} else if (item instanceof HomeAssistantGroupMenuItem) {
|
||||
var haMenuItem = item as HomeAssistantGroupMenuItem;
|
||||
// System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT);
|
||||
// } else {
|
||||
// System.println(item.getLabel() + " " + item.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ using Toybox.Timer;
|
||||
class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
public static var mCommandData as {
|
||||
:type as Lang.String,
|
||||
:service as Lang.String?,
|
||||
:action as Lang.String?,
|
||||
:data as Lang.Dictionary?,
|
||||
:url as Lang.String?,
|
||||
:id as Lang.Number?,
|
||||
@@ -40,8 +40,8 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
//!
|
||||
//! @param options A dictionary describing the command to be executed:<br>
|
||||
//! `{`<br>
|
||||
//!   `:type: as Lang.String,` // The command type, either `"service"` or `"entity"`.<br>
|
||||
//!   `:service: as Lang.String?,` // (For type `"service"`) The Home Assistant service to call (e.g., "light.turn_on").<br>
|
||||
//!   `:type: as Lang.String,` // The command type, either `"action"` or `"entity"`.<br>
|
||||
//!   `:action: as Lang.String?,` // (For type `"action"`) The Home Assistant action to call (e.g., "light.turn_on").<br>
|
||||
//!   `:url: as Lang.Dictionary?,` // (For type `"entity"`) The full Home Assistant entity API URL.<br>
|
||||
//!   `:callback: as Lang.String?,` // (For type `"entity"`) A callback method (Method<data as Dictionary>) to handle the response.<br>
|
||||
//!   `:data: as Lang.Method?,` // (Optional) A dictionary of data to send with the request.<br>
|
||||
@@ -52,7 +52,7 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
function initialize(
|
||||
cOptions as {
|
||||
:type as Lang.String,
|
||||
:service as Lang.String?,
|
||||
:action as Lang.String?,
|
||||
:data as Lang.Dictionary?,
|
||||
:url as Lang.String?,
|
||||
:callback as Lang.Method?,
|
||||
@@ -73,7 +73,7 @@ class WifiLteExecutionConfirmDelegate extends WatchUi.ConfirmationDelegate {
|
||||
mConfirmationView = view;
|
||||
mCommandData = {
|
||||
:type => cOptions[:type],
|
||||
:service => cOptions[:service],
|
||||
:action => cOptions[:action],
|
||||
:data => cOptions[:data],
|
||||
:url => cOptions[:url],
|
||||
:callback => cOptions[:callback],
|
||||
|
||||
@@ -9,92 +9,80 @@
|
||||
// tested on a Venu 2 device. The source code is provided at:
|
||||
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
||||
//
|
||||
// P A Abbey & J D Abbey & @thmichel, 13 October 2025
|
||||
// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023
|
||||
//
|
||||
//------------------------------------------------------------
|
||||
|
||||
using Toybox.Graphics;
|
||||
using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
//! Factory that controls which numbers can be picked
|
||||
class HomeAssistantNumericFactory extends WatchUi.PickerFactory {
|
||||
// define default values in case not contained in data
|
||||
private var mStart as Lang.Float = 0.0;
|
||||
private var mStop as Lang.Float = 100.0;
|
||||
private var mStep as Lang.Float = 1.0;
|
||||
private var mFormatString as Lang.String = "%d";
|
||||
private var mStart as Lang.Float = 0.0;
|
||||
private var mStop as Lang.Float = 100.0;
|
||||
private var mStep as Lang.Float = 1.0;
|
||||
private var mFormatString as Lang.String = "%.2f";
|
||||
|
||||
//! Class Constructor
|
||||
//
|
||||
public function initialize(picker as Lang.Dictionary) {
|
||||
//!
|
||||
public function initialize(data as Lang.Dictionary) {
|
||||
PickerFactory.initialize();
|
||||
|
||||
// Get values from data
|
||||
var val = picker["min"];
|
||||
|
||||
var val = data.get("start");
|
||||
if (val != null) {
|
||||
mStart = val.toString().toFloat();
|
||||
}
|
||||
val = picker["max"];
|
||||
val = data.get("stop");
|
||||
if (val != null) {
|
||||
mStop = val.toString().toFloat();
|
||||
}
|
||||
val = picker["step"];
|
||||
val = data.get("step");
|
||||
if (val != null) {
|
||||
mStep = val.toString().toFloat();
|
||||
}
|
||||
if (mStep > 0.0) {
|
||||
var s = mStep;
|
||||
var dp = 0;
|
||||
while (s < 1.0) {
|
||||
s *= 10;
|
||||
dp++;
|
||||
// Assigned inside the loop and in each iteration to avoid clobbering the default '%d'.
|
||||
mFormatString = "%." + dp.toString() + "f";
|
||||
}
|
||||
} else {
|
||||
// The JSON menu definition defined a step size of 0, revert to the default.
|
||||
mStep = 1.0;
|
||||
}
|
||||
val = data.get("formatString");
|
||||
if (val != null) {
|
||||
mFormatString = val.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//! Get the index of a number item
|
||||
//! @param value The number to get the index of
|
||||
//! @return The index of the number
|
||||
public function getIndex(value as Float) as Number {
|
||||
return ((value / mStep) - mStart).toNumber();
|
||||
}
|
||||
|
||||
//! Generate a Drawable instance for an item
|
||||
//!
|
||||
//! @param index The item index
|
||||
//! @param selected true if the current item is selected, false otherwise
|
||||
//! @return Drawable for the item
|
||||
//
|
||||
public function getDrawable(
|
||||
index as Lang.Number,
|
||||
selected as Lang.Boolean
|
||||
) as WatchUi.Drawable? {
|
||||
public function getDrawable(index as Number, selected as Boolean) as Drawable? {
|
||||
var value = getValue(index);
|
||||
var text = "No item";
|
||||
if (value instanceof Lang.Float) {
|
||||
text = value.format(mFormatString);
|
||||
}
|
||||
return new WatchUi.Text({
|
||||
:text => text,
|
||||
:color => Graphics.COLOR_WHITE,
|
||||
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
|
||||
:locY => WatchUi.LAYOUT_VALIGN_CENTER
|
||||
});
|
||||
return new WatchUi.Text({:text=>text, :color=>Graphics.COLOR_WHITE,
|
||||
:locX=>WatchUi.LAYOUT_HALIGN_CENTER, :locY=>WatchUi.LAYOUT_VALIGN_CENTER});
|
||||
}
|
||||
|
||||
//! Get the value of the item at the given index
|
||||
//!
|
||||
//! @param index Index of the item to get the value of
|
||||
//! @return Value of the item
|
||||
//
|
||||
public function getValue(index as Lang.Number) as Lang.Object? {
|
||||
public function getValue(index as Number) as Object? {
|
||||
return mStart + (index * mStep);
|
||||
}
|
||||
|
||||
//! Get the number of picker items
|
||||
//!
|
||||
//! @return Number of items
|
||||
//
|
||||
public function getSize() as Lang.Number {
|
||||
public function getSize() as Number {
|
||||
return ((mStop - mStart) / mStep).toNumber() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
// tested on a Venu 2 device. The source code is provided at:
|
||||
// https://github.com/house-of-abbey/GarminHomeAssistant.
|
||||
//
|
||||
// P A Abbey & J D Abbey & @thmichel, 13 October 2025
|
||||
// P A Abbey & J D Abbey & Someone0nEarth, 31 October 2023
|
||||
//
|
||||
//------------------------------------------------------------
|
||||
|
||||
@@ -20,79 +20,83 @@ using Toybox.System;
|
||||
using Toybox.WatchUi;
|
||||
|
||||
//! Picker that allows the user to choose a float value
|
||||
//
|
||||
class HomeAssistantNumericPicker extends WatchUi.Picker {
|
||||
|
||||
private var mFactory as HomeAssistantNumericFactory;
|
||||
private var mItem as HomeAssistantNumericMenuItem;
|
||||
|
||||
//! Constructor
|
||||
//
|
||||
public function initialize(
|
||||
factory as HomeAssistantNumericFactory,
|
||||
haItem as HomeAssistantNumericMenuItem
|
||||
) {
|
||||
mItem = haItem;
|
||||
var picker = mItem.getPicker();
|
||||
var min = (picker.get("min") as Lang.String).toFloat();
|
||||
var step = (picker.get("step") as Lang.String).toFloat();
|
||||
var val = haItem.getValue();
|
||||
public function initialize(factory as HomeAssistantNumericFactory, haItem as HomeAssistantNumericMenuItem) {
|
||||
|
||||
if (min == null) {
|
||||
min = 0.0;
|
||||
}
|
||||
if (step == null) {
|
||||
step = 1.0;
|
||||
}
|
||||
mFactory = factory;
|
||||
|
||||
|
||||
var pickerOptions = {:pattern=>[mFactory]};
|
||||
mItem=haItem;
|
||||
|
||||
|
||||
var data = mItem.getData();
|
||||
|
||||
var start = 0.0;
|
||||
var val = data.get("start");
|
||||
if (val != null) {
|
||||
start = val.toString().toFloat();
|
||||
}
|
||||
var step = 1.0;
|
||||
val = data.get("step");
|
||||
if (val != null) {
|
||||
step = val.toString().toFloat();
|
||||
}
|
||||
val = haItem.getSubLabel().toFloat();
|
||||
var index = ((val -start) / step).toNumber();
|
||||
|
||||
pickerOptions[:defaults] =[index];
|
||||
|
||||
var title = new WatchUi.Text({:text=>haItem.getLabel(), :locX=>WatchUi.LAYOUT_HALIGN_CENTER,
|
||||
:locY=>WatchUi.LAYOUT_VALIGN_BOTTOM});
|
||||
pickerOptions[:title] = title;
|
||||
|
||||
|
||||
Picker.initialize(pickerOptions);
|
||||
|
||||
WatchUi.Picker.initialize({
|
||||
:title => new WatchUi.Text({
|
||||
:text => haItem.getLabel(),
|
||||
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
|
||||
:locY => WatchUi.LAYOUT_VALIGN_BOTTOM
|
||||
}),
|
||||
:pattern => [factory],
|
||||
:defaults => [((val - min) / step).toNumber()]
|
||||
});
|
||||
}
|
||||
|
||||
//! Called when the user has completed picking.
|
||||
//!
|
||||
|
||||
//! Get whether the user is done picking
|
||||
//! @param value Value user selected
|
||||
//! @return true if user is done, false otherwise
|
||||
//
|
||||
public function onConfirm(value as Lang.Number or Lang.Float) as Void {
|
||||
public function onConfirm(value as Lang.String) as Void {
|
||||
mItem.setValue(value);
|
||||
mItem.callService();
|
||||
mItem.callAction();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//! Responds to a numeric picker selection or cancellation.
|
||||
//
|
||||
//! Responds to a numeric picker selection or cancellation
|
||||
class HomeAssistantNumericPickerDelegate extends WatchUi.PickerDelegate {
|
||||
private var mPicker as HomeAssistantNumericPicker;
|
||||
|
||||
//! Constructor
|
||||
//
|
||||
public function initialize(picker as HomeAssistantNumericPicker) {
|
||||
PickerDelegate.initialize();
|
||||
mPicker = picker;
|
||||
}
|
||||
|
||||
//! Handle a cancel event from the picker
|
||||
//!
|
||||
//! @return true if handled, false otherwise
|
||||
//
|
||||
public function onCancel() as Lang.Boolean {
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Handle a confirm event from the picker
|
||||
//!
|
||||
//! @param values The values chosen in the picker
|
||||
//! @return true if handled, false otherwise
|
||||
//
|
||||
public function onAccept(values as Lang.Array) as Lang.Boolean {
|
||||
mPicker.onConfirm(values[0]);
|
||||
var chosenValue = values[0].toString();
|
||||
mPicker.onConfirm(chosenValue);
|
||||
WatchUi.popView(WatchUi.SLIDE_RIGHT);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
30
web/main.js
30
web/main.js
@@ -101,12 +101,12 @@ async function get_areas() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services in HomeAssistant.
|
||||
* Get all actions in HomeAssistant.
|
||||
* @returns {Promise<[string, { name: string; description: string; fields:
|
||||
* Record<string, { name: string; description: string; example: string;
|
||||
* selector: unknown; required?: boolean }> }][]>} [id, data]
|
||||
*/
|
||||
async function get_services() {
|
||||
async function get_actions() {
|
||||
try {
|
||||
const res = await fetch(api_url + '/services', {
|
||||
method: 'GET',
|
||||
@@ -122,15 +122,15 @@ async function get_services() {
|
||||
document.querySelector('#api_url').classList.remove('invalid');
|
||||
document.querySelector('#api_token').classList.remove('invalid');
|
||||
const data = await res.json();
|
||||
const services = [];
|
||||
const actions = [];
|
||||
for (const d of data) {
|
||||
for (const service in d.services) {
|
||||
services.push([`${d.domain}.${service}`, d.services[service]]);
|
||||
for (const action in d.services) {
|
||||
actions.push([`${d.domain}.${action}`, d.services[action]]);
|
||||
}
|
||||
}
|
||||
return services;
|
||||
return actions;
|
||||
} catch (e) {
|
||||
console.error('Error fetching services:', e);
|
||||
console.error('Error fetching actions:', e);
|
||||
document.querySelector('#api_url').classList.add('invalid');
|
||||
return [];
|
||||
}
|
||||
@@ -154,11 +154,11 @@ async function get_schema() {
|
||||
* @param {Record<string, string>} areas
|
||||
* @param {[string, { name: string; description: string; fields:
|
||||
* Record<string, { name: string; description: string; example: string;
|
||||
* selector: unknown; required?: boolean }> }][]} services
|
||||
* selector: unknown; required?: boolean }> }][]} actions
|
||||
* @param {{}} schema
|
||||
* @returns {Promise<{}>}
|
||||
*/
|
||||
async function generate_schema(entities, devices, areas, services, schema) {
|
||||
async function generate_schema(entities, devices, areas, actions, schema) {
|
||||
schema.$defs.entity = {
|
||||
enum: Object.keys(entities),
|
||||
};
|
||||
@@ -170,7 +170,7 @@ async function generate_schema(entities, devices, areas, services, schema) {
|
||||
};
|
||||
|
||||
const oneOf = [];
|
||||
for (const [id, data] of services) {
|
||||
for (const [id, data] of actions) {
|
||||
const i_properties = {
|
||||
service: {
|
||||
title: data.name,
|
||||
@@ -428,22 +428,22 @@ let entities;
|
||||
let devices;
|
||||
/** @type {Awaited<ReturnType<typeof get_areas>>} */
|
||||
let areas;
|
||||
/** @type {Awaited<ReturnType<typeof get_services>>} */
|
||||
let services;
|
||||
/** @type {Awaited<ReturnType<typeof get_actions>>} */
|
||||
let actions;
|
||||
let schema;
|
||||
async function loadSchema() {
|
||||
[entities, devices, areas, services, schema] = await Promise.all([
|
||||
[entities, devices, areas, actions, schema] = await Promise.all([
|
||||
get_entities(),
|
||||
get_devices(),
|
||||
get_areas(),
|
||||
get_services(),
|
||||
get_actions(),
|
||||
get_schema(),
|
||||
]);
|
||||
if (window.makeMarkers) {
|
||||
window.makeMarkers();
|
||||
}
|
||||
try {
|
||||
schema = await generate_schema(entities, devices, areas, services, schema);
|
||||
schema = await generate_schema(entities, devices, areas, actions, schema);
|
||||
} catch {}
|
||||
console.log(schema);
|
||||
if (window.m && window.modelUri) {
|
||||
|
||||
Reference in New Issue
Block a user