mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-17 20:08:33 +00:00
Merge branch 'main' of ssh://github.com/house-of-abbey/GarminHomeAssistant
This commit is contained in:
@ -8,12 +8,23 @@
|
|||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
"item": {
|
"toggle": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"entity": { "$ref": "#/$defs/entity" },
|
"entity": { "$ref": "#/$defs/entity" },
|
||||||
"name": { "type": "string" },
|
"name": { "type": "string" },
|
||||||
"type": { "enum": ["toggle", "tap"] }
|
"type": { "const": "toggle" }
|
||||||
|
},
|
||||||
|
"required": ["entity", "name", "type"],
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"tap": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"entity": { "$ref": "#/$defs/entity" },
|
||||||
|
"name": { "type": "string" },
|
||||||
|
"type": { "const": "tap" },
|
||||||
|
"service": { "$ref": "#/$defs/entity" }
|
||||||
},
|
},
|
||||||
"required": ["entity", "name", "type"],
|
"required": ["entity", "name", "type"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
@ -33,7 +44,11 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"oneOf": [{ "$ref": "#/$defs/item" }, { "$ref": "#/$defs/menu" }]
|
"oneOf": [
|
||||||
|
{ "$ref": "#/$defs/toggle" },
|
||||||
|
{ "$ref": "#/$defs/tap" },
|
||||||
|
{ "$ref": "#/$defs/menu" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
//
|
//
|
||||||
// Menu button that triggers a script.
|
// Menu button that triggers a service.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -26,18 +26,20 @@ using Toybox.Application.Properties;
|
|||||||
class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
||||||
hidden var api_key = Properties.getValue("api_key");
|
hidden var api_key = Properties.getValue("api_key");
|
||||||
hidden var strNoInternet as Lang.String;
|
hidden var strNoInternet as Lang.String;
|
||||||
|
hidden var mService as Lang.String or Null;
|
||||||
|
|
||||||
function initialize(
|
function initialize(
|
||||||
label as Lang.String or Lang.Symbol,
|
label as Lang.String or Lang.Symbol,
|
||||||
subLabel as Lang.String or Lang.Symbol or Null,
|
subLabel as Lang.String or Lang.Symbol or Null,
|
||||||
identifier as Lang.Object or Null,
|
identifier as Lang.Object or Null,
|
||||||
|
service as Lang.String or Null,
|
||||||
options as {
|
options as {
|
||||||
:alignment as WatchUi.MenuItem.Alignment,
|
:alignment as WatchUi.MenuItem.Alignment,
|
||||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
||||||
} or Null
|
} or Null
|
||||||
) {
|
) {
|
||||||
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
|
||||||
|
mService = service;
|
||||||
WatchUi.MenuItem.initialize(
|
WatchUi.MenuItem.initialize(
|
||||||
label,
|
label,
|
||||||
subLabel,
|
subLabel,
|
||||||
@ -99,6 +101,7 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
|||||||
// Updated SDK and got a new error
|
// Updated SDK and got a new error
|
||||||
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
// ERROR: venu: Cannot find symbol ':substring' on type 'PolyType<Null or $.Toybox.Lang.Object>'.
|
||||||
var id = mIdentifier as Lang.String;
|
var id = mIdentifier as Lang.String;
|
||||||
|
if (mService == null) {
|
||||||
var url = (Properties.getValue("api_url") as Lang.String) + "/services/" + id.substring(0, id.find(".")) + "/" + id.substring(id.find(".")+1, id.length());
|
var url = (Properties.getValue("api_url") as Lang.String) + "/services/" + id.substring(0, id.find(".")) + "/" + id.substring(id.find(".")+1, id.length());
|
||||||
if (Globals.debug) {
|
if (Globals.debug) {
|
||||||
System.println("HomeAssistantMenuItem execScript() URL=" + url);
|
System.println("HomeAssistantMenuItem execScript() URL=" + url);
|
||||||
@ -110,6 +113,21 @@ class HomeAssistantMenuItem extends WatchUi.MenuItem {
|
|||||||
options,
|
options,
|
||||||
method(:onReturnExecScript)
|
method(:onReturnExecScript)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
var url = Properties.getValue("api_url") + "/services/" + mService.substring(0, mService.find(".")) + "/" + mService.substring(mService.find(".")+1, null);
|
||||||
|
if (Globals.debug) {
|
||||||
|
System.println("URL=" + url);
|
||||||
|
System.println("mIdentifier=" + mIdentifier);
|
||||||
|
}
|
||||||
|
Communications.makeWebRequest(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
"entity_id" => id
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
method(:onReturnSetState)
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Globals.debug) {
|
if (Globals.debug) {
|
||||||
System.println("HomeAssistantMenuItem Note - execScript(): No Internet connection, skipping API call.");
|
System.println("HomeAssistantMenuItem Note - execScript(): No Internet connection, skipping API call.");
|
||||||
|
@ -53,6 +53,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
|||||||
var type = items[i].get("type") as Lang.String or Null;
|
var type = items[i].get("type") as Lang.String or Null;
|
||||||
var name = items[i].get("name") as Lang.String or Null;
|
var name = items[i].get("name") as Lang.String or Null;
|
||||||
var entity = items[i].get("entity") as Lang.String or Null;
|
var entity = items[i].get("entity") as Lang.String or Null;
|
||||||
|
var service = items[i].get("service") as Lang.String or Null;
|
||||||
if (type != null && name != null && entity != null) {
|
if (type != null && name != null && entity != null) {
|
||||||
if (type.equals("toggle")) {
|
if (type.equals("toggle")) {
|
||||||
addItem(
|
addItem(
|
||||||
@ -70,6 +71,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
|||||||
name,
|
name,
|
||||||
strMenuItemTap,
|
strMenuItemTap,
|
||||||
entity,
|
entity,
|
||||||
|
service,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user