control.py 875 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:admin.py
  6. author:rabin
  7. """
  8. import time
  9. from demeter.core import *
  10. # 处理定时命令、周期命令、条件控制、消息、设备状态等
  11. timeSleep = 10
  12. # 更改控制设备的超时状态
  13. def control():
  14. model = Demeter.model('device_info')
  15. cur = Demeter.time() - 10
  16. model.operdate.assgin(cur, '<=')
  17. model.oper = True
  18. model.hardware_type = 3
  19. service = Demeter.service('device')
  20. data = model.select()
  21. if data:
  22. for v in data:
  23. model.id = v['id']
  24. if v['exp'] == '-1':
  25. msg = service.notice('timeout')
  26. service.mul(v, v['name'] + '失败:' + msg, False)
  27. model.update(exp=msg, oper=True, operdate=Demeter.time())
  28. else:
  29. msg = '1'
  30. service.mul(v, '', True)
  31. model.update(exp=msg, oper=False, operdate=Demeter.time())
  32. while 1:
  33. control()
  34. time.sleep(timeSleep)