12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:admin.py
- author:rabin
- """
- import time
- from demeter.core import *
- from pic import pic
- from demeter.mqtt import *
- # 处理定时命令、周期命令、条件控制、消息、设备状态等
- timeSleep = 1000
- # 开关设备
- def switch(value):
- Demeter.service('device').switchMul(value)
-
- def loop():
- while 1:
- model = Demeter.model('device_set_loop')
- cur = Demeter.time()
- date = Demeter.date(cur, '%Y-%m-%d-%w-%H-%M')
- date = date.split('-')
- week = date[3]
- day = date[2]
- model.status = True
- model.hour = date[4]
- model.minute = date[5]
- data = model.select()
- if data:
- for value in data:
- state = False
- value['loop'] = value['loop'].split(',')
- if value['looptype'] == 2:
- if week in value['loop']:
- state = True
- elif value['looptype'] == 3:
- if day in value['loop']:
- state = True
- if state:
- switch(value)
- time.sleep(timeSleep)
- loop()
|