core.py 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 pic import pic
  11. from demeter.mqtt import *
  12. # 处理定时命令、周期命令、条件控制、消息、设备状态等
  13. timeSleep = 1000
  14. # 开关设备
  15. def switch(value):
  16. Demeter.service('device').switchMul(value)
  17. def loop():
  18. while 1:
  19. model = Demeter.model('device_set_loop')
  20. cur = Demeter.time()
  21. date = Demeter.date(cur, '%Y-%m-%d-%w-%H-%M')
  22. date = date.split('-')
  23. week = date[3]
  24. day = date[2]
  25. model.status = True
  26. model.hour = date[4]
  27. model.minute = date[5]
  28. data = model.select()
  29. if data:
  30. for value in data:
  31. state = False
  32. value['loop'] = value['loop'].split(',')
  33. if value['looptype'] == 2:
  34. if week in value['loop']:
  35. state = True
  36. elif value['looptype'] == 3:
  37. if day in value['loop']:
  38. state = True
  39. if state:
  40. switch(value)
  41. time.sleep(timeSleep)
  42. loop()