-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[lcn] Add configuration option invertOpenClosed to binary sensor channel #8102
Conversation
Travis tests have failedHey @toweosp, |
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.
Thanks for your contribution! Here is my feedback.
bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
if (channelGroup.equals(LcnChannelGroup.BINARYSENSOR)) { | ||
Channel channel = thing.getChannel(channelUid); | ||
if (channel != null) { | ||
Object invertConfig = channel.getConfiguration().get("invertOpenClosed"); | ||
boolean invertOpenClosed = invertConfig instanceof Boolean && (boolean) invertConfig; | ||
if (invertOpenClosed) { | ||
if (state.equals(OpenClosedType.OPEN)) { | ||
convertedState = OpenClosedType.CLOSED; | ||
} else { | ||
convertedState = OpenClosedType.OPEN; |
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.
Can you move this into LcnModuleBinarySensorSubHandler
similar to the inversion of the roller shutter up/down in LcnModuleRollershutterRelaySubHandler
?
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.
BaseThingHandler.updateState
is not visible from AbstractLcnModuleSubHandler
. So one can not delegate channel update handling to a sub handler similar to the rollershutter command handling (without revealing BaseThingHandler.updateState
in LcnModuleHandler
). We could delegate state conversion within LcnModuleHandler.updateChannel
to a converter (similar to Converter.onStateUpdateFromHandler(State)
). This would require Converter
to be an (abstract) superclass or better interface for arbitrary converters which are initialized in LcnModuleHandler.initialize
. At the moment Converter
is specialized to deal with variables only.
What do you think?
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.
If I see correctly, BaseThingHandler.updateState()
is invoked via LcnModuleHandler.updateChannel()
-> AbstractLcnModuleSubHandler.fireUpdate()
-> LcnModuleBinarySensorSubHandler.handleStatusMessage()
. I think the conversion could happen in LcnModuleBinarySensorSubHandler:55.
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.
Thanks for your feedback! If I didn't miss something when following your suggestion channel update (and status message handling resp.) would differ between binary sensors and variables. So from a design perspective I think we should choose between using the converter approach or uniquely handle value conversion within the sub-handler's handleStatusMessage
.
Would you like to decide how to uniquely handle value conversion and adapt the code correspondingly? Perhaps it would make sense to handle this on a separate enhancement/pull request due to the necessary refactorings.
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.
Although I'm a fan a of abstracting things, I wouldn't combine conversion of raw data into human readable values and the inversion of binary sensor states. First is a conversion, the other is a manipulation. From the functional perspective, I think they have to less in common to merge these functions.
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.
WDYT?
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.
From my point of view there is no conceptual difference between converting raw variable data (i.e. lcn value) into temperature, speed etc. and converting raw lcn binary sensor data (0 or 1) into open/closed states. In my opinion in both cases conversion applies semantic to raw sensor data leading to human readable values.
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.
Ok, you convinced me. I refactored the conversion code and made Converter
an interface. Do you want to implement an inversion Converter?
Can you give me access rights to merge the changes into your branch? Alternatively, you could merge my lcn-converter
branch into yours. Before doing so you have to rebase this PR's branch to bb6722c.
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.
I added an InversionConverter
. For this I moved Converter.onCommandFromItem(double)
and Converter.onCommandFromItem(QuantityType<?>)
down the hierarchy to ValueConverter
because I think these methods make only sense when converting numerical values. The InversionConverter
might later additionally be used e.g. for visualizing channels with inversed OnOff
or UpDown
states.
Travis tests have failedHey @toweosp, |
1 similar comment
Travis tests have failedHey @toweosp, |
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.
Thanks! There seem to be commits from the 2.5.x branch in this PR, which don't belong to it.
There are some formatting issues. You can view them with mvn spotless:check -Dspotless.check.skip=false
and fix them with mvn spotless:apply
.
if (valueConverter instanceof ValueConverter) { | ||
DecimalType nativeValue = ((ValueConverter) valueConverter) | ||
.onCommandFromItem(decimalType.doubleValue()); | ||
subHandler.handleCommandDecimal(nativeValue, channelGroup, number.get()); | ||
}else{ |
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.
This casting bothers me a bit. Is there an other way?
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.
Sorry, had some issues with my eclipse/EGit installation. I hopefully managed to "clean" the branch from the commits not belonging to this PR, but I still have the following issues:
- I can't satisfy DCO (your commit apparently was missing signature). Tried to apply the steps mentioned in the DCO log but with no success.
- J-N-K is still listed as a reviewer for this PR, although the commits not belonging to this PR are now (hopefully) removed.
To your question regarding the cast: One could move ValueConverter.onCommandFromItem(double)
and ValueConverter.onCommandFromItem(QuantityType<?>)
up to Converter
again making them Nullable
so InversionConverter
could return null
. But in my opinion this would violate separation of concerns, see my last comment.
From a design perspective it might be better to separate conversion for representation (lcn bus -> UI) from conversion of commands (UI -> lcn bus) leading to two different converter hierarchies/interfaces, e.g. StateRepresentationConverter.onStateUpdateFromHandler
and CommandConverter.onCommandFromItem
- or to be okay with the casting ;-)
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.
I'd go for a modified version of your first proposal. Move the methods back to Converter
. Make Converter
a class and add a default implementation for all four methods, that return the identity. Then, Nullable is not needed. Casting, instanceof
and semantic based null values violate OOP paradigms most often.
I don't think splitting the converters by the message direction doesn't solve the problem as the differentiation between values and binary states is still necessary.
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.
Converters refactored as you requested.
Travis tests were successfulHey @toweosp, |
Travis tests have failedHey @toweosp, |
1 similar comment
Travis tests have failedHey @toweosp, |
Travis tests were successfulHey @toweosp, |
Travis tests have failedHey @toweosp, |
1 similar comment
Travis tests have failedHey @toweosp, |
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.
Thanks! Just one small change.
bundles/org.openhab.binding.lcn/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
Travis tests have failedHey @toweosp, |
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
Can you adopt the sign-off of my commit to the merge commit 507251a to satisfy the DCO check? |
Signed-off-by: Fabian Wolter <[email protected]>
References PR #8102 Signed-off-by: Thomas Weiler <[email protected]>
Signed-off-by: Thomas Weiler <[email protected]>
Signed-off-by: Thomas Weiler <[email protected]>
Travis tests have failedHey @toweosp, |
Done (beside failing jdk11 build #8094) |
Can you fix the conflicts raised by the other PR? |
Travis tests have failedHey @toweosp, |
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
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]> Signed-off-by: MPH80 <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]> Signed-off-by: Bernhard <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]> Signed-off-by: Daan Meijer <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
…nel (openhab#8102) Closes openhab#8069 Signed-off-by: Thomas Weiler <[email protected]>
Added configuration option invertOpenClosed to binarysensor channel. Per default lcn binary sensor state 0 corresponds to "closed" while 1 corresponds to "open". Use this parameter to invert that logic.
closes #8069