# -*- coding: utf-8 -*-
"""
    demeter web
    name:admin.py
    author:rabin
"""
import time
from demeter.core import *
# 处理定时命令、周期命令、条件控制、消息、设备状态等
timeSleep = 10

# 更改控制设备的超时状态
class Control(object):

	def run(self):
		self.handle()
		time.sleep(timeSleep)

	def handle(self):
		model = Demeter.model('device_info')
		cur = Demeter.time() - 10
		model.operdate.assign(cur, '<=')
		model.oper = True
		model.hardware_type = 3
		service = Demeter.service('device')
		data = model.select()
		if data:
			for v in data:
				model.id = v['id']
				if v['exp'] == '-1':
					msg = service.notice('timeout')
					service.mul(v, v['name'] + '失败:' + msg, False)
					model.update(exp=msg, oper=True, operdate=Demeter.time())
				else:
					msg = '1'
					service.mul(v, '', True)
					model.update(exp=msg, oper=False, operdate=Demeter.time())