-
-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isTransform(), isEmpty() and isPresent() to ChannelTransformation #4355
Conversation
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
9f05750
to
4e8e067
Compare
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Modbus refactoring also requires this PR. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/syntax-for-binding-transformations/157861/1 |
I don't understand the need for |
We need the ability to check if a transformation is at all defined. If it's defined, the command to be published will be converted to StringType, and subsequently formatBeforePublish will treat the data as a String data. If it's not defined, then the original command type will be preserved (not converted to StringType) and the formatBeforePublish can apply type-specific formatting, e.g. special date format. So that's why we need to be able to know whether transformation is defined. I can instead check if However since ChannelTransformation already does a no-op (return input as output) when it has no transformations (i.e. empty), it's a lot more convenient to add isEmpty/isPresent to it than dealing with null checks around it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it would be fine to do this where needed, but I'm ok with adding it here. Please see my comments.
...b.core.thing/src/main/java/org/openhab/core/thing/binding/generic/ChannelTransformation.java
Outdated
Show resolved
Hide resolved
...b.core.thing/src/main/java/org/openhab/core/thing/binding/generic/ChannelTransformation.java
Show resolved
Hide resolved
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I have triggered a new core snapshot, should be available in about 35 minutes. |
This is needed by the user of this class, e.g. mqtt binding, to know whether to convert the command to
StringType
when transformations were involved, or continue using the native type.Example use cases
https://github.com/openhab/openhab-addons/blob/0d6feb72aa23dcfce946e1367ea0ce8b8c03b330/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java#L136
https://github.com/openhab/openhab-addons/blob/0d6feb72aa23dcfce946e1367ea0ce8b8c03b330/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java#L340
isTransform()
is needed by the modbus addon