-
-
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
[knx] Allow sending items with units to KNX bus. #12675
Conversation
57ebea3
to
05bca23
Compare
...penhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/KNXCoreTypeMapper.java
Show resolved
Hide resolved
...penhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/KNXCoreTypeMapper.java
Outdated
Show resolved
Hide resolved
case 23: { | ||
final String unit = qt.getUnit().toString(); | ||
if (unit.contains("°C")) { | ||
targetOhUnit = "°C/%"; |
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.
What is this unit ?
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.
9.023 DPT_KelvinPerPercent, this is a delta and we need to convert to the matching base unit first (automatic conversion °C to K or °F will fail due to the offset/scaling)
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.
In fact, my question was: is "°C/%" is a valid unit supported by UoM ?
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.
Actually is seem so. DSL rules let you construct this
var k = 25|K
var p = 10|%
var result = k/p
var dimensionless = p.toUnit("")
Printing to the log gets you
...script.UoM ] - this is k: 25 K
...script.UoM ] - this is p: 10 %
...script.UoM ] - this is k/p: 2.5 K/%
...script.UoM ] - this is p converted to dimensionless: 0.1
The values are sent to the KNX bus when I use sendCommand, both tested with items defined as Number and Number:Temperature. It leads to same value on KNX side.
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, strange but if you tested it, I believe you.
...penhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/KNXCoreTypeMapper.java
Outdated
Show resolved
Hide resolved
...penhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/KNXCoreTypeMapper.java
Outdated
Show resolved
Hide resolved
@SJKA : would you like to review ? |
05bca23
to
9a2a491
Compare
@lolodomo thanks for reviewing this |
9a2a491
to
c0905da
Compare
I see "Simon Kaufmann" as author of a lot of classes. Is sjka =Simon Kaufmann ? This is probable... @kaikreuzer : do you know if there still a maintainer for the KNX maintainer ? If not, I will merge this PR without waiting. |
@lolodomo but to me it seems that GitHub re-issued this user account to someone else... Just have a look at the two user profiles mentioned above |
@lolodomo Yes, I think Simon is no longer active here - I have thus created #12694 and added me as a code owner as I was the original author of the 1.x binding (the first binding ever written for openHAB ;-)). |
Yes please |
key, expectedTypeClass, command, dpt); | ||
return new WriteSpecImpl(config, dpt, command); | ||
} | ||
} | ||
if (command instanceof QuantityType) { |
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.
Hm, is it really correct to do an independent "if" here and not check at all the dpt anymore?
I would expect the typeHelper
in line 173 to return DecimalType
as the expectedTypeClass
.
If this is the case, we would probably only need to adapt line 175 to
if (expectedTypeClass.isAssignableFrom(command.getClass())) {
so that it also evaluates to true, if command
is a QuantityType and not only if it is a DecimalType.
Wdyt? Am I missing something?
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.
@kaikreuzer I just did a quick check: expectedTypeClass
returns DecimalType
, command.getClass()
is QuantityType
and isAssignableFrom
returns false.
I don't think that we nedd to check the dpt - the type conversion will anyway only work if the unit conversion is possible.
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.
You're right, I forgot that QuantityType
does not extend DecimalType
. 😞
I would nonetheless prefer to do a proper check of the type in the if clause.
If expectedTypeClass
is null, we should never proceed, so the code should imho move into the if statement above.
And then we could simply enhance line 175 to
if (expectedTypeClass.isInstance(command) || (expectedTypeClass==DecimalType.class && command instanceof QuantityType<?>)) {
(and slightly change the tracing message).
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 looks reasonable, updated code as requested.
Thanks Kai!
c0905da
to
075ae7e
Compare
Items with dimensions (QuantityType) are now translated and can be sent to the KNX bus. This requires the correct DPT to be specified in the channel definition. Fixes openhab#10706. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
075ae7e
to
a103d1e
Compare
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.
Great, thank you!
@holgerfriedrich @kaikreuzer: I debug the component to send items with unit yesterday because my humidity sensor was not working and always got getCommandSpec no Spec found. |
Items with dimensions (QuantityType) are now translated and can be sent to the KNX bus. This requires the correct DPT to be specified in the channel definition. Fixes openhab#10706. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Items with dimensions (QuantityType) are now translated and can be sent to the KNX bus. This requires the correct DPT to be specified in the channel definition. Fixes openhab#10706. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
Items with dimensions (QuantityType) are now translated and can be sent to the KNX bus. This requires the correct DPT to be specified in the channel definition. Fixes openhab#10706. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Items with dimensions (QuantityType) are now translated and can be sent to the
KNX bus. This requires the correct DPT to be specified in the channel
definition. Fixes #10706.
Signed-off-by: Holger Friedrich mail@holger-friedrich.de