rabin 7 years ago
parent
commit
5268558ce1
3 changed files with 41 additions and 25 deletions
  1. 21 6
      cron.py
  2. 2 2
      front/templates/pc/device/mul.html
  3. 18 17
      service/device.py

+ 21 - 6
cron.py

@@ -9,7 +9,7 @@ import time
 from demeter.core import *
 from gevent import monkey; monkey.patch_socket()
 import gevent
-from pic import pic
+#from pic import pic
 # 处理定时命令、周期命令、条件控制、消息、设备状态等
 timeSleep = 10
 
@@ -45,9 +45,24 @@ def control():
 		data = model.select()
 		for v in data:
 			model.id = v['id']
+			model = Demeter.model('device_type')
+			model.id = v['type_id']
+			type_info = model.select(type='fetchone')
+			if type_info['unit'] == 'button':
+				if v['cxtype'] == 1:
+					oper = '升起'
+				elif v['cxtype'] == 2:
+					oper = '降下'
+				elif v['cxtype'] == 5:
+					oper = '停止'
+			else:
+				if v['cxtype'] == 1:
+					oper = '开启'
+				else:
+					oper = '关闭'
 			if v['exp'] == '-1':
 				msg = service.notice('timeout')
-				service.mul(v['id'], v['name'], v['cxtype'], '失败:' + msg, False)
+				service.mul(v['id'], v['name'], v['cxtype'], '失败:' + msg, False, oper=oper)
 			else:
 				msg = '1'
 				service.mul(v['id'], v['name'], v['cxtype'], '', True)
@@ -103,10 +118,10 @@ def savePic():
 
 def handle():
 	gevent.joinall([
-		gevent.spawn(timing),
-		gevent.spawn(loop),
-		gevent.spawn(device),
-		gevent.spawn(savePic),
+		#gevent.spawn(timing),
+		#gevent.spawn(loop),
+		#gevent.spawn(device),
+		#gevent.spawn(savePic),
 		gevent.spawn(control),
 	])
 

+ 2 - 2
front/templates/pc/device/mul.html

@@ -53,7 +53,7 @@
                 </dt>
                 {% else %}
                 <dt class="button">
-                    <button {% if layer %}data-hint="{{layer}}dddddddddddddsf大幅度打发打发"{% end %} onclick="Farm.Button(this, '/device/mul', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn-switch {% if layer and value['value'] in ('1','4') %}hint--top {{hint}} hint--always loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %}"></button>
+                    <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/mul', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn-switch {% if layer and value['value'] in ('1','4') %}hint--top {{hint}} hint--always loading{% end %} {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %}"></button>
 
                     <button {% if layer %}data-hint="{{layer}}"{% end %} onclick="Farm.Button(this, '/device/mul', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn-switch {% if layer and value['value'] == '5' %}hint--top {{hint}} hint--always loading{% end %} {% if value['value'] == '5' %}open{% end %}"></button>
 
@@ -69,5 +69,5 @@
 
 {% block script %}
 {%set loadUrl = '/device/mul?ajax=1' %}
-
+{%include 'inc/load.html'%}
 {% end %}

+ 18 - 17
service/device.py

@@ -103,35 +103,36 @@ class Device(object):
 			model = Demeter.model('device_gateway')
 			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)
+				self.mul(info['id'], info['name'], param['switch'], '成功', True, oper=oper)
 			else:
 				msg = self.notice(msg)
 				model = Demeter.model('device_info')
 				model.id = info['id']
 				model.update(exp=msg)
 
-				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 = '关闭'
-
 				# 如果有批量控制
 				self.mul(info['id'], info['name'], param['switch'], '失败:' + msg, False, oper=oper)