-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-batch.lua
78 lines (67 loc) · 1.87 KB
/
backup-batch.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--[[
%% properties
%% events
%% globals
--]]
-- scene called by backup-create
-------=================
local params = fibaro:args()
local del_id = '0'
local typ = false
local password = ''
function doNotify(info, level)
local scene = api.get("/scenes/" .. __fibaroSceneId)
print( scene.name )
HomeCenter.NotificationService.publish({
type = "GenericSystemNotification", --"GenericDeviceNotification",
priority = level,
canBeDeleted = "true",
data =
{
subType = "DeviceNotConfigured",
name = "Backup System",
text = info,
url = "/scenes/edit.html?id="..__fibaroSceneId.."#bookmark-advanced",
urlText = "Edycja sceny"
}
})
end
if (params) then
for k, v in ipairs(params) do
if (v.del_id) then del_id = v.del_id end
if (v.typ) then typ = v.typ end
if (v.pass) then password = v.pass end
end
end
local function deleteMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'DELETE',
headers = {
['Authorization']= 'Basic '..password
},
},
success = successCallback,
error = errorCallback
})
end
local IP = api.get('/settings/network')['ip']
local url = 'http://'..IP..'/api/service/backups/'..del_id
deleteMethod(url, function(resp)
print('Status2: ' .. resp.status)
print("Backup "..del_id.." deleted at " .. os.date())
local data = json.decode(resp.data)
if tonumber(resp.status) == 200 then
doNotify('Backup '..del_id..' deleted at'.. os.date(), "info" )
else
doNotify('Backup '..del_id..' error '..resp.status..' at '..os.date(), "alert" )
end
end,
function(err)
print(del_id..' error2 ' .. err)
doNotify('Backup '..del_id..' error '..err, "alert" )
end
)
------==================
-- fibaro:sleep(45*1000)