+def check_pcu_state(rec, pcu):
+
+ pcu_state = rec.reboot_trial_status
+
+ # DOWN
+ if pcu_state not in [0, "0"] and pcu.status not in ['offline', 'down']:
+ print "changed status from %s to offline" % pcu.status
+ pcu.status = 'offline'
+ pcu.last_changed = datetime.now()
+
+ # ONLINE
+ if pcu_state in [0, "0"] and pcu.status not in [ 'online', 'good' ]:
+ print "changed status from %s to online" % pcu.status
+ pcu.status = 'online'
+ pcu.last_changed = datetime.now()
+
+
+ # STATE TRANSITIONS
+ if pcu.status == 'online' and changed_greaterthan(pcu.last_changed, 0.5):
+ #send thank you notice, or on-line notice.
+ print "changed status from %s to good" % pcu.status
+ pcu.status = 'good'
+ # NOTE: do not reset last_changed, or you lose how long it's been up.
+
+ if pcu.status == 'offline' and changed_greaterthan(pcu.last_changed, 2):
+ # send down pcu notice
+ print "changed status from %s to down" % pcu.status
+ pcu.status = 'down'
+
+# if pcu.status in [ 'offline', 'down' ] and changed_greaterthan(pcu.last_changed, 2*30):
+# print "changed status from %s to down" % pcu.status
+# pcu.status = 'down'
+# pcu.last_changed = datetime.now()
+