mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Replace Event.wait(0) with Event.is_set()
The functionality is identical, and IMHO the latter is much more readable
This commit is contained in:
@@ -162,7 +162,7 @@ class SmoothedInputDevice(EventsMixin, InputDevice):
|
||||
except DeviceClosed:
|
||||
return super(SmoothedInputDevice, self).__repr__()
|
||||
else:
|
||||
if self.partial or self._queue.full.wait(0):
|
||||
if self.partial or self._queue.full.is_set():
|
||||
return super(SmoothedInputDevice, self).__repr__()
|
||||
else:
|
||||
return "<gpiozero.%s object on pin=%r, pull_up=%s>" % (
|
||||
|
||||
@@ -234,7 +234,7 @@ class EventsMixin(object):
|
||||
The length of time (in seconds) that the device has been active for.
|
||||
When the device is inactive, this is ``None``.
|
||||
"""
|
||||
if self._active_event.wait(0):
|
||||
if self._active_event.is_set():
|
||||
return time() - self._last_changed
|
||||
else:
|
||||
return None
|
||||
@@ -245,7 +245,7 @@ class EventsMixin(object):
|
||||
The length of time (in seconds) that the device has been inactive for.
|
||||
When the device is active, this is ``None``.
|
||||
"""
|
||||
if self._inactive_event.wait(0):
|
||||
if self._inactive_event.is_set():
|
||||
return time() - self._last_changed
|
||||
else:
|
||||
return None
|
||||
@@ -434,11 +434,11 @@ class HoldThread(GPIOThread):
|
||||
self.start()
|
||||
|
||||
def held(self, parent):
|
||||
while not self.stopping.wait(0):
|
||||
while not self.stopping.is_set():
|
||||
if self.holding.wait(0.1):
|
||||
self.holding.clear()
|
||||
while not (
|
||||
self.stopping.wait(0) or
|
||||
self.stopping.is_set() or
|
||||
parent._inactive_event.wait(parent.hold_time)
|
||||
):
|
||||
if parent._held_from is None:
|
||||
|
||||
@@ -64,20 +64,20 @@ def test_input_event_activated():
|
||||
pin = MockPin(2)
|
||||
with DigitalInputDevice(pin) as device:
|
||||
device.when_activated = lambda: event.set()
|
||||
assert not event.wait(0)
|
||||
assert not event.is_set()
|
||||
pin.drive_high()
|
||||
assert event.wait(0)
|
||||
assert event.is_set()
|
||||
|
||||
def test_input_event_deactivated():
|
||||
event = Event()
|
||||
pin = MockPin(2)
|
||||
with DigitalInputDevice(pin) as device:
|
||||
device.when_deactivated = lambda: event.set()
|
||||
assert not event.wait(0)
|
||||
assert not event.is_set()
|
||||
pin.drive_high()
|
||||
assert not event.wait(0)
|
||||
assert not event.is_set()
|
||||
pin.drive_low()
|
||||
assert event.wait(0)
|
||||
assert event.is_set()
|
||||
|
||||
def test_input_wait_active():
|
||||
pin = MockPin(2)
|
||||
|
||||
@@ -160,15 +160,15 @@ def test_mock_pin_edges():
|
||||
pin.when_changed = changed
|
||||
pin.drive_high()
|
||||
assert pin.state
|
||||
assert fired.wait(0)
|
||||
assert fired.is_set()
|
||||
fired.clear()
|
||||
pin.edges = 'falling'
|
||||
pin.drive_low()
|
||||
assert not pin.state
|
||||
assert fired.wait(0)
|
||||
assert fired.is_set()
|
||||
fired.clear()
|
||||
pin.drive_high()
|
||||
assert pin.state
|
||||
assert not fired.wait(0)
|
||||
assert not fired.is_set()
|
||||
assert pin.edges == 'falling'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user