-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification-rec-del.lua
More file actions
71 lines (60 loc) · 3.03 KB
/
Copy pathnotification-rec-del.lua
File metadata and controls
71 lines (60 loc) · 3.03 KB
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
--[[
%% properties
%% weather
%% events
%% globals
--]]
local startSource = fibaro:getSourceTrigger();
test='Check notification'
fibaro:debug(test)
local sqlid = 76
local notification = api.get('/notificationCenter')
if __fibaroSceneId~=nil then id = __fibaroSceneId; prefix = 'S' else id = fibaro:getSelfId(); prefix = 'V' end
local dev = prefix..id
fibaro:startScene(sqlid, {{sev = "info"}, {src = dev}, {msg = test}})
function encode(str)
if (str) then
str = string.gsub (str, "([^%w])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
end
return str
end
for k,v in pairs (notification) do
-- notification for delete
if notification[k]["type"] == "SceneToManyInstancesNotification" and notification[k]["canBeDeleted"] == true then
fibaro:debug(notification[k].id..' - '..notification[k].created..' - '..notification[k].data.sceneId..' - '..notification[k].type..'!')
fibaro:startScene(sqlid, {{sev = notification[k].priority}, {src = dev}, {msg = encode(tostring(os.date('%Y-%m-%d %H:%M:%S', notification[k].created))..' - '..notification[k].data.sceneId..' - '..notification[k].type..'!')}})
if fibaro:getGlobalValue("sys_Log_err") ~= "Working" then
print('Error in connection with SQL server, notification not removed')
else
HomeCenter.NotificationService.remove(notification[k].id)
end
-- only for information without delete
elseif notification[k]["type"] == "GenericDeviceNotification" and notification[k]["canBeDeleted"] == true then
fibaro:debug(notification[k].id..' - '..notification[k].created..' - '..notification[k].data.deviceId..' - '..notification[k].type..'!')
fibaro:startScene(sqlid, {{sev = notification[k].priority}, {src = dev}, {msg = encode(tostring(os.date('%Y-%m-%d %H:%M:%S', notification[k].created))..' - '..notification[k].data.deviceId..' - '..notification[k].type..'!')}})
HomeCenter.NotificationService.remove(notification[k].id)
-- ex. if bloceced for delete
-- --[[
elseif notification[k]["type"] == "GenericSystemNotification" and notification[k]["canBeDeleted"] == false then
fibaro:startScene(sqlid, {{sev = notification[k].priority}, {src = dev}, {msg = encode(tostring(os.date('%Y-%m-%d %H:%M:%S', notification[k].created))..' - '..notification[k].data.name..' - '..notification[k].type..'!')}})
fibaro:debug(notification[k].id..' - '..notification[k].created..' - '..notification[k].data.name..' - '..notification[k].type..'!')
HomeCenter.NotificationService.update(notification[k].id, {
canBeDeleted = true,
data =
{
subType = notification[k].data.subType,
name = notification[k].data.name,
text = notification[k].data.text,
url = notification[k].data.url,
urlText = notification[k].data.urlText
}
})
-- if fibaro:getGlobalValue("sys_Log_err") ~= "Working" then
-- print('Error in connection with SQL server, notification not removed')
-- else
-- HomeCenter.NotificationService.remove(notification[k].id)
-- end
-- --]]
end
end