def sample(self):
     s = Sensor.sample(self)
     # Exceeded the max value...probably out of range.
     if s > self.maxVal:
         ret = Sensor.UNKNOWN
     else:
         ret = s * self.rangeInMeters / self.maxVal
     
     return ret
Beispiel #2
0
co2State = StateAlerter(
    {
        "safe" :        0,
        "risky" :       1000,
        "serious" :     2000,
        "dangerous" :   5000,
        "fatal" :       40000
    },
    "safe",
    notifier.send_co2_up_notification,
    notifier.send_co2_down_notification
)

vocState = StateAlerter(
    {
        "safe" :      0,
        "risky" :     560,
        "dangerous" : 1150
    },
    "safe",
    notifier.send_voc_up_notification,
    notifier.send_voc_down_notification
)

while True:
    time.sleep(1)
    co2, voc = sensor.sample()
    co2State.update(co2)
    vocState.update(voc)