Skip to content

Commit

Permalink
Salus local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ikubicki committed Dec 26, 2024
1 parent 44181b0 commit 541a7d0
Show file tree
Hide file tree
Showing 11 changed files with 833 additions and 197 deletions.
60 changes: 49 additions & 11 deletions Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ class 'Config'

function Config:new(app)
self.app = app
self.user = nil
self.password = nil
self.host = nil
self.port = nil
self.device_id = nil
self.interval = nil
self:init()
return self
end

function Config:getUsername()
if self.username and self.username:len() > 3 then
return self.username
function Config:getUser()
if self.user and self.user:len() > 3 then
return self.user
end
return nil
end
Expand All @@ -21,6 +27,20 @@ function Config:getPassword()
return self.password
end

function Config:getHost()
if self.host and self.host:len() > 3 then
return self.host
end
return nil
end

function Config:getPort()
if self.port and string.len(self.port) > 1 then
return self.port
end
return '80'
end

function Config:getDeviceID()
return self.device_id
end
Expand All @@ -39,20 +59,24 @@ 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.user = self.app:getVariable('User')
self.password = self.app:getVariable('Password')
self.host = self.app:getVariable('Host')
self.port = self.app:getVariable('Port')
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', '')
local storedHost = Globals:get('salus_host', '')
local storedPort = tonumber(Globals:get('salus_port', ''))

-- 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)
if string.len(self.user) < 4 and string.len(storedUsername) > 3 then
self.app:setVariable("User", storedUsername)
self.user = storedUsername
elseif (storedUsername == '' and self.user) then
Globals:set('salus_username', self.user)
end
-- handling password
if string.len(self.password) < 4 and string.len(storedPassword) > 3 then
Expand All @@ -61,9 +85,23 @@ function Config:init()
elseif (storedPassword == '' and self.password) then
Globals:set('salus_password', self.password)
end
-- handling host
if string.len(self.host) < 4 and string.len(storedHost) > 3 then
self.app:setVariable("Host", storedHost)
self.host = storedHost
elseif (storedHost == '' and self.host) then
Globals:set('salus_host', self.host)
end
-- handling port
if string.len(self.host) < 2 and string.len(storedPort) > 3 then
self.app:setVariable("Port", storedPort)
self.port = storedPort
elseif (storedPort == '' and self.port) then
Globals:set('salus_port', self.port)
end
-- handling interval
if not self.interval or self.interval == "" then
self.app:setVariable("Interval", 30)
self.interval = 30
self.app:setVariable("Interval", 5)
self.interval = 5
end
end
13 changes: 0 additions & 13 deletions SalusChildDevice.lua

This file was deleted.

Loading

0 comments on commit 541a7d0

Please sign in to comment.