Device routine returns null

Attempting to get a device handler's version number from an app.

Executing this simple routine in a device handler from an external source returns null, but works when called from within device handler

The routine

def version()
{return "0.1.0"}

Ancillary code
command "version"

When called from an external app returns
image

  globalKeypadDevices.find
		{
		if (it.typeName=='Centralitex Keypad')
			{
//		        map << [Centralitex_Keypad: it.version()]	//version returning null???
			log.debug "version ${it.version()}"
			map << [Centralitex_Keypad: it.currentValue('driverVersion')]	//get stored attribute version
			return true
			}
		}

Tagging @mike.maxwell @bravenel

I would normally present the version number as an attribute of the driver
Then itโ€™s easy to make the app subscribe to that attribute of the driver

I find itโ€™s the easiest/quickest way I know

Andy

I would store this in the device data attribute, this is accessable from an application.

updateDataValue(String name, String value) 
getDataValue(String name)

In an app you need to prepend a device object to the method.

Currently using a device attribute, changed the logic after encountering the null data response. My only issue with using an attribute is it's set using a sendEvent (shown below) when the user clicks "save preferences", so it may not always exist or be correct after an updated driver is installed.

sendEvent(name: "driverVersion", value: version())

When I tried the SendEvent in the version routine it crashed with an error

How can this be used to update the attribute? I tried but it did not do any thing.

I don't understand this.
I guessing it means something like this, that I'm using to get the attribute?

map << [Centralitex_Keypad: it.currentValue('driverVersion')]	

this doesn't set an attribute value, therefore no event, I'm not a fan of creating "fake" events as a place holder for configuration data.

In the driver, probably in the updated method add something like:
updateDataValue("version", "1.0.1")

in the app to get this value from a device
log.debug "driver version:${device.getDataValue("version")}"

in the driver to get this value:
log.debug "driver version:${getDataValue("version")}"

I agree, and I did not know there was another option until you provided this alternative. I'll try it out.

Neither did I :slight_smile:

1 Like

Did a simple test and It works! :grinning:

Just wondering. It does not show anywhere on the device display. Where it is stored?

Driver version routine

def version()
{
updateDataValue("versionx", "1.0.1")
return "0.2.0";
}

In my app

log.debug "driver version:${it.getDataValue("versionx")}"

The log

2019-05-21 11:01:43.968 debug driver version:1.0.1

It's at the very bottom...
This section of the driver details is not dynamic, it's only refreshed when the page loads.

Ok yes now I see it in device Data

Is there a command that deletes the field?

image

Bit confused here with that method..

I see that you are setting 'versionx' to 1.0.1 (and it's great that this works. Thanks Mike for the info)
Why are you sending "0.2.0" as a return?

there doesn't appear to be.

It was only for testing. My apologies for any confusion.

1 Like

Ah!
Great, I thought I was missing something here :slight_smile: :rofl:

I used this method to keep track of labels changes in my Virtual Container app but never thought about using it for versioning. :thinking:

1 Like

Just tried it and it worked perfectly to assign the data

I tried a silly: dataValue.clear() just on the off-chance it would work but it doesn't

@mike.maxwell any chance we can get something like this added Mike?

(because I can't spell...)

1 Like

The following set the field to null but did not remove it

updateDataValue("versionx", null)

The following do not Save

deleteDataValue("versionx")     
removeDataValue("versionx")
1 Like

This would save but I put a try/catch around it and got this error:

1 Like

FWIW: I tried the getDataValue with a nonexitant data name, the result is null, versus throwing an error.

Here's how to get a device's version without the user executing or looking at anything to set the DataValue.

In the device driver

command "version"
def version()
{
updateDataValue("driverVersion", "0.2.0")	//Stores in device Data
}

in the app, assuming "it" points to the device

it.version()     //force set or refresh of DataValue
dvcVersion = it.getDataValue('driverVersion')