rabin 7 years ago
parent
commit
f2a290ce01
2 changed files with 15 additions and 36 deletions
  1. 0 15
      cron.py
  2. 15 21
      service/device.py

+ 0 - 15
cron.py

@@ -46,21 +46,6 @@ def control():
 		data = model.select()
 		for v in data:
 			model.id = v['id']
-			type_model.id = v['type_id']
-			type_info = type_model.select(type='fetchone')
-			oper = ''
-			if type_info['unit'] == 'button':
-				if v['cxnum'] == 1:
-					oper = '升起'
-				elif v['cxnum'] == 2:
-					oper = '降下'
-				elif v['cxnum'] == 5:
-					oper = '停止'
-			else:
-				if v['cxnum'] == 1:
-					oper = '开启'
-				else:
-					oper = '关闭'
 			if v['exp'] == '-1':
 				msg = service.notice('timeout')
 				service.mul(v['id'], v['name'], v['cxnum'], '失败:' + msg, False, oper=oper)

+ 15 - 21
service/device.py

@@ -92,7 +92,7 @@ class Device(object):
 			msg = self.notice('offline')
 			model.id = device_id
 			model.update(exp=msg, cxnum=switch)
-			self.mul(info['id'], info['name'], switch, '失败:' + msg, False)
+			self.mul(info['id'], info['name'], switch, '失败:' + msg, False, oper=oper)
 			#Demeter.error('offline')
 
 	# 处理开关-响应
@@ -104,29 +104,13 @@ class Device(object):
 			model.id = info['gateway_id']
 			gateway = model.select(type='fetchone')
 
-			model = Demeter.model('device_type')
-			model.id = info['type_id']
-			type_info = model.select(type='fetchone')
-			if type_info['unit'] == 'button':
-				if param['switch'] == 1:
-					oper = '升起'
-				elif param['switch'] == 2:
-					oper = '降下'
-				elif param['switch'] == 5:
-					oper = '停止'
-			else:
-				if param['switch'] == 1:
-					oper = '开启'
-				else:
-					oper = '关闭'
-						
 			if msg == 'ok':
 				model = Demeter.model('device_info')
 				model.id = info['id']
 				model.update(value=param['switch'], exp='1')
 
 				# 如果有批量控制
-				self.mul(info['id'], info['name'], param['switch'], '成功', True, oper=oper)
+				self.mul(info['id'], info['name'], param['switch'], '成功', True)
 			else:
 				msg = self.notice(msg)
 				model = Demeter.model('device_info')
@@ -134,7 +118,7 @@ class Device(object):
 				model.update(exp=msg)
 
 				# 如果有批量控制
-				self.mul(info['id'], info['name'], param['switch'], '失败:' + msg, False, oper=oper)
+				self.mul(info['id'], info['name'], param['switch'], '失败:' + msg, False)
 
 				content = oper + gateway['name'] + '下的'+ info['name'] + '失败,错误提示:' + msg
 				Demeter.service('record').msg(info['id'], content, info['farm_id'], 3)
@@ -149,7 +133,7 @@ class Device(object):
 			msg = info['name']
 		return msg
 
-	def mul(self, id, name, switch, msg, state, oper=''):
+	def mul(self, id, name, switch, msg, state):
 		model = Demeter.model('device_mul_queue')
 		model.device_id = id
 		queue = model.select()
@@ -161,7 +145,17 @@ class Device(object):
 			if msg:
 				for v in queue:
 					model.id = v['mul_id']
-					if not oper:
+					type_model = Demeter.model('device_type')
+					type_model.id = info['type_id']
+					type_info = type_model.select(type='fetchone')
+					if type_info['unit'] == 'button':
+						if switch == 1:
+							oper = '升起'
+						elif switch == 2:
+							oper = '降下'
+						elif switch == 5:
+							oper = '停止'
+					else:
 						if switch == 1:
 							oper = '开启'
 						else: