-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.lua
69 lines (60 loc) · 1.89 KB
/
Config.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
--[[
Configuration handler
@author ikubicki
]]
class 'Config'
function Config:new(app)
self.app = app
self:init()
return self
end
function Config:getUsername()
if self.username and self.username:len() > 3 then
return self.username
end
return nil
end
function Config:getPassword()
return self.password
end
function Config:getDeviceID()
return self.device_id
end
function Config:setDeviceID(device_id)
self.device_id = device_id
end
function Config:getInterval()
return tonumber(self.interval) * 1000
end
--[[
This function takes variables and sets as global variables if those are not set already.
This way, adding other devices might be optional and leaves option for users,
what they want to add into HC3 virtual devices.
]]
function Config:init()
self.username = self.app:getVariable('Username')
self.password = self.app:getVariable('Password')
self.device_id = self.app:getVariable('DeviceID')
self.interval = self.app:getVariable('Interval')
local storedUsername = Globals:get('salus_username', '')
local storedPassword = Globals:get('salus_password', '')
-- handling username
if string.len(self.username) < 4 and string.len(storedUsername) > 3 then
self.app:setVariable("Username", storedUsername)
self.username = storedUsername
elseif (storedUsername == '' and self.username) then
Globals:set('salus_username', self.username)
end
-- handling password
if string.len(self.password) < 4 and string.len(storedPassword) > 3 then
self.app:setVariable("Password", storedPassword)
self.password = storedPassword
elseif (storedPassword == '' and self.password) then
Globals:set('salus_password', self.password)
end
-- handling interval
if not self.interval or self.interval == "" then
self.app:setVariable("Interval", 30)
self.interval = 30
end
end