|
|
|
@ -1,10 +1,15 @@
|
|
|
|
|
import fcntl
|
|
|
|
|
import random
|
|
|
|
|
import threading
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
from .base import Sensor, sensor
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import fcntl
|
|
|
|
|
import threading
|
|
|
|
|
CO2_IMPORTS = True
|
|
|
|
|
except ImportError:
|
|
|
|
|
CO2_IMPORTS = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sensor
|
|
|
|
|
class FakeSensor(Sensor):
|
|
|
|
@ -28,6 +33,9 @@ class CO2Meter(Sensor):
|
|
|
|
|
def __init__(self, dev_path, **sensor_conf):
|
|
|
|
|
super(CO2Meter, self).__init__(**sensor_conf)
|
|
|
|
|
|
|
|
|
|
if not CO2_IMPORTS:
|
|
|
|
|
raise RuntimeError("Missing threading or fnctl to run this sensor")
|
|
|
|
|
|
|
|
|
|
self.dev_path = dev_path
|
|
|
|
|
self.key = b'\x11\x11\x11\x11\x11\x11\x11\x11'
|
|
|
|
|
self._dev = None
|
|
|
|
@ -91,9 +99,9 @@ class CO2Meter(Sensor):
|
|
|
|
|
print("Device error: {} - trying to reopen".format(e))
|
|
|
|
|
self.values = {}
|
|
|
|
|
try:
|
|
|
|
|
self._dev.close()
|
|
|
|
|
self._dev.close()
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
pass
|
|
|
|
|
while self._dev.closed:
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
try:
|
|
|
|
@ -101,7 +109,6 @@ class CO2Meter(Sensor):
|
|
|
|
|
except (IOError, OSError) as e:
|
|
|
|
|
print("Device error: {} - trying to reopen".format(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_co2(self):
|
|
|
|
|
if 0x50 in self.values:
|
|
|
|
|
return self.values[0x50]
|
|
|
|
@ -123,7 +130,6 @@ class CO2Meter(Sensor):
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
import argparse
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument("device", help="Device do read from")
|
|
|
|
|