install.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # -*- coding: utf-8 -*-
  2. from demeter.core import *
  3. def manage():
  4. model = Demeter.model('manage_admin')
  5. model.id = 1
  6. info = model.select(type='fetchone')
  7. if not info:
  8. model.role_id = 1
  9. model.username = 'admin'
  10. model.mobile = '15810090845'
  11. model.password = '123456'
  12. model.insert()
  13. model = Demeter.model('manage_role')
  14. model.id = 1
  15. info = model.select(type='fetchone')
  16. if not info:
  17. model.name = '管理员'
  18. model.insert()
  19. def farm():
  20. farm_id = 1
  21. model = Demeter.model('farm')
  22. model.id = farm_id
  23. info = model.select(type='fetchone')
  24. if not info:
  25. model.name = '默认园区'
  26. model.insert()
  27. def device():
  28. # 以下类型只能新增,不能随意更改或删除
  29. # 初始化默认服务
  30. '''
  31. setting_server = (
  32. {'name':'默认mqtt服务(废弃)', 'server_type':1, 'server_host': '192.168.33.10', 'server_port':'8010', 'server_time': '200'}
  33. #,{'name':'默认modbusTcp服务', 'server_type':2, 'server_host': '192.168.33.10', 'server_port':'8010', 'server_time': '200'}
  34. )
  35. model = Demeter.model('setting_server')
  36. for value in setting_server:
  37. model.server_type = value['server_type']
  38. model.server_host = value['server_host']
  39. model.server_port = value['server_port']
  40. info = model.select(type='fetchone')
  41. if not info:
  42. model.name = value['name']
  43. model.server_type = value['server_type']
  44. model.server_host = value['server_host']
  45. model.server_port = value['server_port']
  46. model.server_time = value['server_time']
  47. model.insert()
  48. '''
  49. # 初始化默认产品
  50. product = (
  51. {'name':'默认产品', 'key':'product'},
  52. )
  53. model = Demeter.model('setting_product')
  54. for value in product:
  55. model.key = value['key']
  56. info = model.select(type='fetchone')
  57. if not info:
  58. model.key = value['key']
  59. model.name = value['name']
  60. model.insert()
  61. # 初始化设备类型
  62. setting_device_type = (
  63. {'name':'温度', 'key':'temprature', 'unit':'℃'}
  64. ,{'name':'湿度', 'key':'humidity','unit':'%RH'}
  65. ,{'name':'光照', 'key':'light','unit':'LUX'}
  66. ,{'name':'二氧化碳', 'key':'co2','unit':'PPM'}
  67. ,{'name':'风速', 'key':'speed','unit':'km/h'}
  68. ,{'name':'风向', 'key':'direction','unit':'°'}
  69. ,{'name':'PM2.5', 'key':'pm2.5','unit':'μg/m3'}
  70. ,{'name':'电源', 'key':'power','unit':'V'}
  71. ,{'name':'阀门', 'key':'valve','unit':''}
  72. ,{'name':'放风机', 'key':'blower','unit':''}
  73. ,{'name':'卷帘机', 'key':'curtain','unit':'button'}
  74. ,{'name':'灯光', 'key':'lamp','unit':''}
  75. ,{'name':'除湿器', 'key':'airdryer','unit':''}
  76. ,{'name':'大气压', 'key':'atmos','unit':'hpa'}
  77. ,{'name':'开关', 'key':'sw','unit':'状态'}
  78. ,{'name':'流量', 'key':'flow','unit':'立方米'}
  79. ,{'name':'雨雪', 'key':'yuxue','unit':'button'}
  80. ,{'name':'雨量', 'key':'yuliang','unit':'mm'}
  81. ,{'name':'重量', 'key':'weight','unit':'kg'}
  82. ,{'name':'重量', 'key':'g','unit':'g'}
  83. ,{'name':'上限位', 'key':'uplimit','unit':'状态'}
  84. ,{'name':'下限位', 'key':'downlimit','unit':'状态'}
  85. ,{'name':'空气温度', 'key':'air_temp','unit':'℃'}
  86. ,{'name':'空气湿度', 'key':'air_hume','unit':'%'}
  87. ,{'name':'土壤温度', 'key':'soil_temp','unit':'℃'}
  88. ,{'name':'土壤湿度', 'key':'soil_hume','unit':'%'}
  89. ,{'name':'水泵', 'key':'pump','unit':''}
  90. )
  91. model = Demeter.model('setting_device_type')
  92. for value in setting_device_type:
  93. model.key = value['key']
  94. info = model.select(type='fetchone')
  95. if not info:
  96. model.key = value['key']
  97. model.name = value['name']
  98. model.exp = '{n}'
  99. model.unit = value['unit']
  100. model.insert()
  101. # 初始化硬件类型 1/1/2/3/4/5/6
  102. hardware_type = (
  103. {'name':'网关', 'key':'gateway'}
  104. ,{'name':'传感器', 'key':'sensor'}
  105. ,{'name':'控制器', 'key':'control'}
  106. ,{'name':'电源', 'key':'power'}
  107. ,{'name':'状态', 'key':'status'}
  108. ,{'name':'摄像头', 'key':'pic'}
  109. ,{'name':'摄像机', 'key':'camera'}
  110. )
  111. model = Demeter.model('hardware_type')
  112. for value in hardware_type:
  113. model.key = value['key']
  114. info = model.select(type='fetchone')
  115. if not info:
  116. model.key = value['key']
  117. model.name = value['name']
  118. model.insert()
  119. # 初始化消息类型
  120. msg_type = (
  121. {'name':'系统消息', 'key':'system'}
  122. ,{'name':'警告提醒', 'key':'notice'}
  123. ,{'name':'操作提示', 'key':'oper'}
  124. ,{'name':'新闻', 'key':'news'}
  125. )
  126. model = Demeter.model('msg_type')
  127. for value in msg_type:
  128. model.key = value['key']
  129. info = model.select(type='fetchone')
  130. if not info:
  131. model.key = value['key']
  132. model.name = value['name']
  133. model.insert()
  134. # 初始化错误码类型
  135. notice_type = (
  136. {'name':'设备离线', 'key':'offline'}
  137. ,{'name':'请求超时', 'key':'timeout'}
  138. ,{'name':'设备失联', 'key':'outlink'}
  139. ,{'name':'设备响应超时', 'key':'devtimeot'}
  140. )
  141. model = Demeter.model('notice_type')
  142. for value in notice_type:
  143. model.key = value['key']
  144. info = model.select(type='fetchone')
  145. if not info:
  146. model.key = value['key']
  147. model.name = value['name']
  148. model.insert()
  149. manage()
  150. farm()
  151. device()
  152. Demeter.echo('install success!')