Repository: missionpinball/mpf

Issue:
Only reset drop target banks when they are not reset
Currently we always trigger a reset no matter if the bank of up or down. Mirror the behavior of reset on individual drop targets. See this thread for an example: https://groups.google.com/forum/#!topic/mpf-users/kHq3dM1PMyo

Discussion:

Patch:
diff --git a/mpf/devices/drop_target.py b/mpf/devices/drop_target.py
index 2ac95d3b5..e6eb21095 100644
--- a/mpf/devices/drop_target.py
+++ b/mpf/devices/drop_target.py
@@ -326,11 +326,18 @@ class DropTargetBank(SystemWideDevice, ModeDevice):
         del kwargs
         self.debug_log('Resetting')
 
+        if self.down == 0:
+            self.info_log('All targets are already up. Will not reset bank.')
+            return
+        else:
+            self.info_log('%s targets are down. Will reset those.', self.down)
+
         # figure out all the coils we need to pulse
         coils = set()       # type: Set[Driver]
 
         for drop_target in self.drop_targets:
-            if drop_target.reset_coil:
+            # add all reset coil for targets which are down
+            if drop_target.reset_coil and drop_target.complete:
                 coils.add(drop_target.reset_coil)
 
         for coil in self.reset_coils:


Test patch:
diff --git a/mpf/tests/test_DropTargets.py b/mpf/tests/test_DropTargets.py
index 9b672f623..9be9c3b93 100644
--- a/mpf/tests/test_DropTargets.py
+++ b/mpf/tests/test_DropTargets.py
@@ -58,6 +58,16 @@ class TestDropTargets(MpfTestCase):
         self.assertFalse(self.machine.drop_targets.left3.complete)
         self.assertFalse(self.machine.drop_target_banks.left_bank.complete)
 
+        # check that the bank does not reset if already down
+        self.machine.coils.coil1.pulse = MagicMock()
+        self.machine.drop_target_banks['left_bank'].reset()
+        assert not self.machine.coils.coil1.pulse.called
+
+        # reset should work with one target down
+        self.hit_switch_and_run("switch1", 1)
+        self.machine.drop_target_banks['left_bank'].reset()
+        self.machine.coils.coil1.pulse.assert_called_once_with(max_wait_ms=100)
+
     def test_knockdown_and_reset(self):
         self.mock_event("unexpected_ball_on_playfield")
         self.machine.coils.coil2.pulse = MagicMock(wraps=self.machine.coils.coil2.pulse)