timing.py 800 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. from gevent import monkey; monkey.patch_socket()
  11. import gevent
  12. from pic import pic
  13. from demeter.mqtt import *
  14. # 处理定时命令、周期命令、条件控制、消息、设备状态等
  15. timeSleep = 10
  16. # 开关设备
  17. def switch(value):
  18. Demeter.service('device').switchMul(value)
  19. def timing():
  20. while 1:
  21. model = Demeter.model('device_set_timing')
  22. model.status = 0
  23. cur = Demeter.time()
  24. model.zdate.assgin(cur, '<=')
  25. data = model.select()
  26. if data:
  27. for value in data:
  28. switch(value)
  29. model.id = value['id']
  30. model.update(status=1)
  31. gevent.sleep(timeSleep)
  32. def handle():
  33. gevent.joinall([
  34. gevent.spawn(timing),
  35. ])
  36. handle()