BUG: dzvents: customEvent.data table value is returned as string
Posted: Monday 01 June 2020 22:27
Version: 2020.2 (build 12067)
Build Hash: 0fc3c7b70
Compile Date: 2020-05-17 13:15:45
dzVents Version: 3.0.5
Python Version: 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
https://www.domoticz.com/wiki/DzVents:_ ... nd_methods
If I put a table variable in the 2nd variable [extra data] of emitEvent(name,[extra data]), that variable is of type string when the event triggers. In below code, the values of object.data.idx, object.data.bState and object.data.lastUpdate all equal nil. This is because object.data is of type "string", instead of type "table" that it was when it was emitted.
When the trigger fires, the value of data is no longer of type table. It is now "{"bState":true,"idx":552,"lastUpdate":{"addDays":"Function","addHours":"Function","addMinutes":"Function","addSeconds":"Function","compare":"Function","current":{"day":1,"hour":22,"isdst":true,"min":21,"month":6,"sec":28,"wday":2,"yday":153,"year":2020},"dDate":1591042886,"day":1,"dayAbbrOfWeek":"mon","dayName":"Monday","daysAgo":0,"getISO":"Function","hour":22,"hoursAgo":0,"isToday":true,"isUTC":false,"isdst":true,"makeTime":"Function","matchesRule":"Function","milliSeconds":0,"milliseconds":0,"millisecondsAgo":2995,"min":21,"minutes":21,"minutesAgo":0,"minutesSinceMidnight":1341,"month":6,"monthAbbrName":"jun","monthName":"June","msAgo":2995,"raw":"2020-06-01 22:21:26","rawDate":"2020-06-01","rawDateTime":"2020-06-01 22:21:26","rawTime":"22:21:26","ruleIsAfterCivilTwilightEnd":"Function","ruleIsAfterCivilTwilightStart":"Function","ruleIsAfterSunrise":"Function","ruleIsAfterSunset":"Function","ruleIsAtCivilDayTime":"Function","ruleIsAtCivilNightTime":"Function","ruleIsAtCivilTwilightEnd":"Function","ruleIsAtCivilTwilightStart":"Function","ruleIsAtDayTime":"Function","ruleIsAtNight":"Function","ruleIsAtSunrise":"Function","ruleIsAtSunset":"Function","ruleIsBeforeCivilTwilightEnd":"Function","ruleIsBeforeCivilTwilightStart":"Function","ruleIsBeforeSunrise":"Function","ruleIsBeforeSunset":"Function","ruleIsInWeek":"Function","ruleIsOnDate":"Function","ruleIsOnDay":"Function","ruleMatchesBetweenRange":"Function","ruleMatchesHourSpecification":"Function","ruleMatchesMinuteSpecification":"Function","ruleMatchesTime":"Function","ruleMatchesTimeRange":"Function","sec":26,"seconds":26,"secondsAgo":2,"secondsSinceMidnight":80486,"time":"22:21","utils":{"DZVERSION":"3.0.5","LOG_DEBUG":4,"LOG_ERROR":1,"LOG_FORCE":0.5,"LOG_INFO":3,"LOG_MODULE_EXEC_INFO":2,"cameraExists":"Function","centerPad":"Function","deviceExists":"Function","dumpSelection":"Function","dumpTable":"Function","fileExists":"Function","fromBase64":"Function","fromJSON":"Function","fromXML":"Function","groupExists":"Function","hsbToRGB":"Function","inTable":"Function","isJSON":"Function","isXML":"Function","leadingZeros":"Function","leftPad":"Function","log":"Function","numDecimals":"Function","osExecute":"Function","print":"Function","rgbToHSB":"Function","rightPad":"Function","round":"Function","sceneExists":"Function","setLogMarker":"Function","stringSplit":"Function","stringToSeconds":"Function","toBase64":"Function","toCelsius":"Function","toJSON":"Function","toXML":"Function","urlDecode":"Function","urlEncode":"Function","variableExists":"Function"},"wday":2,"week":23,"yday":153,"year":2020}}"
I do see that this is a json, so I will be able to convert it back into a table. But the point is: I shouldn't have to. I assigned a table, so I expect to receive a table.
Here's the code I used to verify this behavior:
Build Hash: 0fc3c7b70
Compile Date: 2020-05-17 13:15:45
dzVents Version: 3.0.5
Python Version: 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
https://www.domoticz.com/wiki/DzVents:_ ... nd_methods
If I put a table variable in the 2nd variable [extra data] of emitEvent(name,[extra data]), that variable is of type string when the event triggers. In below code, the values of object.data.idx, object.data.bState and object.data.lastUpdate all equal nil. This is because object.data is of type "string", instead of type "table" that it was when it was emitted.
Code: Select all
domoticz.emitEvent('myTestEvent', { idx = object.idx, bState = object.bState, lastUpdate = object.lastUpdate } )
I do see that this is a json, so I will be able to convert it back into a table. But the point is: I shouldn't have to. I assigned a table, so I expect to receive a table.
Here's the code I used to verify this behavior:
Code: Select all
return {
on = {
devices = {
"myTest"
},
customEvents = {
"myTestEvent*"
}
},
execute = function(domoticz, object, triggerInfo)
if object.isDevice then
domoticz.log('Device ' .. object.name .. ': state ' ..tostring(object.bState).. '.', domoticz.LOG_FORCE)
if object.bState == true then
domoticz.emitEvent('myTestEvent', { idx = object.idx, bState = object.bState, lastUpdate = object.lastUpdate } ).afterSec(15)
-- domoticz.emitEvent( "myTestEvent" ).afterSec(30)
end
elseif object.isCustomEvent then
domoticz.log('CustomEvent, ' .. type(object) .. '.', domoticz.LOG_ERROR)
domoticz.log('CustomEvent, "' .. object.data .. '".', domoticz.LOG_ERROR)
--domoticz.utils.dumpTable(object)
domoticz.log('CustomEvent, ' .. type(object.data) .. ', idx = '.. tostring(object.data.idx) .. ', bState = ' ..tostring( object.data.bState) .. '.', domoticz.LOG_ERROR)
if object.data == nil then
domoticz.log('CustomEvent, data is nil.', domoticz.LOG_ERROR)
elseif object.data.idx == nil then
domoticz.log('CustomEvent, data.idx is nil.', domoticz.LOG_ERROR)
else
local dev = domoticz.devices(object.data.idx)
if dev == nil then
domoticz.log('CustomEvent, device ' .. tostring(domoticz.data.idx) .. ' not found.', domoticz.LOG_ERROR)
else
if dev.bState == object.data.bState and dev.lastUpdate == object.data.lastUpdate then
domoticz.log('CustomEvent, device ' .. dev.name .. ' is still on.', domoticz.LOG_FORCE)
else
domoticz.log('CustomEvent, device ' .. dev.name .. ' is off.', domoticz.LOG_FORCE)
end
end
end
else
domoticz.log( "unexpected trigger type.", domoticz.LOG_FORCE)
end
end
}