[Question] Is the Zigbee class DataType actually work? the frustration is really high

Hi There,

I’ve spent countless hours trying to test/understand the Zigbee DataType class, and I’m at the point of ire and absolute frustration.

I cannot find a single usage example of it except in other platforms who have updated their own class to support extra stuff (like hubitat).

My problem is simple, I have a variable with a hex value of 21 and I want to get the getLength of type 21 which is DataType UINT16 (length should return 2)

The examples in the ‘old’ docs are just bad to explain how to properly use them in an example,

If I do this inside a method:

def testvalue = 0x21

def testUnknown = DataType.getLength(testvalue.UINT8)

log.warn "result of test is: ${testUnknown}"

you get:
groovy.lang.MissingPropertyException: No such property: UINT8 for class: java.lang.Integer @line

(Same thing, but for java.lang string if I do a Integer.toHexString(value) first)

If I do, what the documentation says to do (which makes no sense):

DataType.getLength(DataType.UINT8)

you get: java.lang.NullPointerException: Cannot get property ‘UINT8’ on null object @line

(if i replace the first DataType., with the testvalue variable (or even hex as string value), same error)

So the question is simple, WHAT exactly is the getLength() method is expecting??? how exactly can I just derive that the length is (value) if I priorly know the hex code for the DataType ZCL numeric value???

Has anybody actually used getLength() somewhere? can you provide an example on how to use it?

Paging @BroderickCarlin

Thanks Jimmy!

I’ve also tried examples from DTHs from hubitat and Java-based ZCL libraries which they do something like this (integer.parseInt, radix 16) before passing it to getLength:

def testvalue = 33

def testhex = Integer.toHexString(testvalue);

def parsedtest = Integer.parseInt(testhex, 16)

log.warn "value of parsed test is: ${parsedtest}"

def testUnknown = DataType.getLength(parsedtest)

log.warn "result of test is: ${testUnknown}"

This will result in the following:

WARN: value of parsed test is: 33
java.lang.NullPointerException: Cannot invoke method getLength() on null object @line

That is the closest i’ve got to get it working where getLength() will complain that is a null object when its not (its a Int of 33), and I’ve been going crazy trying to understand why getLength() would say its null when its not, or is it expecting something else?

import physicalgraph.zigbee.zcl.DataType

23:04:08: warn result of test is: 2
23:04:08: warn value of parsed test is: 33

1 Like

Thanks @orangebucket!

You beat me to it :frowning: , i started thinking on the premise what if the groovy jvm doesnt import datatype class by default and found and old post from 2017 saying exactly that >_<

Zigbee DataType class missing? - General Discussion - SmartThings Community

Argh, I hate the documentation. (2 days banging my head, god I hate library imports, I thought it was default because I saw an old post of the ST source code using getLength() in the configureReporting() method)

When I first started using SmartThings, the ‘Classic’ environment of Groovy DTHs and SmartApps was pretty much the only way to go to actually do anything.

Unfortunately the ‘new’ environment already existed, that included such things as a new mobile app that didn’t even try to do anything useful (and luckily for me didn’t run on my phone otherwise I’d never have bothered with SmartThings) and a totally incomprehensible Developer Workspace and associated embryonic documentation that contained snippets of information about I know not what, because whatever the new environment could do was totally impenetrable, and anything it did do clearly wasn’t going to involve the ‘community’ in any way. The face of SmartThings was thus a website that didn’t in any way bear any relation to the product and in terms of content remains one of the worst websites I have ever seen (it still isn’t great but it is moving in the right direction and the ‘new’ environment is more like a ‘new new’ environment and a gazillion times better than the one I first encountered).

Despite this new users were encouraged to use the ‘new’ app that couldn’t do anything, and directed towards the ‘new’ documentation which didn’t tell you how to do anything, and nor did it tell you what it was it wasn’t telling you how to do. In the meantime the almost useful ‘Classic’ documentation seemed to get near enough frozen at a point just short of being up to date. It was a good effort but still left you to do too much heavy lifting.

So I can’t say I’m that fond of it either.

2 Likes