From 6ab8d0aaa66f0ea0b4533db47123dc3c8e8ec5b8 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 25 Jan 2017 18:08:44 +0500 Subject: Rise ignition events only if both positions has ignition attribute --- src/org/traccar/events/IgnitionEventHandler.java | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java index 8464c3aef..187b7ce73 100644 --- a/src/org/traccar/events/IgnitionEventHandler.java +++ b/src/org/traccar/events/IgnitionEventHandler.java @@ -39,20 +39,21 @@ public class IgnitionEventHandler extends BaseEventHandler { Collection result = null; - boolean ignition = position.getBoolean(Position.KEY_IGNITION); - - boolean oldIgnition = false; - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); - if (lastPosition != null) { - oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION); - } - - if (ignition && !oldIgnition) { - result = Collections.singleton( - new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId())); - } else if (!ignition && oldIgnition) { - result = Collections.singleton( - new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId())); + if (position.getAttributes().containsKey(Position.KEY_IGNITION)) { + boolean ignition = position.getBoolean(Position.KEY_IGNITION); + + Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) { + boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION); + + if (ignition && !oldIgnition) { + result = Collections.singleton( + new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId())); + } else if (!ignition && oldIgnition) { + result = Collections.singleton( + new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId())); + } + } } return result; } -- cgit v1.2.3 From d0cb885b152d5db3913936c8f1b57e690a47a067 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 26 Jan 2017 10:31:35 +0500 Subject: Fix ignition test --- test/org/traccar/events/IgnitionEventHandlerTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/org/traccar/events/IgnitionEventHandlerTest.java b/test/org/traccar/events/IgnitionEventHandlerTest.java index ad329d139..d6c348c77 100644 --- a/test/org/traccar/events/IgnitionEventHandlerTest.java +++ b/test/org/traccar/events/IgnitionEventHandlerTest.java @@ -1,7 +1,6 @@ package org.traccar.events; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.util.Collection; @@ -21,9 +20,7 @@ public class IgnitionEventHandlerTest extends BaseTest { position.set(Position.KEY_IGNITION, true); position.setValid(true); Collection events = ignitionEventHandler.analyzePosition(position); - assertNotNull(events); - Event event = (Event) events.toArray()[0]; - assertEquals(Event.TYPE_IGNITION_ON, event.getType()); + assertEquals(events, null); } } -- cgit v1.2.3