Some improvements

pull/1995/head
David Peer 2022-06-26 12:54:25 +02:00
parent f98fd1662d
commit fe6293dcbb
1 changed files with 14 additions and 16 deletions

View File

@ -4,14 +4,7 @@
</head>
<body>
<h3>Upload Tigger</h3>
<p>Status: </p><p id="status"></p></p>
<p><textarea id="triggers" style="width:500px; height:300px">
[
{"display": "Open", "trigger": "OPEN_DOOR", "icon":"door"},
{"display": "Office", "trigger": "TOGGLE_LIGHT", "icon":"light"},
{"display": "Living Room", "trigger": "OVEN", "icon":"fire"}
]
</textarea></p>
<p><textarea id="triggers" style="width:500px; height:300px">Load data...</textarea></p>
<p><button id="upload" class="btn btn-primary">Upload</button></p>
<script src="../../core/lib/customize.js"></script>
@ -20,14 +13,22 @@
/*
* Load trigger from BangleJs
*/
document.getElementById("status").innerHTML = "Loading trigger from BangleJs...";
console.log("Loading trigger from BangleJs...");
try {
Puck.eval(`require("Storage").read(${JSON.stringify("ha.trigger.json")})`,data=>{
document.getElementById("triggers").innerHTML = data;
document.getElementById("status").innerHTML = "Loaded trigger from BangleJs.";
console.log("Successfully loaded trigger from BangleJs.");
console.log(data);
});
} catch(ex) {
document.getElementById("status").innerHTML = "Could not load trigger from BangleJs.";
console.log("(Warning) Could not load trigger from BangleJs.");
console.log(ex);
document.getElementById("triggers").innerHTML = `
[
{"display": "Open", "trigger": "OPEN_DOOR", "icon":"door"},
{"display": "Office", "trigger": "TOGGLE_LIGHT", "icon":"light"},
{"display": "Living Room", "trigger": "OVEN", "icon":"fire"}
]`
}
/*
@ -35,14 +36,11 @@
*/
document.getElementById("upload").addEventListener("click", function() {
// get the text to add
var text = document.getElementById("triggers").value;
console.log(text);
// build the app's text using a templated String
var app = text;
var triggerText = document.getElementById("triggers").value;
// send finished app (in addition to contents of app.json)
sendCustomizedApp({
storage:[
{name:"ha.trigger.json", url:"ha.trigger.json", content:app},
{name:"ha.trigger.json", url:"ha.trigger.json", content:triggerText},
]
});
console.log("Sent ha.trigger.json!");