HTTP binding POST

I’m trying to POST a Number:Dimensionless item value to a URL but the binding always encodes a value XX as XX%20%25 (i.e. “XX %”).

I’d think it shouldn’t be appending the UoM (or displayState?), so is it a bug ?

If not, any elegant way to force it to send the plain number only?
(EDIT: using a transformation for now)

Thing http:url:API "HTTP API" [ authMode="BASIC", baseURL="", bufferSize=4096, commandMethod="POST", contentType="text/plain", ignoreSSLError=true, refresh=5, stateMethod="GET", timeout=3000 ] {
                        Type number : SoC "SoC" [ commandExtension="somepath/soc/%2$s", mode="READWRITE", stateExtension="state", stateTransformation="<some>"  ]

Seems I also cannot force handling this as a number, I tried changing the s in %2$s to d but results in

2022-04-28 11:50:37.892 [WARN ] [nding.http.internal.HttpThingHandler] - Creating request for '$d' failed: d != java.lang.String

In MQTT, if you define the unit advanced parameter it will append that unit to the incoming number and strip it from outgoing messages (I think). But the description of unit for the HTTP binding in MainUI implies that it will append that unit to messages in either direction.

Unit to append to the (transformed) value.

But the docs imply it only appends it to incoming and is silent on outgoing.

If a unit is given in the unit parameter, the binding tries to create a QuantityType state before updating the channel, if no unit is present, it creates a DecimalType. Please note that incompatible units (e.g. °C for a Number:Density item) will fail silently, i.e. no error message is logged even if the state update fails.

So I’m not sure what it’s supposed to do for outgoing.

I think a transformation is the best approach for now.

As to whether it’s a bug, :person_shrugging: I can see times where someone would want/need the units so I don’t think it’s fair to always strip them all the time. But it seems like it might be a reasonable default behavior.

Given the similarities between MQTT and HTTP, I’d try to define the unit parameter and see what happens. It might strip the units and the docs just don’t tells us.

As for the %2s, I think there are places in some bindings where that won’t work for quantity types at all. And even with Item labels and other places where it’s used, I think f and d will only work with quantity types if you also supply the units, or indicate the default units (%UNIT% if I recall correctly).