I have a problem with reading a knx scene in openhab. I was upgrading openhab to V2.3.0-SNAPSHOT and use the KNX Binding:
212 │ Active │ 80 │ 2.3.0.201803311310 │ KNX Binding
I am using a byte-scene, so the Number-Item is configurated as followed: 18.001:15/0/0 (via PaperUI)
With the KNX 1.x it was working well. Now I saw in the log file that I got a KNXFormatException.
2018-04-01 16:13:23.906 [INFO ] [g.knx.internal.dpt.KNXCoreTypeMapper] - Translator couldn't parse data for datapoint type '18.001' (KNXFormatException).
2018-04-01 16:13:23.909 [WARN ] [.internal.handler.DeviceThingHandler] - Ignoring KNX bus data: couldn't transform to any Type (destination='15/0/0', datapoint='command DP 15/0/0 'knx:device:KNXToRaspbi', DPT id 18.001, low priority', data='0x00')
The data which I receive (data=0x00) is correct (because it is scene 0). If I press the button to learn the scene I get data=0x80. So data is comming correct only parsing it is failing.
Can someone please help in this case. All other KNX items (switch, dimmer) are working fine.
I tried out some stuff for myself to solve this problem. At first I checked out the source code and took a look with eclipse. I found out that the exception appears because of calling the method “getNumericValue” of the class DPTXlator. It can be found in KNXCoreTypeMapper.
public double getNumericValue() throws KNXFormatException
{
throw new KNXFormatException("No simple numeric representation possible");
}
In case of a scene there should be used the class DPTXlatorSceneControl and the method getSceneNumber
/**
* Returns the scene number of the first translation item.
*
* @return unsigned 6 Bit using type short
*/
public final short getSceneNumber()
{
return (short) (data[0] & 0x3F);
}
There exists a switch case where the number of scene is read out but not returned (case 18).
case 2:
DPTXlator1BitControlled translator1BitControlled = (DPTXlator1BitControlled) translator;
int decValue = (translator1BitControlled.getControlBit() ? 2 : 0)
+ (translator1BitControlled.getValueBit() ? 1 : 0);
return new DecimalType(decValue);
...
case 18:
DPTXlatorSceneControl translatorSceneControl = (DPTXlatorSceneControl) translator;
int decimalValue = translatorSceneControl.getSceneNumber();
if (value.startsWith("learn")) {
decimalValue += 0x80;
}
value = String.valueOf(decimalValue);
break;
case 19:
...
I replaced break with return new DecimalType(decimalValue);. Then it was working.
Hopefully someone can change it and upload it to github. I am not very familar using it.
Please give any response if it makes sense, or maybe I am still working in a wrong way with the scenes??