# Opinion on TCP binding enhancement?

**URL:** <https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176>\
**Category:** Bindings\
**Tags:** bindingtcp, tcp, tcpbinding\
**Created:** [September 16, 2016, 4:26pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176 "2016-09-16T16:26:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [September 16, 2016, 4:26pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/1 "2016-09-16T16:26:25Z")

</div>

A user has kindly contributed [this PR](https://github.com/openhab/openhab/pull/4625) to add a useful feature to the TCP binding (old 1.x binding), to eliminate the burden of putting a transformation in the binding config string, when all you want to do is send a literal string. My preference is to follow the same pattern used by other 1.x bindings that allow either the “TRANSFORMATION(function)” syntax, or the “StringLiteral” syntax. Paolo’s PR has the syntax “(StringLiteral)”, which works fine, but the purist in me is hoping for greater consistency with other bindings. In the end, I don’t suppose it’s a big deal either way, but I wanted to get feedback from users regarding this feature and how they would like to see it configured, instead of my deciding alone to merge the current PR, or asking Paolo to rework it. Plan first; merge last!

Thoughts? Please reply here, instead of on the PR, so all the feedback is in one place.

---

<div class="post-metadata">

**Author:** ![chris](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://community.openhab.org/u/chris)\
**Post date:** [September 16, 2016, 4:31pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/2 "2016-09-16T16:31:42Z")

</div>

I’ve not used it, and not looked at it, so maybe I’m speaking a bit out of turn, but I would strongly suggest to try and keep syntax the same between bindings where possible - it will make things easier for users in the long run…

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [September 16, 2016, 5:01pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/3 "2016-09-16T17:01:08Z")

</div>

I agree as well. The more the same we can keep the syntax between the different binding configs (and Things for OH 2) the easier it is for users to learn and transfer their knowledge to other bindings.

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [September 16, 2016, 5:19pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/4 "2016-09-16T17:19:00Z")

</div>

Would you agree that it might be an opportunity to compatibly expand the binding’s syntax to work in the same way as the MQTT binding, supporting `default`, the transformation syntax, or a string literal? I too would like to see some harmonisation for the purpose of decreasing complexity.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [September 16, 2016, 5:24pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/5 "2016-09-16T17:24:06Z")

</div>

I like “default” or “_". I’ve seen both used for similar meanings. Though I’m cautious about using "_” only because in some cases (Persistence being the main one) “\*” is used counter to expectations (i.e. lots of people assume the \* means a wild card and will match an Item that starts with the previous string as opposed to its ream meaning of all members of this group).

So I guess I would vote for “default”.

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [September 16, 2016, 6:25pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/6 "2016-09-16T18:25:20Z")

</div>

Just to add, in the case where you would want to send the literal string “default”, which would be rare, you would have to use the transformation option.

---

<div class="post-metadata">

**Author:** ![Paolo](https://community.openhab.org/user_avatar/community.openhab.org/paolo/32/15727_2.png) [@Paolo](https://community.openhab.org/u/Paolo)\
**Post date:** [September 19, 2016, 2:20pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/7 "2016-09-19T14:20:47Z")

</div>

I guess we should go for the harmonisation option then. Is there a more precise definition than the wiki of what is this de facto standard you wish to put in place based on the MQTT binding? From what I understand, assuming

```csv
<transformation>

```

is the string passed as an argument in the item definition, the algo is:  
(1) if it equals default return ?  
(2) if it is not in the form TEXT1(TEXT2) then return the whole string  
(3) if can’t find TEXT1 as valid transformation then return the whole string  
(4) if TEXT2 not valid argument of transformation TEXT1 then return the whole string  
(5) return the result of the transformation TEXT1(TEXT2)

If that’s the case I don’t know what the default do. Also it’s clear that in this context there are no WARNINGS or ERRORS produced in case of typos calling for valid transformations.  
Anyway, happy to propose a PR based on this.

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [September 19, 2016, 5:35pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/8 "2016-09-19T17:35:57Z")

</div>

Here is what I would suggest for the TCP/UDP binding. If the `<transformation>` field is:

- `'TEXT1(TEXT2)'` : handle fully compatibly with the existing code (note the single quotes). One performance improvement you could introduce is that if the transformation string specified in the binding config is `'REGEX((.*))'`, then recognize it for what it would do without having to go through an actual transformation.

- `default` : the `toString()` version of the `State` or `Command`

- `TEXT1(TEXT2)` : attempt to use the transformation `TEXT1` with argument `TEXT2`. Log a warning if unable to transform, and proceed as if `default` had been specified. Also, add the same optimization when you see `REGEX((.*))` as described above.

- any other string : use it as specified.

Note that since any string can appear as the `<transformation>`, there can’t be an error at the time the binding config string is parsed, since values like `WRONG(THING)` can’t be detected as unusable until the time it needs to be used.

For any `<transformation>` values you want to pass that are either the literal string `default` or match the `TEXT1(TEXT2)` format, you will have to use a _real_ transformation in order to produce the desired result.

Does that sound to you like how the MQTT binding works? Any conflict with what I described and the semantics of how the MQTT binding works would be resolved in favor of how the MQTT binding works.

---

<div class="post-metadata">

**Author:** ![Paolo](https://community.openhab.org/user_avatar/community.openhab.org/paolo/32/15727_2.png) [@Paolo](https://community.openhab.org/u/Paolo)\
**Post date:** [September 23, 2016, 4:01pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/9 "2016-09-23T16:01:00Z")

</div>

I have checked the code of the MQTT Binding in order to really stick to a ‘MQTT’ style interpretation of the `<transformation>`. The code is quite different from the TCP binding but anyway in a nutshell it seems to work like this:

- if `<transformation>` is empty or `default` then it returns the `State` or the `Command` as a String.
- if it is written like `TEXT1(TEXT2)` then it goes through the transformation (Note: the MQTT binding doesn’t even check that the last character is ‘)’, it just assumes it, bad for typos).
- anything else and it sends back the `<transformation>` string as result.

I am not sure to understand the difference you make between single quotes or not being there. Also, at this stage I prefer to leave alone the REGEX case. Anyway, I have proposed a new PR [here](https://github.com/openhab/openhab/pull/4625/commits/4c51972fea501153c2cb011393d78ffeb65b8162).

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [September 23, 2016, 4:19pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/10 "2016-09-23T16:19:44Z")

</div>

> [@Paolo](#):
>
> I am not sure to understand the difference you make between single quotes or not being there.

The single quotes would have to be supported for backward compatibility, but they seem superfluous to me and I don’t know of another binding that uses them like this. So as long as the new, MQTT-style syntax is supported as well as being backward compatible with existing users, that’s good.

> [@Paolo](#):
>
> Also, at this stage I prefer to leave alone the REGEX case

Sure; that’s an optimization for another day, and also kind of pointless when `default` would mean the same as `REGEX((.*))`?

Thanks for the PR.

---

<div class="post-metadata">

**Author:** ![Paolo](https://community.openhab.org/user_avatar/community.openhab.org/paolo/32/15727_2.png) [@Paolo](https://community.openhab.org/u/Paolo)\
**Post date:** [September 24, 2016, 3:21pm UTC](https://community.openhab.org/t/opinion-on-tcp-binding-enhancement/14176/11 "2016-09-24T15:21:15Z")

</div>

You can find the latest PR [here](https://github.com/openhab/openhab/pull/4658). Sorry I had to go back and forth on 2 separate PR, I closed the other one now.
