control.py 913 B

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