Merge branch 'main' into 80-examples
@ -26,6 +26,15 @@
|
||||
"title": "Menu item type",
|
||||
"description": "One of 'tap', 'template', 'toggle' or 'group'.",
|
||||
"const": "toggle"
|
||||
},
|
||||
"tap_action": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"confirm": {
|
||||
"$ref": "#/$defs/confirm"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["entity", "name", "type"],
|
||||
@ -51,10 +60,10 @@
|
||||
"const": "template"
|
||||
},
|
||||
"tap_action": {
|
||||
"$ref": "#/$defs/action"
|
||||
"$ref": "#/$defs/tap_action"
|
||||
}
|
||||
},
|
||||
"required": ["name", "entity", "content", "type"],
|
||||
"required": ["name", "content", "type"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"tap": {
|
||||
@ -79,24 +88,27 @@
|
||||
"description": "Use 'tap_action' instead to mirror Home Assistant."
|
||||
},
|
||||
"tap_action": {
|
||||
"$ref": "#/$defs/action"
|
||||
"$ref": "#/$defs/tap_action"
|
||||
}
|
||||
},
|
||||
"oneOf": [
|
||||
{
|
||||
"required": ["entity", "name", "type", "service"]
|
||||
"required": ["name", "type", "service"]
|
||||
},
|
||||
{
|
||||
"required": ["entity", "name", "type", "tap_action"]
|
||||
"required": ["name", "type", "tap_action"]
|
||||
}
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"menu": {
|
||||
"group": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"entity": {
|
||||
"$ref": "#/$defs/entity"
|
||||
"$ref": "#/$defs/entity",
|
||||
"deprecated": true,
|
||||
"title": "Schema change:",
|
||||
"description": "'entity' is no longer necessary and should be removed."
|
||||
},
|
||||
"name": {
|
||||
"title": "Your familiar name",
|
||||
@ -114,7 +126,7 @@
|
||||
"$ref": "#/$defs/items"
|
||||
}
|
||||
},
|
||||
"required": ["entity", "name", "title", "type", "items"],
|
||||
"required": ["name", "title", "type", "items"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"items": {
|
||||
@ -131,7 +143,7 @@
|
||||
"$ref": "#/$defs/tap"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/menu"
|
||||
"$ref": "#/$defs/group"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -141,7 +153,7 @@
|
||||
"type": "string",
|
||||
"pattern": "^[^.]+\\.[^.]+$"
|
||||
},
|
||||
"action": {
|
||||
"tap_action": {
|
||||
"title": "Action",
|
||||
"description": "'confirm' field is optional.",
|
||||
"type": "object",
|
||||
@ -150,12 +162,19 @@
|
||||
"$ref": "#/$defs/entity"
|
||||
},
|
||||
"confirm": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Confirm the action before execution as a precaution."
|
||||
"$ref": "#/$defs/confirm"
|
||||
},
|
||||
"data": {
|
||||
"type": "object",
|
||||
"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"]
|
||||
},
|
||||
"confirm": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Confirm the action before execution as a precaution."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ for screen_size, icon_sizes in lookup.items():
|
||||
svg.attrs["width"] = lookup[screen_size][Half]
|
||||
svg.attrs["height"] = lookup[screen_size][Half]
|
||||
with open(output_dir + "/" + entry, "wb") as o:
|
||||
o.write(svg.encode("utf-8"))
|
||||
o.write(svg.encode("utf-8") + b"\n")
|
||||
elif entry.endswith(".xml"):
|
||||
print("Create file: ", entry.ljust(40) + " XML - Copy file")
|
||||
shutil.copyfile(input_dir + "/" + entry, output_dir + "/" + entry)
|
||||
|
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-18/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="18" viewBox="0 -960 960 960" width="18" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-21/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="21" viewBox="0 -960 960 960" width="21" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-24/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="24" viewBox="0 -960 960 960" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-26/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="26" viewBox="0 -960 960 960" width="26" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-28/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="28" viewBox="0 -960 960 960" width="28" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-30/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="30" viewBox="0 -960 960 960" width="30" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-32/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="32" viewBox="0 -960 960 960" width="32" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-38/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="38" viewBox="0 -960 960 960" width="38" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-42/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="42" viewBox="0 -960 960 960" width="42" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-46/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="46" viewBox="0 -960 960 960" width="46" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-48/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 -960 960 960" width="48"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -19,4 +19,5 @@
|
||||
<bitmap id="ErrorIcon" filename="error.svg"/>
|
||||
<bitmap id="GroupTypeIcon" filename="group_type.svg"/>
|
||||
<bitmap id="TapTypeIcon" filename="tap_type.svg"/>
|
||||
<bitmap id="InfoTypeIcon" filename="info_type.svg"/>
|
||||
</drawables>
|
||||
|
1
resources-icons-53/info_type.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg height="53" viewBox="0 -960 960 960" width="53" xmlns="http://www.w3.org/2000/svg"><path d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" fill="blue" stroke="blue"/></svg>
|
After Width: | Height: | Size: 543 B |
@ -28,14 +28,13 @@ using Toybox.WatchUi;
|
||||
using Toybox.Timer;
|
||||
|
||||
class Alert extends WatchUi.View {
|
||||
private static const bRadius = 10;
|
||||
private var mTimer as Timer.Timer;
|
||||
private var mTimeout as Lang.Number;
|
||||
private var mText as Lang.String;
|
||||
private var mFont as Graphics.FontType;
|
||||
private var mFgcolor as Graphics.ColorType;
|
||||
private var mBgcolor as Graphics.ColorType;
|
||||
private var mAntiAlias as Lang.Boolean = false;
|
||||
private static const scRadius = 10;
|
||||
private var mTimer as Timer.Timer;
|
||||
private var mTimeout as Lang.Number;
|
||||
private var mText as Lang.String;
|
||||
private var mFont as Graphics.FontType;
|
||||
private var mFgcolor as Graphics.ColorType;
|
||||
private var mBgcolor as Graphics.ColorType;
|
||||
|
||||
function initialize(params as Lang.Dictionary) {
|
||||
View.initialize();
|
||||
@ -65,10 +64,6 @@ class Alert extends WatchUi.View {
|
||||
mTimeout = 2000;
|
||||
}
|
||||
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
mAntiAlias = true;
|
||||
}
|
||||
|
||||
mTimer = new Timer.Timer();
|
||||
}
|
||||
|
||||
@ -88,7 +83,7 @@ class Alert extends WatchUi.View {
|
||||
var bX = (dc.getWidth() - bWidth) / 2;
|
||||
var bY = (dc.getHeight() - bHeight) / 2;
|
||||
|
||||
if (mAntiAlias) {
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
dc.setAntiAlias(true);
|
||||
}
|
||||
|
||||
@ -98,7 +93,7 @@ class Alert extends WatchUi.View {
|
||||
);
|
||||
dc.clear();
|
||||
dc.setColor(mBgcolor, mBgcolor);
|
||||
dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
|
||||
dc.fillRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
|
||||
|
||||
dc.setColor(mFgcolor, mBgcolor);
|
||||
for (var i = 0; i < 3; ++i) {
|
||||
@ -106,7 +101,7 @@ class Alert extends WatchUi.View {
|
||||
bY += i;
|
||||
bWidth -= (2 * i);
|
||||
bHeight -= (2 * i);
|
||||
dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, bRadius);
|
||||
dc.drawRoundedRectangle(bX, bY, bWidth, bHeight, scRadius);
|
||||
}
|
||||
|
||||
var tX = dc.getWidth() / 2;
|
||||
|
@ -36,16 +36,14 @@ using Toybox.Communications;
|
||||
using Toybox.Timer;
|
||||
|
||||
class ErrorView extends ScalableView {
|
||||
private var mText as Lang.String = "";
|
||||
private static const scErrorIconMargin as Lang.Float = 7f;
|
||||
private var mText as Lang.String = "";
|
||||
private var mDelegate as ErrorDelegate;
|
||||
private const cSettings as Lang.Dictionary = {
|
||||
:errorIconMargin => 7f
|
||||
};
|
||||
// Vertical spacing between the top of the face and the error icon
|
||||
private var mErrorIconMargin as Lang.Number;
|
||||
private var mErrorIcon;
|
||||
private var mTextArea as WatchUi.TextArea or Null;
|
||||
private var mAntiAlias as Lang.Boolean = false;
|
||||
private var mAntiAlias as Lang.Boolean = false;
|
||||
|
||||
private static var instance;
|
||||
private static var mShown as Lang.Boolean = false;
|
||||
@ -54,7 +52,7 @@ class ErrorView extends ScalableView {
|
||||
ScalableView.initialize();
|
||||
mDelegate = new ErrorDelegate(self);
|
||||
// Convert the settings from % of screen size to pixels
|
||||
mErrorIconMargin = pixelsForScreen(cSettings.get(:errorIconMargin) as Lang.Float);
|
||||
mErrorIconMargin = pixelsForScreen(scErrorIconMargin);
|
||||
mErrorIcon = Application.loadResource(Rez.Drawables.ErrorIcon) as Graphics.BitmapResource;
|
||||
if (Graphics.Dc has :setAntiAlias) {
|
||||
mAntiAlias = true;
|
||||
|
@ -86,8 +86,8 @@ class HomeAssistantApp extends Application.AppBase {
|
||||
|
||||
// Return the initial view of your application here
|
||||
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
mIsApp = true;
|
||||
mQuitTimer = new QuitTimer();
|
||||
RezStrings.update();
|
||||
mApiStatus = RezStrings.getChecking();
|
||||
mMenuStatus = RezStrings.getChecking();
|
||||
|
@ -34,12 +34,14 @@ class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
||||
}
|
||||
|
||||
class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
||||
private var mConfirmMethod;
|
||||
private var mTimer;
|
||||
private var mConfirmMethod as Method(state as Lang.Boolean) as Void;
|
||||
private var mTimer as Timer.Timer or Null;
|
||||
private var mState as Lang.Boolean;
|
||||
|
||||
function initialize(callback as Method() as Void) {
|
||||
function initialize(callback as Method(state as Lang.Boolean) as Void, state as Lang.Boolean) {
|
||||
WatchUi.ConfirmationDelegate.initialize();
|
||||
mConfirmMethod = callback;
|
||||
mState = state;
|
||||
var timeout = Settings.getConfirmTimeout(); // ms
|
||||
if (timeout > 0) {
|
||||
mTimer = new Timer.Timer();
|
||||
@ -49,11 +51,11 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
||||
|
||||
function onResponse(response) as Lang.Boolean {
|
||||
getApp().getQuitTimer().reset();
|
||||
if (mTimer) {
|
||||
if (mTimer != null) {
|
||||
mTimer.stop();
|
||||
}
|
||||
if (response == WatchUi.CONFIRM_YES) {
|
||||
mConfirmMethod.invoke();
|
||||
mConfirmMethod.invoke(mState);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -14,26 +14,27 @@
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Menu button with an icon that opens a sub-menu.
|
||||
// Menu button with an icon that opens a sub-menu, i.e. group.
|
||||
//
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
|
||||
class HomeAssistantViewMenuItem extends WatchUi.IconMenuItem {
|
||||
class HomeAssistantGroupMenuItem extends WatchUi.IconMenuItem {
|
||||
private var mMenu as HomeAssistantView;
|
||||
|
||||
function initialize(definition as Lang.Dictionary, icon as WatchUi.Drawable, options as {
|
||||
function initialize(
|
||||
definition as Lang.Dictionary,
|
||||
icon as WatchUi.Drawable,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment
|
||||
} or Null) {
|
||||
var label = definition.get("name") as Lang.String;
|
||||
var identifier = definition.get("entity") as Lang.String;
|
||||
|
||||
WatchUi.IconMenuItem.initialize(
|
||||
label,
|
||||
definition.get("name") as Lang.String,
|
||||
null,
|
||||
null,
|
||||
identifier,
|
||||
icon,
|
||||
options
|
||||
);
|
@ -26,6 +26,7 @@ class HomeAssistantMenuItemFactory {
|
||||
private var mMenuItemOptions as Lang.Dictionary;
|
||||
private var mTapTypeIcon as WatchUi.Bitmap;
|
||||
private var mGroupTypeIcon as WatchUi.Bitmap;
|
||||
private var mInfoTypeIcon as WatchUi.Bitmap;
|
||||
private var mHomeAssistantService as HomeAssistantService;
|
||||
|
||||
private static var instance;
|
||||
@ -47,6 +48,12 @@ class HomeAssistantMenuItemFactory {
|
||||
:locY => WatchUi.LAYOUT_VALIGN_CENTER
|
||||
});
|
||||
|
||||
mInfoTypeIcon = new WatchUi.Bitmap({
|
||||
:rezId => $.Rez.Drawables.InfoTypeIcon,
|
||||
:locX => WatchUi.LAYOUT_HALIGN_CENTER,
|
||||
:locY => WatchUi.LAYOUT_VALIGN_CENTER
|
||||
});
|
||||
|
||||
mHomeAssistantService = new HomeAssistantService();
|
||||
}
|
||||
|
||||
@ -57,46 +64,81 @@ class HomeAssistantMenuItemFactory {
|
||||
return instance;
|
||||
}
|
||||
|
||||
function toggle(label as Lang.String or Lang.Symbol, identifier as Lang.Object or Null) as WatchUi.MenuItem {
|
||||
function toggle(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity_id as Lang.String or Null,
|
||||
confirm as Lang.Boolean
|
||||
) as WatchUi.MenuItem {
|
||||
return new HomeAssistantToggleMenuItem(
|
||||
label,
|
||||
null,
|
||||
identifier,
|
||||
false,
|
||||
confirm,
|
||||
{ "entity_id" => entity_id },
|
||||
mMenuItemOptions
|
||||
);
|
||||
}
|
||||
|
||||
function template(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
identifier as Lang.Object or Null,
|
||||
template as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean
|
||||
function template_tap(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
template as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
) as WatchUi.MenuItem {
|
||||
if (entity != null) {
|
||||
if (data == null) {
|
||||
data = { "entity_id" => entity };
|
||||
} else {
|
||||
data.put("entity_id", entity);
|
||||
}
|
||||
}
|
||||
return new HomeAssistantTemplateMenuItem(
|
||||
label,
|
||||
identifier,
|
||||
template,
|
||||
service,
|
||||
confirm,
|
||||
data,
|
||||
mTapTypeIcon,
|
||||
mMenuItemOptions,
|
||||
mHomeAssistantService
|
||||
);
|
||||
}
|
||||
|
||||
function template_notap(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
template as Lang.String or Null
|
||||
) as WatchUi.MenuItem {
|
||||
return new HomeAssistantTemplateMenuItem(
|
||||
label,
|
||||
template,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
mInfoTypeIcon,
|
||||
mMenuItemOptions,
|
||||
mHomeAssistantService
|
||||
);
|
||||
}
|
||||
|
||||
function tap(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
identifier as Lang.Object or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean
|
||||
label as Lang.String or Lang.Symbol,
|
||||
entity as Lang.String or Null,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null
|
||||
) as WatchUi.MenuItem {
|
||||
return new HomeAssistantMenuItem(
|
||||
if (entity != null) {
|
||||
if (data == null) {
|
||||
data = { "entity_id" => entity };
|
||||
} else {
|
||||
data.put("entity_id", entity);
|
||||
}
|
||||
}
|
||||
return new HomeAssistantTapMenuItem(
|
||||
label,
|
||||
null,
|
||||
identifier,
|
||||
service,
|
||||
confirm,
|
||||
data,
|
||||
mTapTypeIcon,
|
||||
mMenuItemOptions,
|
||||
mHomeAssistantService
|
||||
@ -104,6 +146,6 @@ class HomeAssistantMenuItemFactory {
|
||||
}
|
||||
|
||||
function group(definition as Lang.Dictionary) as WatchUi.MenuItem {
|
||||
return new HomeAssistantViewMenuItem(definition, mGroupTypeIcon, mMenuItemOptions);
|
||||
return new HomeAssistantGroupMenuItem(definition, mGroupTypeIcon, mMenuItemOptions);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class HomeAssistantService {
|
||||
private var mHasToast as Lang.Boolean = false;
|
||||
private var mHasVibrate as Lang.Boolean = false;
|
||||
|
||||
function initialise() {
|
||||
function initialize() {
|
||||
if (WatchUi has :showToast) {
|
||||
mHasToast = true;
|
||||
}
|
||||
@ -38,8 +38,12 @@ class HomeAssistantService {
|
||||
|
||||
// Callback function after completing the POST request to call a service.
|
||||
//
|
||||
function onReturnCall(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String, context as Lang.Object) as Void {
|
||||
var identifier = context as Lang.String;
|
||||
function onReturnCall(
|
||||
responseCode as Lang.Number,
|
||||
data as Null or Lang.Dictionary or Lang.String,
|
||||
context as Lang.Object
|
||||
) as Void {
|
||||
var entity_id = context as Lang.String or Null;
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService onReturnCall() Response Code: " + responseCode);
|
||||
System.println("HomeAssistantService onReturnCall() Response Data: " + data);
|
||||
@ -95,7 +99,7 @@ class HomeAssistantService {
|
||||
var d = data as Lang.Array;
|
||||
var toast = RezStrings.getExecuted();
|
||||
for(var i = 0; i < d.size(); i++) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(identifier)) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(entity_id)) {
|
||||
toast = (d[i].get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String;
|
||||
}
|
||||
}
|
||||
@ -120,7 +124,10 @@ class HomeAssistantService {
|
||||
}
|
||||
}
|
||||
|
||||
function call(identifier as Lang.String, service as Lang.String) as Void {
|
||||
function call(
|
||||
service as Lang.String,
|
||||
data as Lang.Dictionary or Null
|
||||
) as Void {
|
||||
if (! System.getDeviceSettings().phoneConnected) {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantService call(): No Phone connection, skipping API call.");
|
||||
@ -138,11 +145,15 @@ class HomeAssistantService {
|
||||
System.println("HomeAssistantService call() URL=" + url);
|
||||
System.println("HomeAssistantService call() service=" + service);
|
||||
}
|
||||
|
||||
var entity_id = data.get("entity_id");
|
||||
if (entity_id == null) {
|
||||
entity_id = "";
|
||||
}
|
||||
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
{
|
||||
"entity_id" => identifier
|
||||
},
|
||||
data, // Includes {"entity_id": xxxx}
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
@ -150,7 +161,7 @@ class HomeAssistantService {
|
||||
"Authorization" => "Bearer " + Settings.getApiKey()
|
||||
},
|
||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
|
||||
:context => identifier
|
||||
:context => entity_id
|
||||
},
|
||||
method(:onReturnCall)
|
||||
);
|
||||
|
@ -22,17 +22,17 @@ using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
using Toybox.Graphics;
|
||||
|
||||
class HomeAssistantMenuItem extends WatchUi.IconMenuItem {
|
||||
class HomeAssistantTapMenuItem extends WatchUi.IconMenuItem {
|
||||
private var mHomeAssistantService as HomeAssistantService;
|
||||
private var mService as Lang.String;
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mData as Lang.Dictionary 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,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null,
|
||||
icon as Graphics.BitmapType or WatchUi.Drawable,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment
|
||||
@ -41,32 +41,33 @@ class HomeAssistantMenuItem extends WatchUi.IconMenuItem {
|
||||
) {
|
||||
WatchUi.IconMenuItem.initialize(
|
||||
label,
|
||||
subLabel,
|
||||
identifier,
|
||||
null,
|
||||
null,
|
||||
icon,
|
||||
options
|
||||
);
|
||||
|
||||
mHomeAssistantService = haService;
|
||||
mIdentifier = identifier;
|
||||
mService = service;
|
||||
mConfirm = confirm;
|
||||
mData = data;
|
||||
}
|
||||
|
||||
function callService() as Void {
|
||||
if (mConfirm) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm)),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else {
|
||||
onConfirm();
|
||||
mHomeAssistantService.call(mService, mData);
|
||||
}
|
||||
}
|
||||
|
||||
function onConfirm() as Void {
|
||||
mHomeAssistantService.call(mIdentifier as Lang.String, mService);
|
||||
// NB. Parameter 'b' is ignored
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
mHomeAssistantService.call(mService, mData);
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Rendering a Home Assistant Template.
|
||||
// Menu button that renders a Home Assistant Template, and optionally triggers a service.
|
||||
//
|
||||
// Reference:
|
||||
// * https://developers.home-assistant.io/docs/api/rest/
|
||||
@ -26,28 +26,30 @@ using Toybox.Lang;
|
||||
using Toybox.WatchUi;
|
||||
using Toybox.Graphics;
|
||||
|
||||
class HomeAssistantTemplateMenuItem extends WatchUi.MenuItem {
|
||||
class HomeAssistantTemplateMenuItem extends WatchUi.IconMenuItem {
|
||||
private var mHomeAssistantService as HomeAssistantService;
|
||||
private var mTemplate as Lang.String;
|
||||
private var mService as Lang.String or Null;
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mData as Lang.Dictionary or Null;
|
||||
|
||||
function initialize(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
identifier as Lang.Object or Null,
|
||||
template as Lang.String,
|
||||
service as Lang.String or Null,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null,
|
||||
icon as Graphics.BitmapType or WatchUi.Drawable,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment,
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
||||
:alignment as WatchUi.MenuItem.Alignment
|
||||
} or Null,
|
||||
haService as HomeAssistantService
|
||||
) {
|
||||
WatchUi.MenuItem.initialize(
|
||||
WatchUi.IconMenuItem.initialize(
|
||||
label,
|
||||
null,
|
||||
identifier,
|
||||
null,
|
||||
icon,
|
||||
options
|
||||
);
|
||||
|
||||
@ -55,23 +57,25 @@ class HomeAssistantTemplateMenuItem extends WatchUi.MenuItem {
|
||||
mTemplate = template;
|
||||
mService = service;
|
||||
mConfirm = confirm;
|
||||
mData = data;
|
||||
}
|
||||
|
||||
function callService() as Void {
|
||||
if (mConfirm) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm)),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), false),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else {
|
||||
onConfirm();
|
||||
onConfirm(false);
|
||||
}
|
||||
}
|
||||
|
||||
function onConfirm() as Void {
|
||||
// NB. Parameter 'b' is ignored
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
if (mService != null) {
|
||||
mHomeAssistantService.call(mIdentifier as Lang.String, mService);
|
||||
mHomeAssistantService.call(mService, mData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +149,6 @@ class HomeAssistantTemplateMenuItem extends WatchUi.MenuItem {
|
||||
status = RezStrings.getAvailable();
|
||||
setSubLabel(data);
|
||||
requestUpdate();
|
||||
ErrorView.unShow();
|
||||
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
|
||||
getApp().updateNextMenuItem();
|
||||
break;
|
||||
@ -179,9 +182,7 @@ class HomeAssistantTemplateMenuItem extends WatchUi.MenuItem {
|
||||
}
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
{
|
||||
"template" => mTemplate
|
||||
},
|
||||
{ "template" => mTemplate },
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
|
@ -25,21 +25,21 @@ using Toybox.Application.Properties;
|
||||
using Toybox.Timer;
|
||||
|
||||
class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
private var mConfirm as Lang.Boolean;
|
||||
private var mData as Lang.Dictionary;
|
||||
|
||||
function initialize(
|
||||
label as Lang.String or Lang.Symbol,
|
||||
subLabel as Lang.String or Lang.Symbol or {
|
||||
:enabled as Lang.String or Lang.Symbol or Null,
|
||||
:disabled as Lang.String or Lang.Symbol or Null
|
||||
} or Null,
|
||||
identifier,
|
||||
enabled as Lang.Boolean,
|
||||
options as {
|
||||
label as Lang.String or Lang.Symbol,
|
||||
confirm as Lang.Boolean,
|
||||
data as Lang.Dictionary or Null,
|
||||
options as {
|
||||
:alignment as WatchUi.MenuItem.Alignment,
|
||||
:icon as Graphics.BitmapType or WatchUi.Drawable or Lang.Symbol
|
||||
} or Null
|
||||
) {
|
||||
WatchUi.ToggleMenuItem.initialize(label, subLabel, identifier, enabled, options);
|
||||
WatchUi.ToggleMenuItem.initialize(label, null, null, false, options);
|
||||
mConfirm = confirm;
|
||||
mData = data;
|
||||
}
|
||||
|
||||
private function setUiToggle(state as Null or Lang.String) as Void {
|
||||
@ -114,9 +114,9 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
if (msg != null) {
|
||||
// Should be an HTTP 404 according to curl queries
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mIdentifier + " " + msg);
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404. " + mData.get("entity_id") + " " + msg);
|
||||
}
|
||||
ErrorView.show("HTTP 404, " + mIdentifier + ". " + data.get("message"));
|
||||
ErrorView.show("HTTP 404, " + mData.get("entity_id") + ". " + data.get("message"));
|
||||
} else {
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 404, page not found. Check API URL setting.");
|
||||
@ -127,9 +127,9 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
|
||||
case 405:
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mIdentifier + " " + data.get("message"));
|
||||
System.println("HomeAssistantToggleMenuItem onReturnGetState() Response Code: 405. " + mData.get("entity_id") + " " + data.get("message"));
|
||||
}
|
||||
ErrorView.show("HTTP 405, " + mIdentifier + ". " + data.get("message"));
|
||||
ErrorView.show("HTTP 405, " + mData.get("entity_id") + ". " + data.get("message"));
|
||||
|
||||
break;
|
||||
|
||||
@ -143,7 +143,6 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
setLabel((data.get("attributes") as Lang.Dictionary).get("friendly_name") as Lang.String);
|
||||
}
|
||||
setUiToggle(state);
|
||||
ErrorView.unShow();
|
||||
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
|
||||
getApp().updateNextMenuItem();
|
||||
break;
|
||||
@ -171,7 +170,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
ErrorView.show(RezStrings.getNoInternet() + ".");
|
||||
getApp().setApiStatus(RezStrings.getUnavailable());
|
||||
} else {
|
||||
var url = Settings.getApiUrl() + "/states/" + mIdentifier;
|
||||
var url = Settings.getApiUrl() + "/states/" + mData.get("entity_id");
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem getState() URL=" + url);
|
||||
}
|
||||
@ -240,7 +239,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
var state;
|
||||
var d = data as Lang.Array;
|
||||
for(var i = 0; i < d.size(); i++) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(mIdentifier)) {
|
||||
if ((d[i].get("entity_id") as Lang.String).equals(mData.get("entity_id"))) {
|
||||
state = d[i].get("state") as Lang.String;
|
||||
if (Globals.scDebug) {
|
||||
System.println((d[i].get("attributes") as Lang.Dictionary).get("friendly_name") + " State=" + state);
|
||||
@ -278,7 +277,7 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
} else {
|
||||
// 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 id = mData.get("entity_id") as Lang.String;
|
||||
var url = Settings.getApiUrl() + "/services/";
|
||||
if (s) {
|
||||
url = url + id.substring(0, id.find(".")) + "/turn_on";
|
||||
@ -286,14 +285,12 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
url = url + id.substring(0, id.find(".")) + "/turn_off";
|
||||
}
|
||||
if (Globals.scDebug) {
|
||||
System.println("HomeAssistantToggleMenuItem setState() URL=" + url);
|
||||
System.println("HomeAssistantToggleMenuItem setState() mIdentifier=" + mIdentifier);
|
||||
System.println("HomeAssistantToggleMenuItem setState() URL = " + url);
|
||||
System.println("HomeAssistantToggleMenuItem setState() entity_id = " + id);
|
||||
}
|
||||
Communications.makeWebRequest(
|
||||
url,
|
||||
{
|
||||
"entity_id" => mIdentifier
|
||||
},
|
||||
mData,
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
@ -307,4 +304,20 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
|
||||
}
|
||||
}
|
||||
|
||||
function callService(b as Lang.Boolean) as Void {
|
||||
if (mConfirm) {
|
||||
WatchUi.pushView(
|
||||
new HomeAssistantConfirmation(),
|
||||
new HomeAssistantConfirmationDelegate(method(:onConfirm), b),
|
||||
WatchUi.SLIDE_IMMEDIATE
|
||||
);
|
||||
} else {
|
||||
setState(b);
|
||||
}
|
||||
}
|
||||
|
||||
function onConfirm(b as Lang.Boolean) as Void {
|
||||
setState(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,22 +51,29 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
var content = items[i].get("content") as Lang.String or Null;
|
||||
var entity = items[i].get("entity") as Lang.String or Null;
|
||||
var tap_action = items[i].get("tap_action") as Lang.Dictionary or Null;
|
||||
var service = items[i].get("service") as Lang.String or Null;
|
||||
var confirm = false as Lang.Boolean;
|
||||
var service = items[i].get("service") as Lang.String or Null; // Deprecated schema
|
||||
var confirm = false as Lang.Boolean or Null;
|
||||
var data = null as Lang.Dictionary or Null;
|
||||
if (tap_action != null) {
|
||||
service = tap_action.get("service");
|
||||
confirm = tap_action.get("confirm");
|
||||
confirm = tap_action.get("confirm"); // Optional
|
||||
data = tap_action.get("data"); // Optional
|
||||
if (confirm == null) {
|
||||
confirm = false;
|
||||
}
|
||||
}
|
||||
if (type != null && name != null) {
|
||||
if (type.equals("toggle") && entity != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity));
|
||||
addItem(HomeAssistantMenuItemFactory.create().toggle(name, entity, confirm));
|
||||
} else if (type.equals("template") && content != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template(name, entity, content, service, confirm));
|
||||
} else if (type.equals("tap") && entity != null && service != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, service, confirm));
|
||||
if (service == null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_notap(name, content));
|
||||
} else {
|
||||
addItem(HomeAssistantMenuItemFactory.create().template_tap(name, entity, content, service, confirm, data));
|
||||
}
|
||||
|
||||
} else if (type.equals("tap") && service != null) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().tap(name, entity, service, confirm, data));
|
||||
} else if (type.equals("group")) {
|
||||
addItem(HomeAssistantMenuItemFactory.create().group(items[i]));
|
||||
}
|
||||
@ -80,7 +87,7 @@ class HomeAssistantView extends WatchUi.Menu2 {
|
||||
var lmi = mItems as Lang.Array<WatchUi.MenuItem>;
|
||||
for(var i = 0; i < mItems.size(); i++) {
|
||||
var item = lmi[i];
|
||||
if (item instanceof HomeAssistantViewMenuItem) {
|
||||
if (item instanceof HomeAssistantGroupMenuItem) {
|
||||
fullList.addAll(item.getMenuView().getItemsToUpdate());
|
||||
} else if (item instanceof HomeAssistantToggleMenuItem) {
|
||||
fullList.add(item);
|
||||
@ -142,9 +149,9 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
if (Globals.scDebug) {
|
||||
System.println(haToggleItem.getLabel() + " " + haToggleItem.getId() + " " + haToggleItem.isEnabled());
|
||||
}
|
||||
haToggleItem.setState(haToggleItem.isEnabled());
|
||||
} else if (item instanceof HomeAssistantMenuItem) {
|
||||
var haItem = item as HomeAssistantMenuItem;
|
||||
haToggleItem.callService(haToggleItem.isEnabled());
|
||||
} else if (item instanceof HomeAssistantTapMenuItem) {
|
||||
var haItem = item as HomeAssistantTapMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
}
|
||||
@ -155,8 +162,8 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate {
|
||||
System.println(haItem.getLabel() + " " + haItem.getId());
|
||||
}
|
||||
haItem.callService();
|
||||
} else if (item instanceof HomeAssistantViewMenuItem) {
|
||||
var haMenuItem = item as HomeAssistantViewMenuItem;
|
||||
} else if (item instanceof HomeAssistantGroupMenuItem) {
|
||||
var haMenuItem = item as HomeAssistantGroupMenuItem;
|
||||
if (Globals.scDebug) {
|
||||
System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId());
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ using Toybox.System;
|
||||
|
||||
// Can use push view so must never be run in a glance context
|
||||
class WebhookManager {
|
||||
|
||||
function onReturnRequestWebhookId(responseCode as Lang.Number, data as Null or Lang.Dictionary or Lang.String) as Void {
|
||||
switch (responseCode) {
|
||||
case Communications.BLE_HOST_TIMEOUT:
|
||||
@ -236,11 +237,12 @@ class WebhookManager {
|
||||
{
|
||||
:method => Communications.HTTP_REQUEST_METHOD_POST,
|
||||
:headers => {
|
||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
||||
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
|
||||
},
|
||||
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
|
||||
},
|
||||
method(:onReturnRegisterWebhookSensor)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|