Encountered a slight problem with one of my plugins. Vera returns an integer whereas openLuup returns a float for luup.sunrise(). Noting that the underlying representations are almost certainly floats.
A problem crops up when you convert the openLuup luup.sunrise() value to a string and then back to a number as you might do when storing and retrieving a plugin variable. The precision is probably not maintained during these two conversion processes, so you end up with a number ever so slightly different from what you started with. So in my case and with my hardware openLuup prints TRUE and Vera prints FALSE for the code below. Importantly, the printed outcome may depend on the sunrise value. Sometimes the code may work and other times it may not depending on the conversions. The code can be put in the Lua test boxes to see the result in the log files.
This can be fixed in my case by adding some biasing to the values before testing them but that’s a bit of hack. Should openLuup return a float or an integer value?
local PLUGIN_NAME = 'TEST_float_compare'
local DEBUG_MODE = true
local function debug(textParm, logLevel)
if DEBUG_MODE then
local text = ''
local theType = type(textParm)
if (theType == 'string') then
text = textParm
else
text = 'type = '..theType..', value = '..tostring(textParm)
end
luup.log(PLUGIN_NAME..' debug: '..text,50)
elseif (logLevel) then
local text = ''
if (type(textParm) == 'string') then text = textParm end
luup.log(PLUGIN_NAME..' debug: '..text, logLevel)
end
end
local function testFloatCompare()
local nextReset = luup.sunrise()
-- this imitates a Luup plugin variable being stored and retrieved
local countersNextReset = tostring(nextReset)
countersNextReset = tonumber(countersNextReset)
-- if dawn has just occurred then luup.sunrise() will leap ahead by approx 24 hours
-- reset the resettable kWh counters in the meter
debug(nextReset)
debug(countersNextReset)
if (nextReset > countersNextReset) then
debug('TRUE')
else
debug('FALSE')
end
debug(nextReset)
debug(countersNextReset)
end
testFloatCompare()
return true