Skip to content

Commit

Permalink
Fix openhab#6939 - Forced channel triggering without previous state (o…
Browse files Browse the repository at this point in the history
…penhab#10356)

Signed-off-by: Gabor Bicskei <[email protected]>
  • Loading branch information
gbicskei authored Mar 31, 2021
1 parent c474550 commit e73a716
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions bundles/org.openhab.binding.gpstracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ After a location message received from the tracker the log should contain these
2018-10-05 09:27:58.794 [TRACE] [cker.internal.handler.TrackerHandler] - System uses SI measurement units. No conversion is needed.
```

**Note**: If the binding was restarted or the distance channel is new (this is the first location message for the channel) only the second location update will trigger event as the binding has to know the previous state.

### External Region and Presence Switch

Assumptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,20 @@ public void handleCommand(ChannelUID channelUID, Command command) {
*/
private void updateTriggerChannelsWithTransition(TransitionMessage message) {
String regionName = message.getRegionName();
triggerRegionChannel(regionName, message.getEvent());
triggerRegionChannel(regionName, message.getEvent(), true);
}

/**
* Fire trigger event with regionName/enter|leave payload but only if the event differs from the last event.
*
* @param regionName Region name
* @param event Occurred event
* @param forced Force channel triggering in case the transition event is received from the mobile application.
*/
private void triggerRegionChannel(@NonNull String regionName, @NonNull String event) {
private void triggerRegionChannel(@NonNull String regionName, @NonNull String event, boolean forced) {
Boolean lastState = lastTriggeredStates.get(regionName);
Boolean newState = EVENT_ENTER.equals(event);
if (!newState.equals(lastState) && lastState != null) {
if (!newState.equals(lastState) || forced) {
String payload = regionName + "/" + event;
triggerChannel(CHANNEL_REGION_TRIGGER, payload);
lastTriggeredStates.put(regionName, newState);
Expand Down Expand Up @@ -327,9 +328,9 @@ private void updateDistanceChannelFromMessage(LocationMessage message, Channel c
// convert into meters which is the unit of the calculated distance
double radiusMeter = convertToMeters(ConfigHelper.getRegionRadius(c.getConfiguration()));
if (radiusMeter > newDistance) {
triggerRegionChannel(regionName, EVENT_ENTER);
triggerRegionChannel(regionName, EVENT_ENTER, false);
} else {
triggerRegionChannel(regionName, EVENT_LEAVE);
triggerRegionChannel(regionName, EVENT_LEAVE, false);
}
}
}
Expand Down

0 comments on commit e73a716

Please sign in to comment.