コード例 #1
0
 def test8_0_trigger(self):
     """
     Pin >8_0> trigger off
     """
     pin = SlavePin(self.opt)
     now = datetime.datetime.now()
     delay = datetime.timedelta(seconds=600)
     temp_on = now - delay
     cfg = {
         'start': temp_on.strftime("%H:%M"),
         'duration': '5',
         'pin_nr': '1',
     }
     pin.set_cfg(cfg)
     pin.change_mode('time')
     pin.init_pin()
     pin.set_pin(1)
     self.assertTrue("1" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
     pin.set_pin(1)
     self.assertTrue("1" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
コード例 #2
0
ファイル: ctrl.py プロジェクト: ChristianKniep/raspiGpioCtrl
 def run_scenario(self):
     """
     run scenario w/o config files
     """
     if self.opt['--test'] == 'test1':
         pin1 = SlavePin(self.opt)
         cfg = {
             'dow': 'Mon,Tue,Wed,Thu,Fri,Sat,Sun',
             'duration': '60',
             'groups': 'grpA',
             'name': 'TestPin1',
             'pin_nr': '1',
             'start': '01:00',
         }
         pin1.set_cfg(cfg)
         pin1.set_pin(0)
         pin1.change_mode('time')
         pin1.val_path = "%s/gpio%s/value" % (pin1.gpio_base, 1)
         self.add_pin(pin1)
         pin5 = MainPin(self.opt)
         cfg = {
             'groups': 'grpA',
             'name': 'MainPin5',
             'pin_nr': '5',
             'crypt': 'eaa491247883b9b1cd0760bae439a253'
             }
         pin5.set_cfg(cfg, True)
         pin5.val_path = "%s/gpio%s/value" % (pin1.gpio_base, 5)
         pin5.cfg_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % (os.environ["WORKSPACE"])
         pin5.change_mode('off')
         pin5.set_pin(0)
         self.add_pin(pin5)
コード例 #3
0
    def test1_0_main(self):
        """
        Web >1_0> main pin plus pin1
        """
        pin1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        pin1 = SlavePin(self.opt, pin1_file)
        pin1.init_pin(True)
        pin1.set_pin(0)
        pin1.set_cfg({"dow": "Mon,Tue,Wed,Thu,Fri,Sat,Sun"})
        self.assertTrue(pin1.isstate(0))
        pin5_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % PREFIX
        pin5 = MainPin(self.opt, pin5_file)
        pin5.init_pin(True)
        pin5.set_cfg({"groups": "garden"})
        pprint(pin5.get_json())
        pin5.change_mode("off")
        pin5.set_pin(0)
        self.assertTrue(pin5.isstate(0))

        web = Web(self.opt)
        web.add_pin(pin1)
        web.add_pin(pin5)
        web.index()
        exp = [line for line in self.exp_head]
        exp.extend([line for line in self.exp_pin1])
        exp.extend([line for line in self.exp_main5])
        exp.extend([line for line in self.exp_tail])
        exp[20] = "<td style='background-color:red'>"
        exp[36] = "<input type='checkbox' name='dow_Mon' value='Mon' checked>Mon"
        exp[37] = "<input type='checkbox' name='dow_Tue' value='Tue' checked>Tue"
        exp[39] = "<input type='checkbox' name='dow_Thu' value='Thu' checked>Thu"
        exp[40] = "<input type='checkbox' name='dow_Fri' value='Fri' checked>Fri"
        exp[41] = "<input type='checkbox' name='dow_Sat' value='Sat' checked>Sat"
        exp[42] = "<input type='checkbox' name='dow_Sun' value='Sun' checked>Sun"
        exp[52] = "<td><b>MainPin5</b></td>"
        got = web.html
        self.check_web(got, exp)
        pin5.change_mode("auto")
        web.index()
        exp[55] = "<td style='background-color:red'>"
        exp[57] = "<td style='background-color:green'>"
        got = web.html
        self.check_web(got, exp)
コード例 #4
0
 def test3_2_pin(self):
     """
     Pin >3_2> init dry-run pin and set_pin(1) / set_pin(0)
     """
     test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin1 = SlavePin(self.opt, test1_file)
     gpio_sys = "%s/packaged/sys/class/gpio/" % PREFIX
     if os.path.exists("%s/packaged/sys" % PREFIX):
         print os.system("rm -rf %s/packaged/sys" % PREFIX)
         pin1.deb("'%s' removed")
         self.assertFalse(os.path.exists(gpio_sys), "")
     pin1.init_pin()
     pin1.set_pin(1)
     filed = open("%s/gpio1/value" % gpio_sys, "r")
     cont = filed.read().strip()
     filed.close()
     self.assertTrue(cont == "1", cont)
     pin1.set_pin(0)
     filed = open("%s/gpio1/value" % gpio_sys, "r")
     cont = filed.read().strip()
     filed.close()
     self.assertTrue(cont == "0", cont)
コード例 #5
0
 def test3_4_flip(self):
     """
     Pin >3_4> init dry-run pin and flip twice with main-pin
     """
     test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin1 = SlavePin(self.opt, test1_file)
     test5_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % PREFIX
     pin5 = MainPin(self.opt, test5_file)
     gpio_sys = "%s/packaged/sys/class/gpio/" % PREFIX
     if os.path.exists("%s/packaged/sys" % PREFIX):
         print os.system("rm -rf %s/packaged/sys" % PREFIX)
         pin1.deb("'%s' removed")
         self.assertFalse(os.path.exists(gpio_sys), "")
     pin1.init_pin()
     pin5.init_pin()
     pin1.set_pin(0)
     pin5.set_pin(0)
     pin5.change_mode('auto')
     pin1.flip()
     filed = open("%s/gpio1/value" % gpio_sys, "r")
     cont = filed.read().strip()
     filed.close()
     self.assertTrue(cont == "1", cont)