diff --git a/sensors.py b/sensors.py index fa82233..5abc371 100644 --- a/sensors.py +++ b/sensors.py @@ -28,15 +28,13 @@ class GPIOState(Sensor): def __init__(self, pin, transform=lambda x: 1-x): self.pin = pin self.transform = transform - - self.value = GPIO.input(self.pin) - self.update_time() - - def update_time(self): - self.time = perf_counter() def read(self): - self.value = GPIO.input(self.pin) + try: + self.value = GPIO.input(self.pin) + except: + self.value = None + self.time = perf_counter() return (self.time, self.transform(self.value))