arnb
May 21, 2019, 11:42am
1
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
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
Cobra
May 21, 2019, 12:51pm
2
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.
arnb
May 21, 2019, 1:34pm
4
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")}"
arnb
May 21, 2019, 2:51pm
6
I agree, and I did not know there was another option until you provided this alternative. I'll try it out.
arnb
May 21, 2019, 3:07pm
8
arnb:
I'll try it out.
Did a simple test and It works!
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.
arnb
May 21, 2019, 3:13pm
10
Ok yes now I see it in device Data
Is there a command that deletes the field?
Cobra
May 21, 2019, 3:15pm
11
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.
arnb
May 21, 2019, 3:16pm
13
It was only for testing. My apologies for any confusion.
1 Like
Cobra
May 21, 2019, 3:17pm
14
arnb:
It was only for testing.
Ah!
Great, I thought I was missing something here
Cobra:
Neither did I
I used this method to keep track of labels changes in my Virtual Container app but never thought about using it for versioning.
1 Like
Cobra
May 21, 2019, 3:37pm
16
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
arnb
May 21, 2019, 3:41pm
17
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
Cobra
May 21, 2019, 3:42pm
18
Cobra:
dataValue.clear()
This would save but I put a try/catch around it and got this error:
1 Like
arnb
May 21, 2019, 3:52pm
19
FWIW: I tried the getDataValue with a nonexitant data name, the result is null, versus throwing an error.
arnb
May 21, 2019, 7:44pm
20
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')