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