fblackburn1 / node-red-contrib-hubitat

MIT License
18 stars 4 forks source link

Number parameter is sent as a string #165

Closed youzer-name closed 5 days ago

youzer-name commented 6 days ago

I'm trying to use a command node to send a command to a device with a number as a parameter:

Screenshot 2024-11-24 09 46 47

Even though the field shows "number", I'm getting this error when I try to send the command:

groovy.lang.MissingMethodException: No signature of method: user_driver_XXXXXXXXXX.setChargeLimit() is applicable for argument types: (java.lang.String) values: [50] Possible solutions: setChargeLimit(java.lang.Number), setChargeAmps(java.lang.Number) on line 515 (method setChargeLimit)

When I send the command directly from the device page in Hubitat, it works:

image

In the driver the command was set up as:

def setChargeLimit(Number Limit)

I changed that to

def setChargeLimit(Limit)

and then used

Limit.toInteger()

to cast the string to an integer. That worked.

So it seems that despite the field in the Command node saying "number", it is sending a string to the hub.

fblackburn1 commented 5 days ago

Short Answer/Guess:

I don't think the Number type exists (though I’m not a Groovy expert). Did you try with Integer in the method definition to enable automatic casting.

Long Answer:

The command node uses the Maker API for this request, and the argument is passed via the URL. Enabling Node-RED debug will reveal more details. For example:

24 Nov 19:25:21 - [debug] [hubitat command:<node-id>] Request: http://127.0.0.1/apps/api/1/devices/1/setLevel/50

Where setLevel is the command, and 50 is the argument. As shown, there is no strict concept of type—everything is transmitted in the URL as a string (e.g., string, float, int, vector, etc.). It’s up to the driver to handle the argument and perform the necessary conversion.

(not so long answer :joy: )

Rule of Thumb:

You can reproduce or troubleshoot the issue by directly making requests with the Maker API. If the request works through the API but not via the node, I can assist further. Otherwise, the problem is likely related to the driver.

Edit: I'm not an expert with hubitat driver, but I think you should also be sure to have the right type definition for the command :man_shrugging:

        command(
            'setChargeLimit',
            [[
                name: 'Set Charge Limit,
                type: 'NUMBER',
                description: "...",
            ]]
        )
youzer-name commented 5 days ago

That makes sense. So to work with Maker API requests, drivers need to accept strings and cast as needed. Thanks!