Skip to content

Commit

Permalink
[innogysmarthome] Improved handling pushbutton
Browse files Browse the repository at this point in the history
Not all devices send same push button events. Some send 2 (StateChanged and ButtonPressed) others only 1 (StateChanged).
When ButtonPressed is send the StateChanged doesn't contain lastPressedButtonIndex. So in that case we ignore the StateChanged event.
The previous implementation assumed type was also always present, but that is not the case so it can't be used as an check.

Closes openhab#6624

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand committed Dec 23, 2019
1 parent 26ca3db commit 6c51d77
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -815,20 +815,24 @@ public void onDeviceStateChanged(final Device changedDevice, final Event event)

// PushButtonSensor
} else if (capability.isTypePushButtonSensor()) {
// if the same button is pressed more than once
// the buttonIndex and LastKeyPressCounter come with two events
// updates should only do when arriving value
// Some devices send both StateChanged and ButtonPressed. But only one should be handled.
// If ButtonPressed is send lastPressedButtonIndex is not set in StateChanged so ignore
// StateChanged.
// type is also not always present if null will be interpreted as a normal key press.
final Integer tmpButtonIndex = event.getProperties().getLastPressedButtonIndex();
final Integer tmpLastKeyPressCounter = event.getProperties().getLastKeyPressCounter();
final String lastKeyPressType = event.getProperties().getLastKeyPressType();
if (tmpButtonIndex != null && lastKeyPressType != null) {

if (tmpButtonIndex != null) {
capabilityState.setPushButtonSensorButtonIndexState(tmpButtonIndex);
capabilityState.setPushButtonSensorButtonIndexType(lastKeyPressType);
}
if (tmpLastKeyPressCounter != null) {
capabilityState.setPushButtonSensorCounterState(tmpLastKeyPressCounter);
capabilityState
.setPushButtonSensorButtonIndexType(event.getProperties().getLastKeyPressType());

final Integer tmpLastKeyPressCounter = event.getProperties().getLastKeyPressCounter();

if (tmpLastKeyPressCounter != null) {
capabilityState.setPushButtonSensorCounterState(tmpLastKeyPressCounter);
}
deviceChanged = true;
}
deviceChanged = true;

// EnergyConsumptionSensor
} else if (capability.isTypeEnergyConsumptionSensor()) {
Expand Down

0 comments on commit 6c51d77

Please sign in to comment.