fix #338, needs verifcation from homeassistant users

added download link for settings on setup.html and update.html
This commit is contained in:
lumapu 2022-10-16 23:55:08 +02:00
parent 38bb3fd7e2
commit a595950d7d
6 changed files with 77 additions and 29 deletions

View file

@ -67,7 +67,7 @@
<label for="ntpBtn">set system time</label>
<input type="button" name="ntpBtn" id="ntpBtn" class="btn" value="from browser" onclick="setTime()"/>
<input type="button" name="ntpSync" id="ntpSync" class="btn" value="sync NTP" onclick="syncTime()"/>
<span id="apiResult">n/a</span>
<span id="apiResultNtp"></span>
</fieldset>
</div>
@ -85,6 +85,9 @@
<input type="password" class="text" name="mqttPwd"/>
<label for="mqttTopic">Topic</label>
<input type="text" class="text" name="mqttTopic"/>
<label for="mqttBtn">Discovery Config (homeassistant)</label>
<input type="button" name="mqttDiscovery" id="mqttDiscovery" class="btn" value="send" onclick="sendDiscoveryConfig()"/>
<span id="apiResultMqtt"></span>
</fieldset>
</div>
@ -110,7 +113,9 @@
<label for="reboot">Reboot device after successful save</label>
<input type="checkbox" class="cb" name="reboot"/>
<input type="submit" value="save" class="btn right"/>
<input type="submit" value="save" class="btn right"/><br/>
<br/>
<a href="/get_setup" target="_blank">Download your settings (JSON file)</a> (only saved values)
</form>
</div>
</div>
@ -132,8 +137,16 @@
ivHtml(JSON.parse('{"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""]}'), highestId + 1);
});
function apiCb(obj) {
var e = document.getElementById("apiResult");
function apiCbNtp(obj) {
var e = document.getElementById("apiResultNtp");
if(obj["success"])
e.innerHTML = "command excuted";
else
e.innerHTML = "Error: " + obj["error"];
}
function apiCbMqtt(obj) {
var e = document.getElementById("apiResultMqtt");
if(obj["success"])
e.innerHTML = "command excuted";
else
@ -146,13 +159,19 @@
var obj = new Object();
obj.cmd = "set_time";
obj.ts = parseInt(offset + (date.getTime() / 1000));
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
getAjax("/api/setup", apiCbNtp, "POST", JSON.stringify(obj));
}
function syncTime() {
var obj = new Object();
obj.cmd = "sync_ntp";
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
getAjax("/api/setup", apiCbNtp, "POST", JSON.stringify(obj));
}
function sendDiscoveryConfig() {
var obj = new Object();
obj.cmd = "discovery_cfg";
getAjax("/api/setup", apiCbMqtt, "POST", JSON.stringify(obj));
}
function ivHtml(obj, id) {

View file

@ -10,7 +10,9 @@
<h1>Update</h1>
<div id="content" class="content">
<div>
Make sure that you have noted all your settings before starting an update. New versions may have changed their memory layout which can break your existing settings.
Make sure that you have noted all your settings before starting an update. New versions may have changed their memory layout which can break your existing settings.<br/>
<br/>
<a href="/get_setup" target="_blank">Download your settings (JSON file)</a>
</div>
<br/><br/>
<form method="POST" action="/update" enctype="multipart/form-data" accept-charset="utf-8">