rework update logic with migration

This commit is contained in:
joBr99
2022-12-27 00:40:57 +01:00
parent 312f7c88aa
commit 17b7696d62
2 changed files with 46 additions and 16 deletions

View File

@@ -332,26 +332,36 @@ def update_berry_driver(cmd, idx, payload, payload_json)
def task() def task()
import path import path
import string import string
if path.exists("nsp-lovelace-driver.tapp") if string.find(payload, ".tapp") > 0
var r = string.find(payload, ".tapp") print("tapp in URL; will do .tapp update and migration if necessary")
if r < 0
print("URL doesn't contain .tapp skipping update") if path.exists("autoexec.be")
else print("autoexec.be found; will check for migration")
r = tasmota.urlfetch(payload, "nsp-lovelace-driver.tapp") var autoexecfile = open('autoexec.be')
var line = autoexecfile.readline()
autoexecfile.close()
if string.find(line, "NSPanel Tasmota Lovelace UI Berry Driver") > 0
print("found lovelace berry driver, going to delete autoexec.be and .bec")
path.remove("autoexec.be")
path.remove("autoexec.bec")
end
end
var r = tasmota.urlfetch(payload, "nsp-lovelace-driver.tapp")
if r < 0 if r < 0
print("Update failed") print("Update failed")
else else
tasmota.cmd("Restart 1") tasmota.cmd("Restart 1")
end end
end
else elif string.find(payload, ".be") > 0
var r = string.find(payload, ".be") print("be in URL; will do .be update")
if r < 0 if path.exists("nsp-lovelace-driver.tapp")
print("URL doesn't contain .be skipping update") print("Error: there is the tapp version of the berry driver installed; cannot do .be update.")
else else
var cl = webclient() var cl = webclient()
cl.begin(payload) cl.begin(payload)
r = cl.GET() var r = cl.GET()
if r == 200 if r == 200
print("Sucessfully downloaded nspanel-lovelace-ui berry driver") print("Sucessfully downloaded nspanel-lovelace-ui berry driver")
else else
@@ -364,6 +374,26 @@ def update_berry_driver(cmd, idx, payload, payload_json)
print("Sucessfully written nspanel-lovelace-ui berry driver") print("Sucessfully written nspanel-lovelace-ui berry driver")
tasmota.cmd("Restart 1") tasmota.cmd("Restart 1")
end end
end
else
print("invalid url filetype")
end
if path.exists("nsp-lovelace-driver.tapp")
var r = string.find(payload, ".tapp")
if r < 0
print("URL doesn't contain .tapp skipping update")
else
end
else
var r = string.find(payload, ".be")
if r < 0
print("URL doesn't contain .be skipping update")
else
end end
end end
end end

Binary file not shown.