Example #1
0
 def save_model(self, request, obj, form, change):
     if form.cleaned_data['selrequest'] == True:
         conres = ControlRequest(controllerid=obj.controllerid,
                                 deviceindex=0,
                                 controltype=80,
                                 devicetype=1)
         conres.save()
         self.message_user(request, "created controlrequest")
     return super(SettingDirectiveAdmin,
                  self).save_model(request, obj, form, change)
Example #2
0
 def test_withrequest(self):
     for i in range(0,100):
         req = ControlRequest(id=i+100, controllerid=self.con, deviceindex=0, controltype=10, devicetype=1)
         req.save()
     
     ml = ModelLife(target_model=0,life_day = 1, force_life_day = 10)
     ml.save()
     
     deletemodels.deleteallmodels()
     
     self.assertEqual(10, ControlResult.objects.all().count())
     self.assertEqual(10, ControlRequest.objects.all().count())
Example #3
0
 def test_multirequest(self):
     req1 = ControlRequest(controllerid=self.con,deviceindex=1,controltype=10,devicetype=1)
     req1.save()
     
     req2 = ControlRequest(controllerid=self.con,deviceindex=1,controltype=40,devicetype=1)
     req2.save()
     
     self.client = Client()
     deviceindex = "1"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     self.assertEqual(result[0],"RESET",)
     self.assertEqual(result[2] ,"CONTROLLER", )
     self.assertEqual(result[3] ,"1", )
     self.assertEqual(result[4],"",)
     
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     self.assertEqual(result[0],"GET_SETTING",)
     self.assertEqual(result[2] ,"CONTROLLER", )
     self.assertEqual(result[3] ,"1", )
     self.assertEqual(result[4],"",)
Example #4
0
 def test_FW_UPDATE(self):
     
     sfw = SettingFWUpdateInfo(controllerid=self.con)
     sfw.deviceindex = 1
     sfw.url = "AAAa"
     fwt = FWType(typeid="0",typenm="test0",devicetype=self.devicetype)
     fwt.save()
     fwt2 = FWType(typeid="1",typenm="test1",devicetype=self.devicetype)
     fwt2.save()
     fwif = FWInfo(type=fwt2,version="X.X",url="http://aaa.aaa.aaa/romfs.img.gz",filehash="aaaa")
     fwif.save()
     sfw.fw = fwif
     sfw.save()
     
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=50,devicetype=1)
     req.save()
     
     self.client = Client()
     deviceindex = "1"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     print response.content
     
     self.assertEqual(result[0],"FW_UPDATE",'controltype does not match %s' % result[0])
     self.assertRegexpMatches(result[1],"[0-9]+", "id don't match %s" % result[1])
     self.assertEqual(result[2] ,"CONTROLLER", "controltype don't match %s" % result[2])
     self.assertEqual(result[3] ,"1", "deviceid don't match %s" % result[3])
     self.assertEqual(result[4] ,"2", "deviceid don't match %s" % result[4])
     self.assertEqual(result[5] ,";http", "deviceid don't match %s" % result[5])
     
     req = ControlRequest.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     self.assertEqual(req.deleteflg,True)
     
     
     res = ControlResult.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     
     self.assertEqual(res.requestid ,int(result[1]), "requestid don't match {0}".format(res.requestid))
     self.assertEqual(res.controllerid ,req.controllerid, "controllerid don't match {0}".format(res.controllerid))
     self.assertEqual(res.deviceindex ,req.deviceindex, "deviceindex don't match {0}".format(res.deviceindex))
     self.assertEqual(res.controltype ,req.controltype, "controltype don't match {0}".format(res.controltype))
     self.assertEqual(res.devicetype ,req.devicetype, "devicetype don't match {0}".format(res.devicetype))
     self.assertIsNone(res.result,)
     self.assertEqual(res.resultmsg,"")
Example #5
0
 def test_settingDEG(self):
     
     sdeg = SettingDEG(controllerid=self.con)
     sdeg.deviceindex = 1
     sdeg.max_power = 99999.9
     sdeg.min_sec_switch_onoff = 99
     sdeg.max_cnt_switch_onoff = 99
     sdeg.mode = 1
     sdeg.save()
     
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=30,devicetype=6)
     req.save()
     
     self.client = Client()
     deviceindex = "1"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     
     self.assertEqual(result[0],"SETTING",'controltype does not match %s' % result[0])
     self.assertRegexpMatches(result[1],"[0-9]+", "id don't match %s" % result[1])
     self.assertEqual(result[2] ,"DEG", "controltype don't match %s" % result[2])
     self.assertEqual(result[3] ,"1", "deviceid don't match %s" % result[3])
     
     ressettting = result[4].split(',')
     self.assertEqual(ressettting[0], str(int(sdeg.max_power*10)),)
     self.assertEqual(ressettting[1], str(sdeg.min_sec_switch_onoff),)
     self.assertEqual(ressettting[2], str(sdeg.max_cnt_switch_onoff),)
     self.assertEqual(ressettting[3], str(sdeg.mode),)
     
     req = ControlRequest.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     self.assertEqual(req.deleteflg,True)
     
     
     res = ControlResult.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     
     self.assertEqual(res.requestid ,int(result[1]), "requestid don't match {0}".format(res.requestid))
     self.assertEqual(res.controllerid ,req.controllerid, "controllerid don't match {0}".format(res.controllerid))
     self.assertEqual(res.deviceindex ,req.deviceindex, "deviceindex don't match {0}".format(res.deviceindex))
     self.assertEqual(res.controltype ,req.controltype, "controltype don't match {0}".format(res.controltype))
     self.assertEqual(res.devicetype ,req.devicetype, "devicetype don't match {0}".format(res.devicetype))
     self.assertIsNone(res.result,)
     self.assertEqual(res.resultmsg,"")
Example #6
0
 def test_settingController(self):
     
     scon = SettingController(controllerid=self.con,mode="01")
     scon.save()
     
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=30,devicetype=1)
     req.save()
     
     self.client = Client()
     deviceindex = "10"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     
     self.assertEqual(result[0],"SETTING",'controltype does not match %s' % result[0])
     self.assertRegexpMatches(result[1],"[0-9]+", "id don't match %s" % result[1])
     self.assertEqual(result[2] ,"CONTROLLER", "controltype don't match %s" % result[2])
     self.assertEqual(result[3] ,"1", "deviceid don't match %s" % result[3])
     self.assertEqual(result[4],"01","csvdata don't match %s " % result[4])
     
     
     res = ControlResult.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     
     self.assertEqual(res.requestid ,int(result[1]), "requestid don't match {0}".format(res.requestid))
     self.assertEqual(res.controllerid ,req.controllerid, "controllerid don't match {0}".format(res.controllerid))
     self.assertEqual(res.deviceindex ,req.deviceindex, "deviceindex don't match {0}".format(res.deviceindex))
     self.assertEqual(res.controltype ,req.controltype, "controltype don't match {0}".format(res.controltype))
     self.assertEqual(res.devicetype ,req.devicetype, "devicetype don't match {0}".format(res.devicetype))
     
     
     req =ControlRequest.objects.filter(controllerid=self.con,deviceindex=1,controltype=30,devicetype=1).get()
     self.assertEqual(req.deleteflg,True)
         
     reqreslt = ControlResult.objects.get(controllerid=self.con,deviceindex=1,controltype=30,devicetype=1)
     self.assertIsNone(reqreslt.result,)
     self.assertEqual(res.resultmsg,"")
Example #7
0
 def test_resetController(self):
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=10,devicetype=1)
     req.save()
     
     self.client = Client()
     deviceindex = "10"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     self.assertEqual(result[0],"RESET",)
     self.assertEqual(result[2] ,"CONTROLLER", )
     self.assertEqual(result[3] ,"1", )
     self.assertEqual(result[4],"",)
     
     conr=ControlRequest.objects.filter(controllerid=self.con,deviceindex=1,controltype=10,devicetype=1).get()
     self.assertEqual(conr.deleteflg,True)
         
     reqreslt = ControlResult.objects.get(controllerid=self.con,deviceindex=1,controltype=10,devicetype=1)
     self.assertIsNone(reqreslt.result,)
     self.assertEqual(reqreslt.resultmsg,"")
Example #8
0
 def test_Directive(self):
     
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=80,devicetype=1)
     req.save()
     
     direct = SettingDirective()
     direct.controllerid = self.con
     direct.target_day = datetime.date(2014,1,2)
     direct.period_no = 0
     direct.period_type = 1
     direct.grid_cost = 1
     direct.outage_probability = 0
     direct.start_time = datetime.time(0,0,0)
     direct.end_time =datetime.time(12,0,0)
     direct.soc_opt =50
     direct.outage_cnt_opt = 0
     direct.outage_soc_max_opt = 50
     direct.outage_soc_min_opt = 50
     direct.save()
     
     objs = SettingDirective.objects.filter(controllerid = self.con).order_by("period_no")
     
     print len(objs)
     
     direct2 = SettingDirective()
     direct2.controllerid = self.con
     direct2.target_day =  datetime.date(2014,1,2)
     direct2.period_no = 1
     direct2.period_type = 2
     direct2.grid_cost =2
     direct2.outage_probability = 0
     direct2.start_time = datetime.time(12,0,0)
     direct2.end_time =datetime.time(0,0,0)
     direct2.soc_opt =20
     direct2.outage_cnt_opt = 0
     direct2.outage_soc_max_opt = 50
     direct2.outage_soc_min_opt = 50
     direct2.save()
     
     objs = SettingDirective.objects.filter(controllerid = self.con).order_by("period_no")
     
     print len(objs)
     
     self.client = Client()
     deviceindex = "1"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     print response.content
     result = response.content.split(":")       
     
     self.assertEqual(result[0],"DIRECTIVE",'controltype does not match %s' % result[0])
     self.assertRegexpMatches(result[1],"[0-9]+", "id don't match %s" % result[1])
     self.assertEqual(result[2] ,"CONTROLLER", "controltype don't match %s" % result[2])
     self.assertEqual(result[3] ,"1", "deviceid don't match %s" % result[3])
     
     self.assertEqual(result[4],"2","csvdata don't match %s = %s " % (result[4],direct.getline()))
     self.assertEqual(result[5],direct.getline(),"csvdata don't match %s = %s " % (result[5],direct.getline()))
     self.assertEqual(result[6],direct2.getline(),"csvdata don't match %s = %s " % (result[6],direct2.getline()))
     
     req = ControlRequest.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     self.assertEqual(req.deleteflg,True)
     
     
     res = ControlResult.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     
     self.assertEqual(res.requestid ,int(result[1]), "requestid don't match {0}".format(res.requestid))
     self.assertEqual(res.controllerid ,req.controllerid, "controllerid don't match {0}".format(res.controllerid))
     self.assertEqual(res.deviceindex ,req.deviceindex, "deviceindex don't match {0}".format(res.deviceindex))
     self.assertEqual(res.controltype ,req.controltype, "controltype don't match {0}".format(res.controltype))
     self.assertEqual(res.devicetype ,req.devicetype, "devicetype don't match {0}".format(res.devicetype))
     self.assertIsNone(res.result,)
     self.assertEqual(res.resultmsg,"")
Example #9
0
 def test_settingBattery(self):
     
     sbttr = SettingBattery(controllerid=self.con)
     sbttr.deviceindex = 1
     sbttr.mode = 00
     sbttr.soc_max = 100
     sbttr.soc_min = 100
     sbttr.energy = 99999.9
     sbttr.shipping_energy = 99999.9
     sbttr.chargepower_max =99999.9
     sbttr.dischargepower_max = 99999.9
     sbttr.bms_cnt = 99
     sbttr.voltage_max = 99999.9
     sbttr.voltage_min =99999.9
     sbttr.peak_shaving_limit = 99999.9
     sbttr.type = self.devicetypeb
     sbttr.save()
     
     req = ControlRequest(controllerid=self.con,deviceindex=1,controltype=30,devicetype=2)
     req.save()
     
     self.client = Client()
     deviceindex = "10"
     alarmtype = "0"
     senddate = "2020-07-08 11:11:11"
     csvline = ','.join([self.con.controllerid,deviceindex,senddate,alarmtype,])
     has = hashlib.md5(csvline+"gaui120gtahogsa").hexdigest()
     response = self.client.post('/emsserver/deviceif/polling/' + has,csvline,'application/x-www-form-urlencoded')
     
     result = response.content.split(':')
     
     self.assertEqual(result[0],"SETTING",'controltype does not match %s' % result[0])
     self.assertRegexpMatches(result[1],"[0-9]+", "id don't match %s" % result[1])
     self.assertEqual(result[2] ,"BATTERY", "controltype don't match %s" % result[2])
     self.assertEqual(result[3] ,"1", "deviceid don't match %s" % result[3])
     
     ressettting = result[4].split(',')
     self.assertEqual(ressettting[0], str(sbttr.mode),'mode does not match{0}!={1}'.format(int(ressettting[0]), sbttr.mode))
     self.assertEqual(ressettting[1], str(sbttr.soc_max),'soc_max does not match{0}!={1}'.format(int(ressettting[1]), sbttr.soc_max))
     self.assertEqual(ressettting[2], str(sbttr.soc_min),'soc_min does not match{0}!={1}'.format(int(ressettting[2]), sbttr.soc_min))
     self.assertEqual(ressettting[3], str(int(sbttr.energy*10)),'energy does not match{0}!={1}'.format(Decimal(ressettting[3]) / Decimal(10), sbttr.energy))
     self.assertEqual(ressettting[4], str(int(sbttr.shipping_energy*10)),'shipping_energy does not match{0}!={1}'.format(Decimal(ressettting[4]) / Decimal(10), sbttr.shipping_energy))
     self.assertEqual(ressettting[5], str(int(sbttr.chargepower_max*10)),'chargepower_max does not match{0}!={1}'.format(Decimal(ressettting[5]) / Decimal(10), sbttr.chargepower_max))
     self.assertEqual(ressettting[6], str(int(sbttr.dischargepower_max*10)),'dischargepower_max does not match{0}!={1}'.format(Decimal(ressettting[6]) / Decimal(10), sbttr.dischargepower_max))
     self.assertEqual(ressettting[7], str(sbttr.bms_cnt), 'bms_cnt does not match{0}!={1}'.format(int(ressettting[7]), sbttr.bms_cnt))
     self.assertEqual(ressettting[8], str(int(sbttr.voltage_max*10)),'voltage_max does not match{0}!={1}'.format(Decimal(ressettting[8]) / Decimal(10), sbttr.voltage_max))
     self.assertEqual(ressettting[9], str(int(sbttr.voltage_min*10)),'voltage_min does not match{0}!={1}'.format(Decimal(ressettting[9]) / Decimal(10), sbttr.voltage_min))
     self.assertEqual(ressettting[10], str(int(sbttr.peak_shaving_limit*10)),'peak_shaving_limit does not match{0}!={1}'.format(Decimal(ressettting[10]) / Decimal(10), sbttr.peak_shaving_limit))
     
     req = ControlRequest.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     self.assertEqual(req.deleteflg,True)
     
     res = ControlResult.objects.filter(controllerid_id__exact=self.con.controllerid).order_by("updatedate")[0:1].get()
     
     self.assertEqual(res.requestid ,int(result[1]), "requestid don't match {0}".format(res.requestid))
     self.assertEqual(res.controllerid ,req.controllerid, "controllerid don't match {0}".format(res.controllerid))
     self.assertEqual(res.deviceindex ,req.deviceindex, "deviceindex don't match {0}".format(res.deviceindex))
     self.assertEqual(res.controltype ,req.controltype, "controltype don't match {0}".format(res.controltype))
     self.assertEqual(res.devicetype ,req.devicetype, "devicetype don't match {0}".format(res.devicetype))
     self.assertIsNone(res.result,)
     self.assertEqual(res.resultmsg,"")