Makes `value` an alias of `is_active` in the base `GPIODevice`, and
`values` an infinite iterable of this value. Then adds `source` property
to `OutputDevice` allowing simple linkage of devices via iterators.
This commit is contained in:
Dave Jones
2015-10-19 08:19:52 +01:00
parent 3230f3ae18
commit f6294a5bf4
2 changed files with 53 additions and 2 deletions

View File

@@ -155,12 +155,25 @@ class GPIODevice(object):
return self._pin
@property
def is_active(self):
def value(self):
"""
Returns `True` if the device is currently active and `False` otherwise.
"""
return self._read()
is_active = value
@property
def values(self):
"""
An infinite iterator of values read from `value`.
"""
while True:
try:
yield self.value
except GPIODeviceClosed:
break
def __repr__(self):
try:
return "<gpiozero.%s object on pin=%d, is_active=%s>" % (