TCP Binding and Transformation field

I am a total beginner here.
Why can’t one pass a string directly in the Transformation field in the item declaration? For instance, in the example given in the TCP Binding wiki:

tcp=">[ON:'MAP(')], >[OFF:'MAP(']"

Assuming content is:

why can’t I just write:

tcp=">[ON:'1234'], >[OFF:'5678']"

I understand that this declaration does not work, but I would like to understand why such a simple way of declaring items doesn’t work. I fear I am not understanding something fundamental about items and transformations.

It appears to be a missing feature in the TCP binding, and doesn’t really relate directly to the rest of openHAB. It would be a relatively easy change to this code to add support for what you are looking for.

Thanks Watou. So it’s just something from the TCP binding that could be improved.
Is it possible to change the code? I have had a look but am no expert. The function itself seems actually to return already the second argument ‘response’, which could be the transformation string itself, but the call to that function seem to pass an empty string if I read correctly.
Anyway, if you tell me I can propose a change I will work on it.

You could use a non-existent transformation type and value, like “FAKE(the string I want)”, but that will produce either a WARN or ERROR in the log. The best solution would be to make a backward-compatible change that accepts literal strings without requiring transformation, or just use a MAP transformation with a one-line .map file.

You are welcome to submit a pull request, but if you do please make sure it’s been well tested and backward-compatible, and please read the developer guidelines here. Thanks!

Actually “FAKE(string)” returns the command (ON or OFF) and not the string, at least in my setup, and it does throw a WARN (only). I will go with the MAP option even if I need one file per item, which I was looking to avoid.
Thanks very much anyway, I got my answer that this is something that could be added and not something I am not getting about the functionalities. I will work on the TCP binding a bit more and maybe propose a pull.

1 Like

Oh yes, you’re right; so the MAP (or other transformation) is the only option aside from a pull request.

Actually, wouldn’t it be better to create a new transformation that returns the argument only?

One concern is that there are different 1.x bindings that handle this part of binding config syntax in similar but slightly different ways; I think if the approach used by another binding (like serial, mqtt, a few others) on how literals are specified (instead of TRANSFORM(argument) you just have a literal string like motor OFF). Code changes around this line could support literal strings in a way that’s familiar to other binding users.

ok, I am going to check the mqtt binding, I will need to use it anyway, and see if I can come up with something consistent.

1 Like

I have proposed a change in the code through a pull request in I hope it’s ok.

Hi Paolo, I don’t see your pull request here:

Please let me know! Thanks.

Sorry, didn’t complete the process. There you go.

1 Like