BUG: dzvents: customEvent.dump() not available  [SOLVED]

Moderator: leecollings

Post Reply
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

BUG: dzvents: customEvent.dump() not available

Post by rrozema »

https://www.domoticz.com/wiki/DzVents:_ ... leshooting describes the use of item.dump() to debug a script. However, below code results in error message
"
2020-06-01 20:59:17.847 Error: dzVents: Error: (3.0.5) ...domoticz/scripts/dzVents/generated_scripts/Script #3.lua:19: attempt to call a nil value (field 'dump')
", apparently the type of object passed in for the 2nd variable -which I believe to be "customEvent"-, does not seem to expose this function dump(). Either the documentation is wrong, or the customEvent type is missing the dump() function.

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
            object.dump()
            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)
            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
}

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]
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: BUG: dzvents: customEvent.dump() not available

Post by waaren »

rrozema wrote: Monday 01 June 2020 21:06 https://www.domoticz.com/wiki/DzVents:_ ... leshooting describes the use of item.dump() to debug a script. However, below code results in error message
Sorry but I cannot located item.dump() anywhere in the wiki. Do I overlook something ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: BUG: dzvents: customEvent.dump() not available

Post by rrozema »

waaren wrote: Monday 01 June 2020 22:59
rrozema wrote: Monday 01 June 2020 21:06 https://www.domoticz.com/wiki/DzVents:_ ... leshooting describes the use of item.dump() to debug a script. However, below code results in error message
Sorry but I cannot located item.dump() anywhere in the wiki. Do I overlook something ?

Code: Select all

Device attributes and methods for specific devices
Note that if you do not find your specific device type here you can always inspect what is in the rawData attribute. Please let us know that it is missing so we can write an adapter for it (or you can write your own and submit it). Calling myDevice.dump() will dump all attributes and values for myDevice to the Domoticz log.
plus

Code: Select all

execute = function(domoticz, item, triggerInfo) … end
When all the above conditions are met (active == true and the on section has at least one matching rule), then this execute function is called. This is the heart of your script. The function has three parameters:

1. (domoticz, item, triggerInfo)
The domoticz object. This object gives you access to almost everything in your Domoticz system, including all methods to manipulate them—like modifying switches or sending notifications. More about the domoticz object below.

2. (domoticz, item, triggerInfo)
Depending on what actually triggered the script, item is either a:

customEvent 3.0.0
device,
variable,
scene,
group,
timer,
system, 3.0.0
security or
httpResponse
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: BUG: dzvents: customEvent.dump() not available  [SOLVED]

Post by waaren »

rrozema wrote: Monday 01 June 2020 23:23 myDevice.dump()
Sorry if this gave you the impression that you could do an customEvent.dump()
It is not what is described nor what is meant.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: BUG: dzvents: customEvent.dump() not available

Post by rrozema »

It is inconsistent that device does support the dump() function and other types don't. The whole idea of calling the dump() function is to get insight into what I am being passed as that 2nd parameter: If I knew what the values and methods of item were I wouldn't need that dump() function, Why not add the function to all types that can be passed as the item parameter to the execute function? Having consistency makes it easier for all to learn how to use dzvents.

For anyone that runs into the same problem: a workaround is to call domoticz.utils.dumpTable(item). Then it works for all types that item can be,
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: BUG: dzvents: customEvent.dump() not available

Post by waaren »

rrozema wrote: Tuesday 02 June 2020 0:18 The whole idea of calling the dump() function is to get insight into what I am being passed as that 2nd parameter: I
Sorry but I disagree. The dump() function is certainly not limited for use on 2nd parm of the execute function. You can use it on every device, scene or group to find out the functions, tables and attributes for these objects.
Why not add the function to all types that can be passed as the item parameter to the execute function? Having consistency makes it easier for all to learn how to use dzVents.
Thx for the suggestion. I had a quick look at the code and I don't think it is complicated to implement. I will discuss with the other developers of dzVents and if they also agree it can be part of one of the next beta's
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: BUG: dzvents: customEvent.dump() not available

Post by rrozema »

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest