Closed WindnSalt closed 6 years ago
@CptMW which version do you use? Could you, for debugging, uncomment https://github.com/snowdd1/homebridge-knx/blob/6e17c099857a0efc2ee191ca6a90df8608ad90f7/lib/knxaccess.js#L211-L215 to produce debug output? I think there might be something in the parser. Reverse is not so commonly used, it's tending to break quite unnoticed.
Turned on the debugging as you suggested and couldn't resist to dig deeper. The debugging output was in sync with the observed behavior. So I looked into how the characteristics object is created and finally realized I did not pay attention to how the JSON parser interprets types. In my knx_config.json I had:
"Reverse": "true"
With
"Reverse": true
everything worked just fine.
In order to make this a bit more robust, I tried converting the Reverse member of the config object into a Boolean in the constructor of the CharacteristicKNX object. I changed lines 116 and 160 in characteristic-knx.js into
reversed: (Boolean(this.config.Reverse)===true),
In case it is noted as a Boolean in the knx_config.json that does not do much. In case it is noted as a string it would convert Reverse into a Boolean and therefore Reverse would be interpreted as intended. If you want I can prepare a pull request.
Problem with (Boolean(this.config.Reverse)===true)
is that it would make the string "false"
become true also, because any non-empty string is true-ish AFAIK.
I'd better put an extra hint into the READMEs.
While trying to integrate a reversed switch I ran into an issue. From the logs it looks like the reverse flag is read during configuration parsing, but while switching the flag is not considered. See config and logs attached.
knx_config.json - Reverse: true
homebridge.log: startup - Reverse: true
homebridge.log: Device off / on - Reverse: true
knx_config.json - Reverse: false
homebridge.log: startup - Reverse: false
homebridge.log: Device off / on - Reverse: false